-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Adds SOM integration tests for serverless #184888
Changes from 15 commits
14428a9
ba714a3
2482892
0eff45c
601e55f
907dc33
321db7b
ccb566c
8032917
2446ef2
a9cc309
7de5703
43afb95
b34e97c
8434dfd
4c58391
58e6f13
e10b03e
90afd0c
01c197a
cbc282b
fcc9645
395d1fe
6023dbf
785504b
89214b9
78cc092
32ec76b
564884e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { SavedObjectWithMetadata } from '@kbn/saved-objects-management-plugin/common'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { RoleCredentials } from '../../../../shared/services'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const svlCommonApi = getService('svlCommonApi'); | ||
const svlUserManager = getService('svlUserManager'); | ||
const supertest = getService('supertest'); | ||
const kibanaServer = getService('kibanaServer'); | ||
let roleAuthc: RoleCredentials; | ||
|
||
describe('_bulk_delete', () => { | ||
const endpoint = '/internal/kibana/management/saved_objects/_bulk_delete'; | ||
const validObject = { type: 'visualization', id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab' }; | ||
const invalidObject = { type: 'wigwags', id: 'foo' }; | ||
|
||
before(async () => { | ||
roleAuthc = await svlUserManager.createApiKeyForRole('admin'); | ||
}); | ||
|
||
after(async () => { | ||
await svlUserManager.invalidateApiKeyForRole(roleAuthc); | ||
}); | ||
|
||
beforeEach(() => | ||
kibanaServer.importExport.load( | ||
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json' | ||
) | ||
); | ||
afterEach(() => | ||
kibanaServer.importExport.unload( | ||
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json' | ||
) | ||
); | ||
|
||
function expectSuccess(index: number, objs: SavedObjectWithMetadata[]) { | ||
const { type, id, error } = objs[index]; | ||
expect(type).to.eql(validObject.type); | ||
expect(id).to.eql(validObject.id); | ||
expect(error).to.equal(undefined); | ||
} | ||
|
||
function expectBadRequest(index: number, objs: SavedObjectWithMetadata[]) { | ||
const { type, id, error } = objs[index]; | ||
expect(type).to.eql(invalidObject.type); | ||
expect(id).to.eql(invalidObject.id); | ||
expect(error).to.eql({ | ||
message: `Unsupported saved object type: '${invalidObject.type}': Bad Request`, | ||
statusCode: 400, | ||
error: 'Bad Request', | ||
}); | ||
} | ||
|
||
it('should return 200 for an existing object', async () => | ||
await supertest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
.post(endpoint) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.set(roleAuthc.apiKeyHeader) | ||
.send([validObject]) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body).to.have.length(1); | ||
expectSuccess(0, body); | ||
})); | ||
|
||
it('should return error for invalid object type', async () => | ||
await supertest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.post(endpoint) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.set(roleAuthc.apiKeyHeader) | ||
.send([invalidObject]) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body).to.have.length(1); | ||
expectBadRequest(0, body); | ||
})); | ||
|
||
it('should return mix of successes and errors', async () => | ||
await supertest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.post(endpoint) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.set(roleAuthc.apiKeyHeader) | ||
.send([validObject, invalidObject]) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body).to.have.length(2); | ||
expectSuccess(0, body); | ||
expectBadRequest(1, body); | ||
})); | ||
}); | ||
} |
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { SavedObjectWithMetadata } from '@kbn/saved-objects-management-plugin/common'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { RoleCredentials } from '../../../../shared/services'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const svlCommonApi = getService('svlCommonApi'); | ||
const svlUserManager = getService('svlUserManager'); | ||
const supertest = getService('supertest'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const kibanaServer = getService('kibanaServer'); | ||
let roleAuthc: RoleCredentials; | ||
|
||
const URL = '/api/kibana/management/saved_objects/_bulk_get'; | ||
const validObject = { type: 'visualization', id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab' }; | ||
const invalidObject = { type: 'wigwags', id: 'foo' }; | ||
|
||
describe('_bulk_get', () => { | ||
before(async () => { | ||
roleAuthc = await svlUserManager.createApiKeyForRole('admin'); | ||
}); | ||
|
||
after(async () => { | ||
await svlUserManager.invalidateApiKeyForRole(roleAuthc); | ||
}); | ||
|
||
describe('get objects in bulk', () => { | ||
before(() => | ||
kibanaServer.importExport.load( | ||
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json' | ||
) | ||
); | ||
after(() => | ||
kibanaServer.importExport.unload( | ||
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json' | ||
) | ||
); | ||
|
||
function expectSuccess(index: number, objs: SavedObjectWithMetadata[]) { | ||
const { type, id, meta, error } = objs[index]; | ||
expect(type).to.eql(validObject.type); | ||
expect(id).to.eql(validObject.id); | ||
expect(meta).to.not.equal(undefined); | ||
expect(error).to.equal(undefined); | ||
} | ||
|
||
function expectBadRequest(index: number, objs: SavedObjectWithMetadata[]) { | ||
const { type, id, error } = objs[index]; | ||
expect(type).to.eql(invalidObject.type); | ||
expect(id).to.eql(invalidObject.id); | ||
expect(error).to.eql({ | ||
message: `Unsupported saved object type: '${invalidObject.type}': Bad Request`, | ||
statusCode: 400, | ||
error: 'Bad Request', | ||
}); | ||
} | ||
|
||
it('should return 200 for object that exists and inject metadata', async () => | ||
await supertest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.post(URL) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.set(roleAuthc.apiKeyHeader) | ||
.send([validObject]) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body).to.have.length(1); | ||
expectSuccess(0, body); | ||
})); | ||
|
||
it('should return error for invalid object type', async () => | ||
await supertest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.post(URL) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.set(roleAuthc.apiKeyHeader) | ||
.send([invalidObject]) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body).to.have.length(1); | ||
expectBadRequest(0, body); | ||
})); | ||
|
||
it('should return mix of successes and errors', async () => | ||
await supertest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.post(URL) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.set(roleAuthc.apiKeyHeader) | ||
.send([validObject, invalidObject]) | ||
.expect(200) | ||
.then(({ body }) => { | ||
expect(body).to.have.length(2); | ||
expectSuccess(0, body); | ||
expectBadRequest(1, body); | ||
})); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be supertestWithoutAuth, like this:
const supertestWithoutAuth = getService('supertestWithoutAuth');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done