-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Migrated last pieces of legacy fixture code #74470
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a1f3a5
Migrated last pieces of legacy fixture code
YulNaumenko 1b84ffe
Implemented own server for webhook simulator
YulNaumenko 71dce90
Fixed type checks. Moved slack simulator to own server
YulNaumenko 039d487
close server after tests run
YulNaumenko 4831126
Merge remote-tracking branch 'upstream/master' into alerting-legacy-fix
YulNaumenko 9c9a95a
Fixed due to comments
YulNaumenko 36d82b6
Merge remote-tracking branch 'upstream/master' into alerting-legacy-fix
YulNaumenko e11be08
fixed failing tests
YulNaumenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ing_api_integration/common/fixtures/plugins/actions_simulators/server/slack_simulation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import http from 'http'; | ||
|
|
||
| export async function initPlugin() { | ||
| return http.createServer((request, response) => { | ||
| if (request.method === 'POST') { | ||
| let data = ''; | ||
| request.on('data', (chunk) => { | ||
| data += chunk; | ||
| }); | ||
| request.on('end', () => { | ||
| const body = JSON.parse(data); | ||
| const text = body && body.text; | ||
|
|
||
| if (text == null) { | ||
| response.statusCode = 400; | ||
| response.end('bad request to slack simulator'); | ||
| return; | ||
| } | ||
|
|
||
| switch (text) { | ||
| case 'success': { | ||
| response.statusCode = 200; | ||
| response.end('ok'); | ||
| return; | ||
| } | ||
| case 'no_text': | ||
| response.statusCode = 400; | ||
| response.end('no_text'); | ||
| return; | ||
|
|
||
| case 'invalid_payload': | ||
| response.statusCode = 400; | ||
| response.end('invalid_payload'); | ||
| return; | ||
|
|
||
| case 'invalid_token': | ||
| response.statusCode = 403; | ||
| response.end('invalid_token'); | ||
| return; | ||
|
|
||
| case 'status_500': | ||
| response.statusCode = 500; | ||
| response.end('simulated slack 500 response'); | ||
| return; | ||
|
|
||
| case 'rate_limit': | ||
| const res = { | ||
| retry_after: 1, | ||
| ok: false, | ||
| error: 'rate_limited', | ||
| }; | ||
|
|
||
| response.writeHead(429, { 'Content-Type': 'application/json', 'Retry-After': '1' }); | ||
| response.write(JSON.stringify(res)); | ||
| response.end(); | ||
| return; | ||
| } | ||
| response.statusCode = 400; | ||
| response.end('unknown request to slack simulator'); | ||
| }); | ||
| } | ||
| }); | ||
| } |
88 changes: 88 additions & 0 deletions
88
...g_api_integration/common/fixtures/plugins/actions_simulators/server/webhook_simulation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| import expect from '@kbn/expect'; | ||
| import http from 'http'; | ||
| import { fromNullable, map, filter, getOrElse } from 'fp-ts/lib/Option'; | ||
| import { pipe } from 'fp-ts/lib/pipeable'; | ||
| import { constant } from 'fp-ts/lib/function'; | ||
|
|
||
| export async function initPlugin() { | ||
| return http.createServer((request, response) => { | ||
| const credentials = pipe( | ||
| fromNullable(request.headers.authorization), | ||
| map((authorization) => authorization.split(/\s+/)), | ||
| filter((parts) => parts.length > 1), | ||
| map((parts) => Buffer.from(parts[1], 'base64').toString()), | ||
| filter((credentialsPart) => credentialsPart.indexOf(':') !== -1), | ||
| map((credentialsPart) => { | ||
| const [username, password] = credentialsPart.split(':'); | ||
| return { username, password }; | ||
| }), | ||
| getOrElse(constant({ username: '', password: '' })) | ||
| ); | ||
|
|
||
| if (request.method === 'POST' || request.method === 'PUT') { | ||
| let data = ''; | ||
| request.on('data', (chunk) => { | ||
| data += chunk; | ||
| }); | ||
| request.on('end', () => { | ||
| switch (data) { | ||
| case 'success': | ||
| response.statusCode = 200; | ||
| response.end('OK'); | ||
| return; | ||
| case 'authenticate': | ||
| return validateAuthentication(credentials, response); | ||
| case 'success_post_method': | ||
| return validateRequestUsesMethod(request.method ?? '', 'post', response); | ||
| case 'success_put_method': | ||
| return validateRequestUsesMethod(request.method ?? '', 'put', response); | ||
| case 'failure': | ||
| response.statusCode = 500; | ||
| response.end('Error'); | ||
| return; | ||
| } | ||
| response.statusCode = 400; | ||
| response.end( | ||
| `unknown request to webhook simulator [${data ? `content: ${data}` : `no content`}]` | ||
| ); | ||
| return; | ||
| }); | ||
| } else { | ||
| request.on('end', () => { | ||
| response.statusCode = 400; | ||
| response.end('unknown request to webhook simulator [no content]'); | ||
| return; | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function validateAuthentication(credentials: any, res: any) { | ||
| try { | ||
| expect(credentials).to.eql({ | ||
| username: 'elastic', | ||
| password: 'changeme', | ||
| }); | ||
| res.statusCode = 200; | ||
| res.end('OK'); | ||
| } catch (ex) { | ||
| res.statusCode = 403; | ||
| res.end(`the validateAuthentication operation failed. ${ex.message}`); | ||
| } | ||
| } | ||
|
|
||
| function validateRequestUsesMethod(requestMethod: string, method: string, res: any) { | ||
| try { | ||
| expect(requestMethod.toLowerCase()).to.eql(method); | ||
| res.statusCode = 200; | ||
| res.end('OK'); | ||
| } catch (ex) { | ||
| res.statusCode = 403; | ||
| res.end(`the validateAuthentication operation failed. ${ex.message}`); | ||
| } | ||
| } | ||
26 changes: 0 additions & 26 deletions
26
.../test/alerting_api_integration/common/fixtures/plugins/actions_simulators_legacy/index.ts
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...t/alerting_api_integration/common/fixtures/plugins/actions_simulators_legacy/package.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.