Skip to content

Commit f79a2b3

Browse files
committed
Fix tests and remove token normalization
1 parent 19c1f94 commit f79a2b3

7 files changed

Lines changed: 46 additions & 20 deletions

File tree

src/core/server/integration_tests/saved_objects/registration/type_registrations.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const previouslyRegisteredTypes = [
121121
'ml-module',
122122
'ml-telemetry',
123123
'monitoring-telemetry',
124+
'oauth_state',
124125
'observability-onboarding-state',
125126
'osquery-pack',
126127
'osquery-pack-asset',

x-pack/platform/plugins/shared/actions/server/config.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ describe('config validation', () => {
3535
"microsoftExchangeUrl": "https://login.microsoftonline.com",
3636
"microsoftGraphApiScope": "https://graph.microsoft.com/.default",
3737
"microsoftGraphApiUrl": "https://graph.microsoft.com/v1.0",
38+
"oAuthRateLimit": Object {
39+
"authorize": Object {
40+
"limit": 100,
41+
"lookbackWindow": "1h",
42+
},
43+
"callback": Object {
44+
"limit": 100,
45+
"lookbackWindow": "1h",
46+
},
47+
},
3848
"preconfigured": Object {},
3949
"preconfiguredAlertHistoryEsIndex": false,
4050
"responseTimeout": "PT1M",
@@ -69,6 +79,16 @@ describe('config validation', () => {
6979
"microsoftExchangeUrl": "https://login.microsoftonline.com",
7080
"microsoftGraphApiScope": "https://graph.microsoft.com/.default",
7181
"microsoftGraphApiUrl": "https://graph.microsoft.com/v1.0",
82+
"oAuthRateLimit": Object {
83+
"authorize": Object {
84+
"limit": 100,
85+
"lookbackWindow": "1h",
86+
},
87+
"callback": Object {
88+
"limit": 100,
89+
"lookbackWindow": "1h",
90+
},
91+
},
7292
"preconfigured": Object {
7393
"mySlack1": Object {
7494
"actionTypeId": ".slack",
@@ -212,6 +232,16 @@ describe('config validation', () => {
212232
"microsoftExchangeUrl": "https://login.microsoftonline.com",
213233
"microsoftGraphApiScope": "https://graph.microsoft.com/.default",
214234
"microsoftGraphApiUrl": "https://graph.microsoft.com/v1.0",
235+
"oAuthRateLimit": Object {
236+
"authorize": Object {
237+
"limit": 100,
238+
"lookbackWindow": "1h",
239+
},
240+
"callback": Object {
241+
"limit": 100,
242+
"lookbackWindow": "1h",
243+
},
244+
},
215245
"preconfigured": Object {},
216246
"preconfiguredAlertHistoryEsIndex": false,
217247
"responseTimeout": "PT1M",
@@ -382,6 +412,16 @@ describe('config validation', () => {
382412
"microsoftExchangeUrl": "https://login.microsoftonline.com",
383413
"microsoftGraphApiScope": "https://graph.microsoft.com/.default",
384414
"microsoftGraphApiUrl": "https://graph.microsoft.com/v1.0",
415+
"oAuthRateLimit": Object {
416+
"authorize": Object {
417+
"limit": 100,
418+
"lookbackWindow": "1h",
419+
},
420+
"callback": Object {
421+
"limit": 100,
422+
"lookbackWindow": "1h",
423+
},
424+
},
385425
"preconfigured": Object {},
386426
"preconfiguredAlertHistoryEsIndex": false,
387427
"rateLimiter": Object {

x-pack/platform/plugins/shared/actions/server/lib/get_oauth_authorization_code_access_token.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* 2.0.
66
*/
77

8-
import startCase from 'lodash/startCase';
98
import pLimit from 'p-limit';
109
import type { Logger } from '@kbn/core/server';
1110
import type { ActionsConfigurationUtilities } from '../actions_config';
@@ -143,10 +142,7 @@ export const getOAuthAuthorizationCodeAccessToken = async ({
143142
shouldUseBasicAuth
144143
);
145144

146-
// Some providers return "bearer" instead of "Bearer", but expect "Bearer" in the header,
147-
// so we normalize the token type, i.e., capitalize first letter (e.g., "bearer" -> "Bearer")
148-
const normalizedTokenType = startCase(tokenResult.tokenType);
149-
const newAccessToken = `${normalizedTokenType} ${tokenResult.accessToken}`;
145+
const newAccessToken = `${tokenResult.tokenType} ${tokenResult.accessToken}`;
150146

151147
// Update stored token
152148
await connectorTokenClient.updateWithRefreshToken({

x-pack/platform/plugins/shared/actions/server/lib/get_oauth_client_credentials_access_token.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* 2.0.
66
*/
77
import type { Logger } from '@kbn/core/server';
8-
import startCase from 'lodash/startCase';
98
import type { ActionsConfigurationUtilities } from '../actions_config';
109
import type { ConnectorToken, ConnectorTokenClientContract } from '../types';
1110
import { requestOAuthClientCredentialsToken } from './request_oauth_client_credentials_token';
@@ -80,10 +79,7 @@ export const getOAuthClientCredentialsAccessToken = async ({
8079
},
8180
configurationUtilities
8281
);
83-
// Some providers return "bearer" instead of "Bearer", but expect "Bearer" in the header,
84-
// so we normalize the token type, i.e., capitalize first letter (e.g., "bearer" -> "Bearer")
85-
const normalizedTokenType = startCase(tokenResult.tokenType);
86-
accessToken = `${normalizedTokenType} ${tokenResult.accessToken}`;
82+
accessToken = `${tokenResult.tokenType} ${tokenResult.accessToken}`;
8783

8884
// try to update connector_token SO
8985
if (connectorId && connectorTokenClient) {

x-pack/platform/plugins/shared/actions/server/lib/get_oauth_jwt_access_token.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* 2.0.
66
*/
77
import type { Logger } from '@kbn/core/server';
8-
import startCase from 'lodash/startCase';
98
import type { ActionsConfigurationUtilities } from '../actions_config';
109
import type { ConnectorToken, ConnectorTokenClientContract } from '../types';
1110
import { createJWTAssertion } from './create_jwt_assertion';
@@ -90,10 +89,7 @@ export const getOAuthJwtAccessToken = async ({
9089
logger,
9190
configurationUtilities
9291
);
93-
// Some providers return "bearer" instead of "Bearer", but expect "Bearer" in the header,
94-
// so we normalize the token type, i.e., capitalize first letter (e.g., "bearer" -> "Bearer")
95-
const normalizedTokenType = startCase(tokenResult.tokenType);
96-
accessToken = `${normalizedTokenType} ${tokenResult.accessToken}`;
92+
accessToken = `${tokenResult.tokenType} ${tokenResult.accessToken}`;
9793

9894
// try to update connector_token SO
9995
if (connectorId && connectorTokenClient) {

x-pack/platform/plugins/shared/actions/server/routes/oauth_callback.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import { schema } from '@kbn/config-schema';
99
import type { CoreSetup, IRouter, Logger } from '@kbn/core/server';
1010
import { i18n } from '@kbn/i18n';
11-
import startCase from 'lodash/startCase';
1211
import type { ActionsPluginsStart } from '../plugin';
1312
import type { ILicenseState } from '../lib';
1413
import { BASE_ACTION_API_PATH } from '../../common';
@@ -396,10 +395,7 @@ export const oauthCallbackRoute = (
396395
connectorId: oauthState.connectorId,
397396
tokenType: 'access_token',
398397
});
399-
// Some providers return "bearer" instead of "Bearer", but expect "Bearer" in the header,
400-
// so we normalize the token type, i.e., capitalize first letter (e.g., "bearer" -> "Bearer")
401-
const normalizedTokenType = startCase(tokenResult.tokenType);
402-
const formattedToken = `${normalizedTokenType} ${tokenResult.accessToken}`;
398+
const formattedToken = `${tokenResult.tokenType} ${tokenResult.accessToken}`;
403399
await connectorTokenClient.createWithRefreshToken({
404400
connectorId: oauthState.connectorId,
405401
accessToken: formattedToken,

x-pack/platform/test/plugin_api_integration/test_suites/task_manager/check_registered_task_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default function ({ getService }: FtrProviderContext) {
105105
'actions:.xmatters',
106106
'actions:.xsoar',
107107
'actions:connector_usage_reporting',
108+
'actions:oauth_state_cleanup',
108109
'actions_telemetry',
109110
'ad_hoc_run-backfill',
110111
'alert-deletion',

0 commit comments

Comments
 (0)