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.
[Serverless Search] add api integration tests (elastic#168752)
## Summary Adding API integration tests for exists routes (most of them). This is missing some of the connector routes for now.
- Loading branch information
1 parent
5fc8429
commit a48b58f
Showing
5 changed files
with
205 additions
and
0 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
103 changes: 103 additions & 0 deletions
103
x-pack/test_serverless/api_integration/test_suites/search/serverless_search/api_key.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,103 @@ | ||
/* | ||
* 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 'expect'; | ||
import { kibanaTestUser } from '@kbn/test'; | ||
import { SecurityApiKey } from '@elastic/elasticsearch/lib/api/types'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
const API_BASE_PATH = '/internal/serverless_search'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const svlCommonApi = getService('svlCommonApi'); | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
const log = getService('log'); | ||
|
||
describe('API Key routes', function () { | ||
describe('GET api_keys', function () { | ||
it('return apiKeys', async () => { | ||
const { body } = await supertest | ||
.get(`${API_BASE_PATH}/api_keys`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.expect(200); | ||
|
||
expect(body).toBeDefined(); | ||
expect(body.apiKeys).toBeDefined(); | ||
expect(Array.isArray(body.apiKeys)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('POST api_key', function () { | ||
const deleteAllApiKeys = async () => { | ||
let apiKeys: SecurityApiKey[]; | ||
// Delete existing API keys | ||
try { | ||
const apiKeysResult = await es.security.getApiKey({ username: kibanaTestUser.username }); | ||
apiKeys = apiKeysResult.api_keys; | ||
} catch (err) { | ||
log.debug('[Setup error] error listing API keys'); | ||
throw err; | ||
} | ||
|
||
expect(Array.isArray(apiKeys)).toBe(true); | ||
if (apiKeys.length === 0) { | ||
return; | ||
} | ||
|
||
const apiKeysToDelete = apiKeys.map(({ id }) => id); | ||
await es.security.invalidateApiKey({ ids: apiKeysToDelete }); | ||
}; | ||
before(async () => { | ||
await deleteAllApiKeys(); | ||
}); | ||
after(async () => { | ||
await deleteAllApiKeys(); | ||
}); | ||
it('can create a key that expires', async () => { | ||
const createBody = { | ||
name: 'test-api-key-001', | ||
expiration: '60d', | ||
}; | ||
const { body } = await supertest | ||
.post(`${API_BASE_PATH}/api_key`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send(createBody) | ||
.expect(200); | ||
|
||
expect(body).toMatchObject({ name: 'test-api-key-001', expiration: expect.anything() }); | ||
}); | ||
it('can create a key that never expires', async () => { | ||
const createBody = { | ||
name: 'test-api-key-002', | ||
}; | ||
const { body } = await supertest | ||
.post(`${API_BASE_PATH}/api_key`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send(createBody) | ||
.expect(200); | ||
|
||
expect(body).toMatchObject({ name: 'test-api-key-002' }); | ||
}); | ||
it('has beats_logstash_format in result', async () => { | ||
const createBody = { | ||
name: 'test-api-key-003', | ||
}; | ||
const { body } = await supertest | ||
.post(`${API_BASE_PATH}/api_key`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.send(createBody) | ||
.expect(200); | ||
|
||
expect(body).toMatchObject({ | ||
name: 'test-api-key-003', | ||
beats_logstash_format: expect.stringContaining(':'), | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
x-pack/test_serverless/api_integration/test_suites/search/serverless_search/connectors.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,42 @@ | ||
/* | ||
* 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 'expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
const API_BASE_PATH = '/internal/serverless_search'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const svlCommonApi = getService('svlCommonApi'); | ||
const supertest = getService('supertest'); | ||
|
||
describe('Connectors routes', function () { | ||
describe('GET connectors', function () { | ||
it('returns list of connectors', async () => { | ||
const { body } = await supertest | ||
.get(`${API_BASE_PATH}/connectors`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.expect(200); | ||
|
||
expect(body.connectors).toBeDefined(); | ||
expect(Array.isArray(body.connectors)).toBe(true); | ||
}); | ||
}); | ||
describe('GET connectors', function () { | ||
it('returns list of connector_types', async () => { | ||
const { body } = await supertest | ||
.get(`${API_BASE_PATH}/connector_types`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.expect(200); | ||
|
||
expect(body.connectors).toBeDefined(); | ||
expect(Array.isArray(body.connectors)).toBe(true); | ||
expect(body.connectors.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
}); | ||
} |
16 changes: 16 additions & 0 deletions
16
x-pack/test_serverless/api_integration/test_suites/search/serverless_search/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,16 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('Serverless Search - Server', function () { | ||
loadTestFile(require.resolve('./api_key')); | ||
loadTestFile(require.resolve('./connectors')); | ||
loadTestFile(require.resolve('./indices')); | ||
}); | ||
} |
43 changes: 43 additions & 0 deletions
43
x-pack/test_serverless/api_integration/test_suites/search/serverless_search/indices.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,43 @@ | ||
/* | ||
* 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 'expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
const API_BASE_PATH = '/internal/serverless_search'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const svlCommonApi = getService('svlCommonApi'); | ||
const supertest = getService('supertest'); | ||
|
||
describe('Indices routes', function () { | ||
describe('GET indices', function () { | ||
it('has route', async () => { | ||
const { body } = await supertest | ||
.get(`${API_BASE_PATH}/indices`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.expect(200); | ||
|
||
expect(body).toBeDefined(); | ||
}); | ||
it('accepts search_query', async () => { | ||
await supertest | ||
.get(`${API_BASE_PATH}/indices`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.query({ search_query: 'foo' }) | ||
.expect(200); | ||
}); | ||
it('accepts from & size', async () => { | ||
await supertest | ||
.get(`${API_BASE_PATH}/indices`) | ||
.set(svlCommonApi.getInternalRequestHeader()) | ||
.query({ from: 0, size: 10 }) | ||
.expect(200); | ||
}); | ||
}); | ||
}); | ||
} |