Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps] allow Slack API URL to be overridden for functional tests #1

Open
wants to merge 1 commit into
base: 154359-create-slac-web-api-connector
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
*/

export const SLACK_API_CONNECTOR_ID = '.slack_api';
export const SLACK_URL = 'https://slack.com/api/';
12 changes: 12 additions & 0 deletions x-pack/plugins/stack_connectors/common/slack_api/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ export function retryResultSeconds(
serviceMessage: message,
};
}

// This is only modifiable via config, at startup. The reason we
// added this was to test with a local simulator for functional tests.
let SlackApiUrl = 'https://slack.com/api/';

export function internalSetSlackApiURL(url: string): void {
SlackApiUrl = url;
}

export function internalGetSlackApiURL(): string {
return SlackApiUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import type {
SlackApiSecrets,
} from '../../../common/slack_api/types';
import { SlackApiSecretsSchema, SlackApiParamsSchema } from '../../../common/slack_api/schema';
import { SLACK_API_CONNECTOR_ID, SLACK_URL } from '../../../common/slack_api/constants';
import { SLACK_API_CONNECTOR_ID } from '../../../common/slack_api/constants';
import { SLACK_CONNECTOR_NAME } from './translations';
import { api } from './api';
import { createExternalService } from './service';
import { internalGetSlackApiURL } from '../../../common/slack_api/lib';

const supportedSubActions = ['getChannels', 'postMessage'];

Expand Down Expand Up @@ -53,7 +54,7 @@ const validateSlackUrl = (secretsObject: SlackApiSecrets, validatorServices: Val
const { configurationUtilities } = validatorServices;

try {
configurationUtilities.ensureUriAllowed(SLACK_URL);
configurationUtilities.ensureUriAllowed(internalGetSlackApiURL());
} catch (allowedListError) {
throw new Error(
i18n.translate('xpack.stackConnectors.slack_api.configurationError', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import {
errorResult,
successResult,
} from '../../../common/slack_api/lib';
import { SLACK_API_CONNECTOR_ID, SLACK_URL } from '../../../common/slack_api/constants';
import { SLACK_API_CONNECTOR_ID } from '../../../common/slack_api/constants';
import { getRetryAfterIntervalFromHeaders } from '../lib/http_response_retry_header';
import { internalGetSlackApiURL } from '../../../common/slack_api/lib';

const buildSlackExecutorErrorResponse = ({
slackApiError,
Expand Down Expand Up @@ -112,7 +113,7 @@ export const createExternalService = (
}

const axiosInstance = axios.create({
baseURL: SLACK_URL,
baseURL: internalGetSlackApiURL(),
headers: {
Authorization: `Bearer ${token}`,
'Content-type': 'application/json; charset=UTF-8',
Expand Down