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.
fix check for security and added jest test (elastic#109429)
- Loading branch information
1 parent
9f2fe19
commit db02f70
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/reporting/server/routes/deprecations.test.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,83 @@ | ||
/* | ||
* 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 { of } from 'rxjs'; | ||
import { UnwrapPromise } from '@kbn/utility-types'; | ||
import { setupServer } from 'src/core/server/test_utils'; | ||
import { API_GET_ILM_POLICY_STATUS } from '../../common/constants'; | ||
import { securityMock } from '../../../security/server/mocks'; | ||
|
||
import supertest from 'supertest'; | ||
|
||
import { | ||
createMockConfigSchema, | ||
createMockPluginSetup, | ||
createMockReportingCore, | ||
createMockLevelLogger, | ||
} from '../test_helpers'; | ||
|
||
import { registerDeprecationsRoutes } from './deprecations'; | ||
|
||
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>; | ||
|
||
describe(`GET ${API_GET_ILM_POLICY_STATUS}`, () => { | ||
const reportingSymbol = Symbol('reporting'); | ||
let server: SetupServerReturn['server']; | ||
let httpSetup: SetupServerReturn['httpSetup']; | ||
|
||
const createReportingCore = ({ | ||
security, | ||
}: { | ||
security?: ReturnType<typeof securityMock.createSetup>; | ||
}) => | ||
createMockReportingCore( | ||
createMockConfigSchema({ | ||
queue: { | ||
indexInterval: 'year', | ||
timeout: 10000, | ||
pollEnabled: true, | ||
}, | ||
index: '.reporting', | ||
}), | ||
createMockPluginSetup({ | ||
security, | ||
router: httpSetup.createRouter(''), | ||
licensing: { license$: of({ isActive: true, isAvailable: true, type: 'gold' }) }, | ||
}) | ||
); | ||
|
||
beforeEach(async () => { | ||
jest.clearAllMocks(); | ||
({ server, httpSetup } = await setupServer(reportingSymbol)); | ||
}); | ||
|
||
it('correctly handles authz when security is unavailable', async () => { | ||
const core = await createReportingCore({}); | ||
|
||
registerDeprecationsRoutes(core, createMockLevelLogger()); | ||
await server.start(); | ||
|
||
await supertest(httpSetup.server.listener) | ||
.get(API_GET_ILM_POLICY_STATUS) | ||
.expect(200) | ||
.then(/* Ignore result */); | ||
}); | ||
|
||
it('correctly handles authz when security is disabled', async () => { | ||
const security = securityMock.createSetup(); | ||
security.license.isEnabled.mockReturnValue(false); | ||
const core = await createReportingCore({ security }); | ||
|
||
registerDeprecationsRoutes(core, createMockLevelLogger()); | ||
await server.start(); | ||
|
||
await supertest(httpSetup.server.listener) | ||
.get(API_GET_ILM_POLICY_STATUS) | ||
.expect(200) | ||
.then(/* Ignore result */); | ||
}); | ||
}); |
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