forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added API integration tests for console_extensions server side
- Loading branch information
1 parent
a522cdd
commit 865601d
Showing
4 changed files
with
116 additions
and
6 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
102 changes: 102 additions & 0 deletions
102
x-pack/test/api_integration/apis/console/console_extensions.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,102 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function securityTests({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertestWithoutAuth'); | ||
const security = getService('security'); | ||
const spaces = getService('spaces'); | ||
|
||
describe('/api/console_extensions/text_object/*', () => { | ||
const username = 'kibana_user'; | ||
const roleName = 'kibana_user'; | ||
const password = `${username}-password`; | ||
|
||
beforeEach(async () => { | ||
await security.user.create(username, { | ||
password, | ||
roles: [roleName], | ||
full_name: 'a kibana user', | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
try { | ||
await security.user.delete(username); | ||
} catch (e) { | ||
// ignore | ||
} | ||
}); | ||
|
||
it('get_all cannot be accessed by an anonymous user', async () => { | ||
await supertest | ||
.get('/api/console_extensions/text_objects/get_all') | ||
.set('kbn-xsrf', 'xxx') | ||
.send() | ||
.expect(401); | ||
}); | ||
|
||
it('create cannot be accessed by an anonymous user', async () => { | ||
await supertest | ||
.post('/api/console_extensions/text_objects/create') | ||
.set('kbn-xsrf', 'xxx') | ||
.send() | ||
.expect(401); | ||
}); | ||
|
||
it('update cannot be accessed by an anonymous user', async () => { | ||
await supertest | ||
.put('/api/console_extensions/text_objects/update') | ||
.set('kbn-xsrf', 'xxx') | ||
.send() | ||
.expect(401); | ||
}); | ||
|
||
it('can create and update a saved object', async () => { | ||
const { | ||
body: { id }, | ||
} = await supertest | ||
.post('/api/console_extensions/text_objects/create') | ||
.set('kbn-xsrf', 'xxx') | ||
.auth(username, password) | ||
.send({ createdAt: 123, updatedAt: 123, text: 'test' }) | ||
.expect(200); | ||
|
||
await supertest | ||
.put('/api/console_extensions/text_objects/update') | ||
.set('kbn-xsrf', 'xxx') | ||
.auth(username, password) | ||
.send({ id, createdAt: 123, updatedAt: 123, text: 'test' }) | ||
.expect(204); | ||
}); | ||
|
||
it('rejects malformed data', async () => { | ||
await supertest | ||
.post('/api/console_extensions/text_objects/create') | ||
.set('kbn-xsrf', 'xxx') | ||
.auth(username, password) | ||
.send({ BAD: 123, updatedAt: 123, text: 'test' }) | ||
.expect(400); | ||
|
||
await supertest | ||
.put('/api/console_extensions/text_objects/update') | ||
.set('kbn-xsrf', 'xxx') | ||
.auth(username, password) | ||
.send({ id: 'not a real id', BAD: 123, updatedAt: 123, text: 'test' }) | ||
.expect(400); | ||
}); | ||
|
||
it('rejects updates to non-existent objects', async () => { | ||
await supertest | ||
.put('/api/console_extensions/text_objects/update') | ||
.set('kbn-xsrf', 'xxx') | ||
.auth(username, password) | ||
.send({ id: 'not a real id', createdAt: 123, updatedAt: 123, text: 'test' }) | ||
.expect(404); | ||
}); | ||
}); | ||
} |
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