|
3 | 3 | * SPDX-License-Identifier: Apache-2.0
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import { OnPreRoutingHandler } from 'src/core/server'; |
| 6 | +import { OnPostAuthHandler, OnPreRoutingHandler } from 'src/core/server'; |
7 | 7 | import { coreMock, httpServerMock } from '../../../core/server/mocks';
|
8 | 8 | import { WorkspacePlugin } from './plugin';
|
9 | 9 | import { getWorkspaceState } from '../../../core/server/utils';
|
| 10 | +import * as utilsExports from './utils'; |
10 | 11 |
|
11 | 12 | describe('Workspace server plugin', () => {
|
12 | 13 | it('#setup', async () => {
|
@@ -67,6 +68,70 @@ describe('Workspace server plugin', () => {
|
67 | 68 | expect(toolKitMock.next).toBeCalledTimes(1);
|
68 | 69 | });
|
69 | 70 |
|
| 71 | + describe('#setupPermission', () => { |
| 72 | + const setupMock = coreMock.createSetup(); |
| 73 | + const initializerContextConfigMock = coreMock.createPluginInitializerContext({ |
| 74 | + enabled: true, |
| 75 | + permission: { |
| 76 | + enabled: true, |
| 77 | + }, |
| 78 | + }); |
| 79 | + let registerOnPostAuthFn: OnPostAuthHandler = () => httpServerMock.createResponseFactory().ok(); |
| 80 | + setupMock.http.registerOnPostAuth.mockImplementation((fn) => { |
| 81 | + registerOnPostAuthFn = fn; |
| 82 | + return fn; |
| 83 | + }); |
| 84 | + const workspacePlugin = new WorkspacePlugin(initializerContextConfigMock); |
| 85 | + const requestWithWorkspaceInUrl = httpServerMock.createOpenSearchDashboardsRequest({ |
| 86 | + path: '/w/foo/app', |
| 87 | + }); |
| 88 | + |
| 89 | + it('catch error', async () => { |
| 90 | + await workspacePlugin.setup(setupMock); |
| 91 | + const toolKitMock = httpServerMock.createToolkit(); |
| 92 | + |
| 93 | + await registerOnPostAuthFn( |
| 94 | + requestWithWorkspaceInUrl, |
| 95 | + httpServerMock.createResponseFactory(), |
| 96 | + toolKitMock |
| 97 | + ); |
| 98 | + expect(toolKitMock.next).toBeCalledTimes(1); |
| 99 | + }); |
| 100 | + |
| 101 | + it('with yml config', async () => { |
| 102 | + jest |
| 103 | + .spyOn(utilsExports, 'getPrincipalsFromRequest') |
| 104 | + .mockImplementation(() => ({ users: [`user1`] })); |
| 105 | + jest |
| 106 | + .spyOn(utilsExports, 'getOSDAdminConfigFromYMLConfig') |
| 107 | + .mockResolvedValue([['group1'], ['user1']]); |
| 108 | + |
| 109 | + await workspacePlugin.setup(setupMock); |
| 110 | + const toolKitMock = httpServerMock.createToolkit(); |
| 111 | + |
| 112 | + await registerOnPostAuthFn( |
| 113 | + requestWithWorkspaceInUrl, |
| 114 | + httpServerMock.createResponseFactory(), |
| 115 | + toolKitMock |
| 116 | + ); |
| 117 | + expect(toolKitMock.next).toBeCalledTimes(1); |
| 118 | + }); |
| 119 | + |
| 120 | + it('uninstall security plugin', async () => { |
| 121 | + jest.spyOn(utilsExports, 'getPrincipalsFromRequest').mockImplementation(() => ({})); |
| 122 | + |
| 123 | + await workspacePlugin.setup(setupMock); |
| 124 | + const toolKitMock = httpServerMock.createToolkit(); |
| 125 | + |
| 126 | + await registerOnPostAuthFn( |
| 127 | + requestWithWorkspaceInUrl, |
| 128 | + httpServerMock.createResponseFactory(), |
| 129 | + toolKitMock |
| 130 | + ); |
| 131 | + expect(toolKitMock.next).toBeCalledTimes(1); |
| 132 | + }); |
| 133 | + }); |
| 134 | + |
70 | 135 | it('#start', async () => {
|
71 | 136 | const setupMock = coreMock.createSetup();
|
72 | 137 | const startMock = coreMock.createStart();
|
|
0 commit comments