-
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
[APM] Migrate settings API tests to be deployment-agnostic #200762
Merged
iblancof
merged 33 commits into
elastic:main
from
iblancof:198989-apm-migrate-test-apm_api_integration-tests-settings-to-be-deployment-agnostic-api-tests
Nov 21, 2024
Merged
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
1c3c51a
Create settings/anomaly_detection basic deployment agnostic api tests
iblancof 744db47
Create settings/anomaly_detection read user deployment agnostic api t…
iblancof eeb1971
Create settings/custom_link deployment agnostic api tests
iblancof a825c95
Create settings/apm_indices deployment agnostic api tests
iblancof 86c262f
Create settings/agent_keys deployment agnostic api tests
iblancof 8c4f48a
Create tests loader for settings deployment agnostic tests
iblancof 4a4c838
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof ed0bc6b
Clean stateful tests
iblancof e74f551
Refactor imports to use type-only imports in APM settings test files
iblancof e183e46
Invalidate samlAuth
iblancof 48a98c9
Remove unused constant
iblancof 8c61a72
Update x-pack/test/api_integration/deployment_agnostic/apis/observabi…
iblancof 41e3a23
Update x-pack/test/api_integration/deployment_agnostic/apis/observabi…
iblancof 2cb8be0
Remove migrated test
iblancof f2d8c39
Remove FIPS skip
iblancof de4cb58
Better support for public api calls
crespocarlos f10b108
Merge pull request #1 from crespocarlos/apm-api-service-improvement
iblancof adc918a
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof d50e6bf
Use publicApi
iblancof 294c068
Reorder apmApiIntegrationTests
iblancof 1b1123a
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof 4fcd4dc
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof 4134664
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof e2ed6f5
Remove duplicated test file import
iblancof 61a9a0c
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof 4f8ad0c
Remove test case that was not deployment agnostic
iblancof f1e40f1
Remove duplicated writeUser test
iblancof 681d40a
Merge branch '198989-apm-migrate-test-apm_api_integration-tests-setti…
iblancof 96db562
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof e8371fb
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof 269f33f
Add deleteSavedObject again afterEach
iblancof ea617dd
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof f5c0e14
Merge branch 'main' into 198989-apm-migrate-test-apm_api_integration-…
iblancof 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 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
84 changes: 84 additions & 0 deletions
84
...gration/deployment_agnostic/apis/observability/apm/settings/agent_keys/agent_keys.spec.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,84 @@ | ||
/* | ||
* 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 { PrivilegeType, ClusterPrivilegeType } from '@kbn/apm-plugin/common/privilege_type'; | ||
import type { RoleCredentials } from '../../../../../services'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context'; | ||
import { expectToReject } from '../../../../../../../apm_api_integration/common/utils/expect_to_reject'; | ||
import type { ApmApiError } from '../../../../../services/apm_api'; | ||
|
||
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const apmApiClient = getService('apmApi'); | ||
const samlAuth = getService('samlAuth'); | ||
|
||
const agentKeyName = 'test'; | ||
const allApplicationPrivileges = [PrivilegeType.AGENT_CONFIG, PrivilegeType.EVENT]; | ||
const clusterPrivileges = [ClusterPrivilegeType.MANAGE_OWN_API_KEY]; | ||
|
||
async function createAgentKey(roleAuthc: RoleCredentials) { | ||
return await apmApiClient.publicApi({ | ||
endpoint: 'POST /api/apm/agent_keys 2023-10-31', | ||
params: { | ||
body: { | ||
name: agentKeyName, | ||
privileges: allApplicationPrivileges, | ||
}, | ||
}, | ||
roleAuthc, | ||
}); | ||
} | ||
|
||
async function invalidateAgentKey(id: string) { | ||
return await apmApiClient.writeUser({ | ||
endpoint: 'POST /internal/apm/api_key/invalidate', | ||
params: { | ||
body: { id }, | ||
}, | ||
}); | ||
} | ||
|
||
async function getAgentKeys() { | ||
return await apmApiClient.writeUser({ endpoint: 'GET /internal/apm/agent_keys' }); | ||
} | ||
|
||
describe('When the user does not have the required privileges', () => { | ||
let roleAuthc: RoleCredentials; | ||
|
||
before(async () => { | ||
roleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('editor'); | ||
}); | ||
Comment on lines
+51
to
+53
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. API key should be invalidated in after(async () => {
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc);
}); 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. I missed that, thank you! |
||
|
||
after(async () => { | ||
await samlAuth.invalidateM2mApiKeyWithRoleScope(roleAuthc); | ||
}); | ||
|
||
describe('When the user does not have the required cluster privileges', () => { | ||
it('should return an error when creating an agent key', async () => { | ||
const error = await expectToReject<ApmApiError>(() => createAgentKey(roleAuthc)); | ||
expect(error.res.status).to.be(403); | ||
expect(error.res.body.message).contain('is missing the following requested privilege'); | ||
expect(error.res.body.attributes).to.eql({ | ||
_inspect: [], | ||
data: { | ||
missingPrivileges: allApplicationPrivileges, | ||
missingClusterPrivileges: clusterPrivileges, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return an error when invalidating an agent key', async () => { | ||
const error = await expectToReject<ApmApiError>(() => invalidateAgentKey(agentKeyName)); | ||
expect(error.res.status).to.be(500); | ||
}); | ||
|
||
it('should return an error when getting a list of agent keys', async () => { | ||
const error = await expectToReject<ApmApiError>(() => getAgentKeys()); | ||
expect(error.res.status).to.be(500); | ||
}); | ||
}); | ||
}); | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...n/deployment_agnostic/apis/observability/apm/settings/anomaly_detection/read_user.spec.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,52 @@ | ||
/* | ||
* 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 type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context'; | ||
import type { ApmApiError } from '../../../../../services/apm_api'; | ||
|
||
export default function apiTest({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const apmApiClient = getService('apmApi'); | ||
|
||
function getJobs() { | ||
return apmApiClient.readUser({ endpoint: `GET /internal/apm/settings/anomaly-detection/jobs` }); | ||
} | ||
|
||
function createJobs(environments: string[]) { | ||
return apmApiClient.readUser({ | ||
endpoint: `POST /internal/apm/settings/anomaly-detection/jobs`, | ||
params: { | ||
body: { environments }, | ||
}, | ||
}); | ||
} | ||
|
||
describe('ML jobs', () => { | ||
describe(`when readUser has read access to ML`, () => { | ||
describe('when calling the endpoint for listing jobs', () => { | ||
it('returns a list of jobs', async () => { | ||
const { body } = await getJobs(); | ||
|
||
expect(body.jobs).not.to.be(undefined); | ||
expect(body.hasLegacyJobs).to.be(false); | ||
}); | ||
}); | ||
|
||
describe('when calling create endpoint', () => { | ||
it('returns an error because the user does not have access', async () => { | ||
try { | ||
await createJobs(['production', 'staging']); | ||
expect(true).to.be(false); | ||
} catch (e) { | ||
const err = e as ApmApiError; | ||
expect(err.res.status).to.be(403); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
71 changes: 71 additions & 0 deletions
71
...ation/deployment_agnostic/apis/observability/apm/settings/apm_indices/apm_indices.spec.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,71 @@ | ||
/* | ||
* 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 { | ||
APM_INDEX_SETTINGS_SAVED_OBJECT_ID, | ||
APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE, | ||
} from '@kbn/apm-data-access-plugin/server/saved_objects/apm_indices'; | ||
import expect from '@kbn/expect'; | ||
import type { DeploymentAgnosticFtrProviderContext } from '../../../../../ftr_provider_context'; | ||
|
||
export default function apmIndicesTests({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
const kibanaServer = getService('kibanaServer'); | ||
const apmApiClient = getService('apmApi'); | ||
|
||
async function deleteSavedObject() { | ||
try { | ||
return await kibanaServer.savedObjects.delete({ | ||
type: APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE, | ||
id: APM_INDEX_SETTINGS_SAVED_OBJECT_ID, | ||
}); | ||
} catch (e) { | ||
if (e.response.status !== 404) { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
describe('APM Indices', () => { | ||
beforeEach(async () => { | ||
await deleteSavedObject(); | ||
}); | ||
|
||
it('returns APM Indices', async () => { | ||
const response = await apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/settings/apm-indices', | ||
}); | ||
expect(response.status).to.be(200); | ||
expect(response.body).to.eql({ | ||
transaction: 'traces-apm*,apm-*,traces-*.otel-*', | ||
span: 'traces-apm*,apm-*,traces-*.otel-*', | ||
error: 'logs-apm*,apm-*,logs-*.otel-*', | ||
metric: 'metrics-apm*,apm-*,metrics-*.otel-*', | ||
onboarding: 'apm-*', | ||
sourcemap: 'apm-*', | ||
}); | ||
}); | ||
|
||
it('updates apm indices', async () => { | ||
const INDEX_VALUE = 'foo-*'; | ||
|
||
const writeResponse = await apmApiClient.writeUser({ | ||
endpoint: 'POST /internal/apm/settings/apm-indices/save', | ||
params: { | ||
body: { transaction: INDEX_VALUE }, | ||
}, | ||
}); | ||
expect(writeResponse.status).to.be(200); | ||
|
||
const readResponse = await apmApiClient.readUser({ | ||
endpoint: 'GET /internal/apm/settings/apm-indices', | ||
}); | ||
|
||
expect(readResponse.status).to.be(200); | ||
expect(readResponse.body.transaction).to.eql(INDEX_VALUE); | ||
}); | ||
}); | ||
} |
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.
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.
Thank you for reorg the list. This was bothering me so much.