-
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.
[ML] Adding ml_capabilities api tests (#92786)
* [ML] Adding ml_capabilities api tests * updating test text * changes based on review
- Loading branch information
1 parent
37d7ea2
commit 3b66bf7
Showing
4 changed files
with
362 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
124 changes: 124 additions & 0 deletions
124
x-pack/test/api_integration/apis/ml/system/capabilities.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,124 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api'; | ||
import { USER } from '../../../../functional/services/ml/security_common'; | ||
import { MlCapabilitiesResponse } from '../../../../../plugins/ml/common/types/capabilities'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertestWithoutAuth'); | ||
const ml = getService('ml'); | ||
|
||
async function runRequest(user: USER): Promise<MlCapabilitiesResponse> { | ||
const { body } = await supertest | ||
.get(`/api/ml/ml_capabilities`) | ||
.auth(user, ml.securityCommon.getPasswordForUser(user)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.expect(200); | ||
|
||
return body; | ||
} | ||
|
||
describe('ml_capabilities', () => { | ||
describe('get capabilities', function () { | ||
it('should be enabled in space', async () => { | ||
const { mlFeatureEnabledInSpace } = await runRequest(USER.ML_POWERUSER); | ||
expect(mlFeatureEnabledInSpace).to.eql(true); | ||
}); | ||
|
||
it('should have upgradeInProgress false', async () => { | ||
const { upgradeInProgress } = await runRequest(USER.ML_POWERUSER); | ||
expect(upgradeInProgress).to.eql(false); | ||
}); | ||
|
||
it('should have full license', async () => { | ||
const { isPlatinumOrTrialLicense } = await runRequest(USER.ML_POWERUSER); | ||
expect(isPlatinumOrTrialLicense).to.eql(true); | ||
}); | ||
|
||
it('should have the right number of capabilities', async () => { | ||
const { capabilities } = await runRequest(USER.ML_POWERUSER); | ||
expect(Object.keys(capabilities).length).to.eql(29); | ||
}); | ||
|
||
it('should get viewer capabilities', async () => { | ||
const { capabilities } = await runRequest(USER.ML_VIEWER); | ||
|
||
expect(capabilities).to.eql({ | ||
canCreateJob: false, | ||
canDeleteJob: false, | ||
canOpenJob: false, | ||
canCloseJob: false, | ||
canUpdateJob: false, | ||
canForecastJob: false, | ||
canCreateDatafeed: false, | ||
canDeleteDatafeed: false, | ||
canStartStopDatafeed: false, | ||
canUpdateDatafeed: false, | ||
canPreviewDatafeed: false, | ||
canGetFilters: false, | ||
canCreateCalendar: false, | ||
canDeleteCalendar: false, | ||
canCreateFilter: false, | ||
canDeleteFilter: false, | ||
canCreateDataFrameAnalytics: false, | ||
canDeleteDataFrameAnalytics: false, | ||
canStartStopDataFrameAnalytics: false, | ||
canCreateMlAlerts: false, | ||
canAccessML: true, | ||
canGetJobs: true, | ||
canGetDatafeeds: true, | ||
canGetCalendars: true, | ||
canFindFileStructure: true, | ||
canGetDataFrameAnalytics: true, | ||
canGetAnnotations: true, | ||
canCreateAnnotation: true, | ||
canDeleteAnnotation: true, | ||
}); | ||
}); | ||
|
||
it('should get power user capabilities', async () => { | ||
const { capabilities } = await runRequest(USER.ML_POWERUSER); | ||
|
||
expect(capabilities).to.eql({ | ||
canCreateJob: true, | ||
canDeleteJob: true, | ||
canOpenJob: true, | ||
canCloseJob: true, | ||
canUpdateJob: true, | ||
canForecastJob: true, | ||
canCreateDatafeed: true, | ||
canDeleteDatafeed: true, | ||
canStartStopDatafeed: true, | ||
canUpdateDatafeed: true, | ||
canPreviewDatafeed: true, | ||
canGetFilters: true, | ||
canCreateCalendar: true, | ||
canDeleteCalendar: true, | ||
canCreateFilter: true, | ||
canDeleteFilter: true, | ||
canCreateDataFrameAnalytics: true, | ||
canDeleteDataFrameAnalytics: true, | ||
canStartStopDataFrameAnalytics: true, | ||
canCreateMlAlerts: true, | ||
canAccessML: true, | ||
canGetJobs: true, | ||
canGetDatafeeds: true, | ||
canGetCalendars: true, | ||
canFindFileStructure: true, | ||
canGetDataFrameAnalytics: true, | ||
canGetAnnotations: true, | ||
canCreateAnnotation: true, | ||
canDeleteAnnotation: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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('system', function () { | ||
loadTestFile(require.resolve('./capabilities')); | ||
loadTestFile(require.resolve('./space_capabilities')); | ||
}); | ||
} |
222 changes: 222 additions & 0 deletions
222
x-pack/test/api_integration/apis/ml/system/space_capabilities.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,222 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api'; | ||
import { USER } from '../../../../functional/services/ml/security_common'; | ||
import { MlCapabilitiesResponse } from '../../../../../plugins/ml/common/types/capabilities'; | ||
|
||
const idSpaceWithMl = 'space_with_ml'; | ||
const idSpaceNoMl = 'space_no_ml'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const supertest = getService('supertestWithoutAuth'); | ||
const spacesService = getService('spaces'); | ||
const ml = getService('ml'); | ||
|
||
async function runRequest(user: USER, space?: string): Promise<MlCapabilitiesResponse> { | ||
const { body } = await supertest | ||
.get(`${space ? `/s/${space}` : ''}/api/ml/ml_capabilities`) | ||
.auth(user, ml.securityCommon.getPasswordForUser(user)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.expect(200); | ||
|
||
return body; | ||
} | ||
|
||
describe('ml_capabilities in spaces', () => { | ||
before(async () => { | ||
await spacesService.create({ id: idSpaceWithMl, name: 'space_one', disabledFeatures: [] }); | ||
await spacesService.create({ id: idSpaceNoMl, name: 'space_two', disabledFeatures: ['ml'] }); | ||
}); | ||
|
||
after(async () => { | ||
await spacesService.delete(idSpaceWithMl); | ||
await spacesService.delete(idSpaceNoMl); | ||
}); | ||
|
||
describe('get capabilities', function () { | ||
it('should be enabled in space - space with ML', async () => { | ||
const { mlFeatureEnabledInSpace } = await runRequest(USER.ML_POWERUSER, idSpaceWithMl); | ||
expect(mlFeatureEnabledInSpace).to.eql(true); | ||
}); | ||
it('should not be enabled in space - space without ML', async () => { | ||
const { mlFeatureEnabledInSpace } = await runRequest(USER.ML_POWERUSER, idSpaceNoMl); | ||
expect(mlFeatureEnabledInSpace).to.eql(false); | ||
}); | ||
|
||
it('should have upgradeInProgress false - space with ML', async () => { | ||
const { upgradeInProgress } = await runRequest(USER.ML_POWERUSER, idSpaceWithMl); | ||
expect(upgradeInProgress).to.eql(false); | ||
}); | ||
it('should have upgradeInProgress false - space without ML', async () => { | ||
const { upgradeInProgress } = await runRequest(USER.ML_POWERUSER, idSpaceNoMl); | ||
expect(upgradeInProgress).to.eql(false); | ||
}); | ||
|
||
it('should have full license - space with ML', async () => { | ||
const { isPlatinumOrTrialLicense } = await runRequest(USER.ML_POWERUSER, idSpaceWithMl); | ||
expect(isPlatinumOrTrialLicense).to.eql(true); | ||
}); | ||
it('should have full license - space without ML', async () => { | ||
const { isPlatinumOrTrialLicense } = await runRequest(USER.ML_POWERUSER, idSpaceNoMl); | ||
expect(isPlatinumOrTrialLicense).to.eql(true); | ||
}); | ||
|
||
it('should have the right number of capabilities - space with ML', async () => { | ||
const { capabilities } = await runRequest(USER.ML_POWERUSER, idSpaceWithMl); | ||
expect(Object.keys(capabilities).length).to.eql(29); | ||
}); | ||
it('should have the right number of capabilities - space without ML', async () => { | ||
const { capabilities } = await runRequest(USER.ML_POWERUSER, idSpaceNoMl); | ||
expect(Object.keys(capabilities).length).to.eql(29); | ||
}); | ||
|
||
it('should get viewer capabilities - space with ML', async () => { | ||
const { capabilities } = await runRequest(USER.ML_VIEWER, idSpaceWithMl); | ||
expect(capabilities).to.eql({ | ||
canCreateJob: false, | ||
canDeleteJob: false, | ||
canOpenJob: false, | ||
canCloseJob: false, | ||
canUpdateJob: false, | ||
canForecastJob: false, | ||
canCreateDatafeed: false, | ||
canDeleteDatafeed: false, | ||
canStartStopDatafeed: false, | ||
canUpdateDatafeed: false, | ||
canPreviewDatafeed: false, | ||
canGetFilters: false, | ||
canCreateCalendar: false, | ||
canDeleteCalendar: false, | ||
canCreateFilter: false, | ||
canDeleteFilter: false, | ||
canCreateDataFrameAnalytics: false, | ||
canDeleteDataFrameAnalytics: false, | ||
canStartStopDataFrameAnalytics: false, | ||
canCreateMlAlerts: false, | ||
canAccessML: true, | ||
canGetJobs: true, | ||
canGetDatafeeds: true, | ||
canGetCalendars: true, | ||
canFindFileStructure: true, | ||
canGetDataFrameAnalytics: true, | ||
canGetAnnotations: true, | ||
canCreateAnnotation: true, | ||
canDeleteAnnotation: true, | ||
}); | ||
}); | ||
|
||
it('should get viewer capabilities - space without ML', async () => { | ||
const { capabilities } = await runRequest(USER.ML_VIEWER, idSpaceNoMl); | ||
expect(capabilities).to.eql({ | ||
canCreateJob: false, | ||
canDeleteJob: false, | ||
canOpenJob: false, | ||
canCloseJob: false, | ||
canUpdateJob: false, | ||
canForecastJob: false, | ||
canCreateDatafeed: false, | ||
canDeleteDatafeed: false, | ||
canStartStopDatafeed: false, | ||
canUpdateDatafeed: false, | ||
canPreviewDatafeed: false, | ||
canGetFilters: false, | ||
canCreateCalendar: false, | ||
canDeleteCalendar: false, | ||
canCreateFilter: false, | ||
canDeleteFilter: false, | ||
canCreateDataFrameAnalytics: false, | ||
canDeleteDataFrameAnalytics: false, | ||
canStartStopDataFrameAnalytics: false, | ||
canCreateMlAlerts: false, | ||
canAccessML: false, | ||
canGetJobs: false, | ||
canGetDatafeeds: false, | ||
canGetCalendars: false, | ||
canFindFileStructure: false, | ||
canGetDataFrameAnalytics: false, | ||
canGetAnnotations: false, | ||
canCreateAnnotation: false, | ||
canDeleteAnnotation: false, | ||
}); | ||
}); | ||
|
||
it('should get power user capabilities - space with ML', async () => { | ||
const { capabilities } = await runRequest(USER.ML_POWERUSER, idSpaceWithMl); | ||
expect(capabilities).to.eql({ | ||
canCreateJob: true, | ||
canDeleteJob: true, | ||
canOpenJob: true, | ||
canCloseJob: true, | ||
canUpdateJob: true, | ||
canForecastJob: true, | ||
canCreateDatafeed: true, | ||
canDeleteDatafeed: true, | ||
canStartStopDatafeed: true, | ||
canUpdateDatafeed: true, | ||
canPreviewDatafeed: true, | ||
canGetFilters: true, | ||
canCreateCalendar: true, | ||
canDeleteCalendar: true, | ||
canCreateFilter: true, | ||
canDeleteFilter: true, | ||
canCreateDataFrameAnalytics: true, | ||
canDeleteDataFrameAnalytics: true, | ||
canStartStopDataFrameAnalytics: true, | ||
canCreateMlAlerts: true, | ||
canAccessML: true, | ||
canGetJobs: true, | ||
canGetDatafeeds: true, | ||
canGetCalendars: true, | ||
canFindFileStructure: true, | ||
canGetDataFrameAnalytics: true, | ||
canGetAnnotations: true, | ||
canCreateAnnotation: true, | ||
canDeleteAnnotation: true, | ||
}); | ||
}); | ||
|
||
it('should get power user capabilities - space without ML', async () => { | ||
const { capabilities } = await runRequest(USER.ML_POWERUSER, idSpaceNoMl); | ||
expect(capabilities).to.eql({ | ||
canCreateJob: false, | ||
canDeleteJob: false, | ||
canOpenJob: false, | ||
canCloseJob: false, | ||
canUpdateJob: false, | ||
canForecastJob: false, | ||
canCreateDatafeed: false, | ||
canDeleteDatafeed: false, | ||
canStartStopDatafeed: false, | ||
canUpdateDatafeed: false, | ||
canPreviewDatafeed: false, | ||
canGetFilters: false, | ||
canCreateCalendar: false, | ||
canDeleteCalendar: false, | ||
canCreateFilter: false, | ||
canDeleteFilter: false, | ||
canCreateDataFrameAnalytics: false, | ||
canDeleteDataFrameAnalytics: false, | ||
canStartStopDataFrameAnalytics: false, | ||
canCreateMlAlerts: false, | ||
canAccessML: false, | ||
canGetJobs: false, | ||
canGetDatafeeds: false, | ||
canGetCalendars: false, | ||
canFindFileStructure: false, | ||
canGetDataFrameAnalytics: false, | ||
canGetAnnotations: false, | ||
canCreateAnnotation: false, | ||
canDeleteAnnotation: false, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |