Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export interface AuthenticationServiceSetup {
areAPIKeysEnabled: () => Promise<boolean>;
}

/**
* Start has the same contract as Setup for now.
*/
export type AuthenticationServiceStart = AuthenticationServiceSetup;

export class AuthenticationService {
public setup({
application,
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/security/public/authentication/index.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
* 2.0.
*/

import type { AuthenticationServiceSetup } from './authentication_service';
import type {
AuthenticationServiceSetup,
AuthenticationServiceStart,
} from './authentication_service';

export const authenticationMock = {
createSetup: (): jest.Mocked<AuthenticationServiceSetup> => ({
getCurrentUser: jest.fn(),
areAPIKeysEnabled: jest.fn(),
}),
createStart: (): jest.Mocked<AuthenticationServiceStart> => ({
getCurrentUser: jest.fn(),
areAPIKeysEnabled: jest.fn(),
}),
};
6 changes: 5 additions & 1 deletion x-pack/plugins/security/public/authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
* 2.0.
*/

export { AuthenticationService, AuthenticationServiceSetup } from './authentication_service';
export {
AuthenticationService,
AuthenticationServiceSetup,
AuthenticationServiceStart,
} from './authentication_service';
1 change: 1 addition & 0 deletions x-pack/plugins/security/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function createSetupMock() {
}
function createStartMock() {
return {
authc: authenticationMock.createStart(),
navControlService: navControlServiceMock.createStart(),
};
}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/security/public/plugin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ describe('Security Plugin', () => {
features: {} as FeaturesPluginStart,
})
).toEqual({
authc: {
getCurrentUser: expect.any(Function),
areAPIKeysEnabled: expect.any(Function),
},
navControlService: {
getUserMenuLinks$: expect.any(Function),
addUserMenuLinks: expect.any(Function),
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/security/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { LicensingPluginSetup } from '../../licensing/public';
import type { SpacesPluginStart } from '../../spaces/public';
import { SecurityLicenseService } from '../common/licensing';
import { accountManagementApp } from './account_management';
import type { AuthenticationServiceSetup } from './authentication';
import type { AuthenticationServiceSetup, AuthenticationServiceStart } from './authentication';
import { AuthenticationService } from './authentication';
import type { ConfigType } from './config';
import { ManagementService } from './management';
Expand Down Expand Up @@ -153,7 +153,10 @@ export class SecurityPlugin
this.managementService.start({ capabilities: core.application.capabilities });
}

return { navControlService: this.navControlService.start({ core }) };
return {
navControlService: this.navControlService.start({ core }),
authc: this.authc as AuthenticationServiceStart,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is to give the authorization service a real start lifecycle method so that it can expose these functions itself.

At this point, we have no need for a real start lifecycle, so this is the easier approach.

};
}

public stop() {
Expand Down