Skip to content

Commit

Permalink
Default to OSD admin if security uninstall
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <[email protected]>
  • Loading branch information
yubonluo committed May 23, 2024
1 parent 05a3454 commit fd10be4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/plugins/workspace/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ describe('Workspace server plugin', () => {
});

it('with yml config', async () => {
jest.spyOn(utilsExports, 'getPrincipalsFromRequest').mockImplementation(() => ({}));
jest
.spyOn(utilsExports, 'getPrincipalsFromRequest')
.mockImplementation(() => ({ users: [`user1`] }));
jest
.spyOn(utilsExports, 'getOSDAdminConfigFromYMLConfig')
.mockResolvedValue([['group1'], ['user1']]);
Expand All @@ -114,6 +116,20 @@ describe('Workspace server plugin', () => {
);
expect(toolKitMock.next).toBeCalledTimes(1);
});

it('uninstall security plugin', async () => {
jest.spyOn(utilsExports, 'getPrincipalsFromRequest').mockImplementation(() => ({}));

await workspacePlugin.setup(setupMock);
const toolKitMock = httpServerMock.createToolkit();

await registerOnPostAuthFn(
requestWithWorkspaceInUrl,
httpServerMock.createResponseFactory(),
toolKitMock
);
expect(toolKitMock.next).toBeCalledTimes(1);
});
});

it('#start', async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export class WorkspacePlugin implements Plugin<WorkspacePluginSetup, WorkspacePl
} catch (e) {
return toolkit.next();
}
// If the security plugin is not installed, login defaults to OSD Admin
if (!groups.length && !users.length) {
updateWorkspaceState(request, {
isDashboardAdmin: true,
});
return toolkit.next();
}

const [configGroups, configUsers] = await getOSDAdminConfigFromYMLConfig(this.globalConfig$);
updateDashboardAdminStateForRequest(request, groups, users, configGroups, configUsers);
Expand Down

0 comments on commit fd10be4

Please sign in to comment.