-
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.
- Loading branch information
Showing
11 changed files
with
303 additions
and
14 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
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
72 changes: 72 additions & 0 deletions
72
...ns/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.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,72 @@ | ||
/* | ||
* 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 { httpServerMock, httpServiceMock, loggingSystemMock } from 'src/core/server/mocks'; | ||
import // eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
'src/core/server/elasticsearch/client/mocks'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { KibanaRequest } from 'src/core/server/http/router/request'; | ||
import { defineGetComplianceDashboardRoute } from './compliance_dashboard'; | ||
|
||
import { CspAppService } from '../../lib/csp_app_services'; | ||
import { CspAppContext } from '../../plugin'; | ||
|
||
describe('compliance dashboard permissions API', () => { | ||
let logger: ReturnType<typeof loggingSystemMock.createLogger>; | ||
|
||
beforeEach(() => { | ||
logger = loggingSystemMock.createLogger(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should accept to a user with fleet.all privilege', async () => { | ||
const router = httpServiceMock.createRouter(); | ||
const cspAppContextService = new CspAppService(); | ||
|
||
const cspContext: CspAppContext = { | ||
logger, | ||
service: cspAppContextService, | ||
}; | ||
defineGetComplianceDashboardRoute(router, cspContext); | ||
const [_, handler] = router.get.mock.calls[0]; | ||
|
||
const mockContext = { | ||
fleet: { authz: { fleet: { all: true } } }, | ||
} as unknown as KibanaRequest; | ||
|
||
const mockResponse = httpServerMock.createResponseFactory(); | ||
const mockRequest = httpServerMock.createKibanaRequest(); | ||
const [context, req, res] = [mockContext, mockRequest, mockResponse]; | ||
|
||
await handler(context, req, res); | ||
|
||
expect(res.forbidden).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('should reject to a user without fleet.all privilege', async () => { | ||
const router = httpServiceMock.createRouter(); | ||
const cspAppContextService = new CspAppService(); | ||
|
||
const cspContext: CspAppContext = { | ||
logger, | ||
service: cspAppContextService, | ||
}; | ||
defineGetComplianceDashboardRoute(router, cspContext); | ||
const [_, handler] = router.get.mock.calls[0]; | ||
|
||
const mockContext = { | ||
fleet: { authz: { fleet: { all: true } } }, | ||
} as unknown as KibanaRequest; | ||
|
||
const mockResponse = httpServerMock.createResponseFactory(); | ||
const mockRequest = httpServerMock.createKibanaRequest(); | ||
const [context, req, res] = [mockContext, mockRequest, mockResponse]; | ||
|
||
await handler(context, req, res); | ||
|
||
expect(res.forbidden).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
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
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
Oops, something went wrong.