Add test for okta auth custom scope
Signed-off-by: ataylorme <andrew@ataylor.me>
This commit is contained in:
@@ -17,13 +17,14 @@
|
||||
import { OktaAuthProvider } from './provider';
|
||||
import * as helpers from '../../lib/passport/PassportStrategyHelper';
|
||||
import { OAuthResult } from '../../lib/oauth';
|
||||
import { AuthResolverContext } from '../types';
|
||||
import { AuthResolverContext, OAuthStartResponse } from '../types';
|
||||
|
||||
jest.mock('../../lib/passport/PassportStrategyHelper', () => {
|
||||
return {
|
||||
executeFrameHandlerStrategy: jest.fn(),
|
||||
executeRefreshTokenStrategy: jest.fn(),
|
||||
executeFetchUserProfileStrategy: jest.fn(),
|
||||
executeRedirectStrategy: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -34,6 +35,11 @@ const mockFrameHandler = jest.spyOn(
|
||||
() => Promise<{ result: OAuthResult; privateInfo: any }>
|
||||
>;
|
||||
|
||||
const mockRedirectStrategy = jest.spyOn(
|
||||
helpers,
|
||||
'executeRedirectStrategy',
|
||||
) as unknown as jest.MockedFunction<() => Promise<OAuthStartResponse>>;
|
||||
|
||||
describe('createOktaProvider', () => {
|
||||
it('should auth', async () => {
|
||||
const provider = new OktaAuthProvider({
|
||||
@@ -97,4 +103,40 @@ describe('createOktaProvider', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass a custom scope to start and refresh requests', async () => {
|
||||
const mockScope = 'openid profile email offline_access groups';
|
||||
const reqScope = 'openid profile email offline_access';
|
||||
const provider = new OktaAuthProvider({
|
||||
resolverContext: {} as AuthResolverContext,
|
||||
authHandler: async ({ fullProfile }) => ({
|
||||
profile: {
|
||||
email: fullProfile.emails![0]!.value,
|
||||
displayName: fullProfile.displayName,
|
||||
},
|
||||
}),
|
||||
audience: 'http://example.com',
|
||||
clientId: 'mock',
|
||||
clientSecret: 'mock',
|
||||
callbackUrl: 'mock',
|
||||
scope: mockScope,
|
||||
});
|
||||
|
||||
mockRedirectStrategy.mockResolvedValueOnce({
|
||||
url: 'http://example.com/',
|
||||
});
|
||||
|
||||
const req: any = {
|
||||
state: {
|
||||
nonce: 'nonce',
|
||||
env: 'development',
|
||||
},
|
||||
scope: reqScope,
|
||||
};
|
||||
|
||||
await provider.start(req);
|
||||
const mockCallScope = (mockRedirectStrategy.mock.calls[0] as any)?.[2]
|
||||
?.scope;
|
||||
expect(mockCallScope).toBe(mockScope);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user