Skip to content

Commit

Permalink
Fix session manager types
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Jun 11, 2024
1 parent 9aa461c commit 87aef36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-test/src/auth/saml_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const createCloudSAMLSession = async (params: CloudSamlSessionParams) =>
const samlResponse = await createSAMLResponse({ location, ecSession, email, kbnHost, log });
const cookie = await finishSAMLHandshake({ kbnHost, samlResponse, sid, log });
const userProfile = await getSecurityProfile({ kbnHost, cookie, log });
return new Session(cookie, email, userProfile.full_name);
return new Session(cookie, email, userProfile.full_name, userProfile.username);
};

export const createLocalSAMLSession = async (params: LocalSamlSessionParams) => {
Expand Down
10 changes: 7 additions & 3 deletions packages/kbn-test/src/auth/sesson_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('SamlSessionManager', () => {
.KbnClient.mockImplementation(() => ({ version: { get } }));
get.mockImplementation(() => Promise.resolve('8.12.0'));

createLocalSAMLSessionMock.mockResolvedValue(new Session(cookieInstance, email, fullname));
createLocalSAMLSessionMock.mockResolvedValue(
new Session(cookieInstance, email, fullname, username)
);
});

const hostOptions = {
Expand All @@ -61,6 +63,7 @@ describe('SamlSessionManager', () => {
};
const email = 'testuser@elastic.com';
const fullname = 'Test User';
const username = 'test_user';
const cookieInstance = Cookie.parse(
'sid=kbn_cookie_value; Path=/; Expires=Wed, 01 Oct 2023 07:00:00 GMT'
)!;
Expand Down Expand Up @@ -149,6 +152,7 @@ describe('SamlSessionManager', () => {
)!;
const cloudEmail = 'viewer@elastic.co';
const cloudFullname = 'Test Viewer';
const cloudUsername = 'test_viewer';
const cloudUsers = new Array<[Role, User]>();
cloudUsers.push(['viewer', { email: 'viewer@elastic.co', password: 'p1234' }]);
cloudUsers.push(['editor', { email: 'editor@elastic.co', password: 'p1234' }]);
Expand Down Expand Up @@ -185,7 +189,7 @@ describe('SamlSessionManager', () => {
get.mockImplementationOnce(() => Promise.resolve('8.12.0'));

createCloudSAMLSessionMock.mockResolvedValue(
new Session(cloudCookieInstance, cloudEmail, cloudFullname)
new Session(cloudCookieInstance, cloudEmail, cloudFullname, cloudUsername)
);
readCloudUsersFromFileMock.mockReturnValue(cloudUsers);
});
Expand All @@ -202,7 +206,7 @@ describe('SamlSessionManager', () => {
test(`'getSessionCookieForRole' should return the actual cookie value`, async () => {
const samlSessionManager = new SamlSessionManager(samlSessionManagerOptions);
createCloudSAMLSessionMock.mockResolvedValue(
new Session(cloudCookieInstance, cloudEmail, cloudFullname)
new Session(cloudCookieInstance, cloudEmail, cloudFullname, cloudUsername)
);
const cookie = await samlSessionManager.getSessionCookieForRole(roleViewer);
expect(cookie).toBe(cloudCookieInstance.value);
Expand Down

0 comments on commit 87aef36

Please sign in to comment.