-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to ensure AAD isn't broken after performing a change on an …
- Loading branch information
Showing
28 changed files
with
360 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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
58 changes: 58 additions & 0 deletions
58
x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/index.ts
This file contains 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,58 @@ | ||
/* | ||
* 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 Joi from 'joi'; | ||
import Hapi from 'hapi'; | ||
import { Legacy } from 'kibana'; | ||
import KbnServer from '../../../../../../../src/legacy/server/kbn_server'; | ||
import { PluginStartContract } from '../../../../../../plugins/encrypted_saved_objects/server'; | ||
|
||
interface CheckAADRequest extends Hapi.Request { | ||
payload: { | ||
spaceId?: string; | ||
type: string; | ||
id: string; | ||
}; | ||
} | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function(kibana: any) { | ||
return new kibana.Plugin({ | ||
require: ['actions', 'alerting', 'encryptedSavedObjects'], | ||
name: 'aad-fixtures', | ||
init(server: Legacy.Server) { | ||
const newPlatform = ((server as unknown) as KbnServer).newPlatform; | ||
const esoPlugin = newPlatform.start.plugins.encryptedSavedObjects as PluginStartContract; | ||
|
||
server.route({ | ||
method: 'POST', | ||
path: '/api/check_aad', | ||
options: { | ||
validate: { | ||
payload: Joi.object() | ||
.keys({ | ||
spaceId: Joi.string().optional(), | ||
type: Joi.string().required(), | ||
id: Joi.string().required(), | ||
}) | ||
.required(), | ||
}, | ||
}, | ||
async handler(request: CheckAADRequest) { | ||
let namespace: string | undefined; | ||
const spacesPlugin = server.plugins.spaces; | ||
if (spacesPlugin && request.payload.spaceId) { | ||
namespace = spacesPlugin.spaceIdToNamespace(request.payload.spaceId); | ||
} | ||
await esoPlugin.getDecryptedAsInternalUser(request.payload.type, request.payload.id, { | ||
namespace, | ||
}); | ||
return { success: true }; | ||
}, | ||
}); | ||
}, | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/package.json
This file contains 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,7 @@ | ||
{ | ||
"name": "aad-fixtures", | ||
"version": "0.0.0", | ||
"kibana": { | ||
"version": "kibana" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
x-pack/test/alerting_api_integration/common/lib/check_aad.ts
This file contains 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,20 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
interface Opts { | ||
supertest: any; | ||
spaceId?: string; | ||
type: string; | ||
id: string; | ||
} | ||
|
||
export async function checkAAD({ supertest, spaceId, type, id }: Opts) { | ||
await supertest | ||
.post('/api/check_aad') | ||
.set('kbn-xsrf', 'foo') | ||
.send({ spaceId, type, id }) | ||
.expect(200, { success: true }); | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.