Skip to content

Commit 0530eee

Browse files
committed
fix authcode tests
1 parent 0c23375 commit 0530eee

File tree

2 files changed

+17
-59
lines changed

2 files changed

+17
-59
lines changed

packages/wallet/wdk/test/authcode-pkce.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('AuthCodePkceHandler', () => {
5656
handler = new AuthCodePkceHandler(
5757
'google-pkce',
5858
'https://accounts.google.com',
59+
'https://accounts.google.com/o/oauth2/v2/auth',
5960
'test-google-client-id',
6061
mockNitroInstrument,
6162
mockSignatures,
@@ -81,8 +82,6 @@ describe('AuthCodePkceHandler', () => {
8182
8283
}
8384
})
84-
85-
vi.spyOn(handler as any, 'oauthUrl').mockReturnValue('https://accounts.google.com/oauth/authorize')
8685
})
8786

8887
afterEach(() => {
@@ -116,7 +115,7 @@ describe('AuthCodePkceHandler', () => {
116115
})
117116

118117
// Verify OAuth URL is constructed correctly
119-
expect(result).toMatch(/^https:\/\/accounts\.google\.com\/oauth\/authorize\?/)
118+
expect(result).toMatch(/^https:\/\/accounts\.google\.com\/o\/oauth2\/v2\/auth\?/)
120119
expect(result).toContain('code_challenge=mock-challenge-hash')
121120
expect(result).toContain('code_challenge_method=S256')
122121
expect(result).toContain('client_id=test-google-client-id')
@@ -335,19 +334,16 @@ describe('AuthCodePkceHandler', () => {
335334
const newRedirectUri = 'https://newdomain.com/callback'
336335
handler.setRedirectUri(newRedirectUri)
337336

338-
// Verify redirect URI is used in OAuth URL construction
339-
const mockUrl = 'https://accounts.google.com/oauth/authorize'
340-
vi.spyOn(handler as any, 'oauthUrl').mockReturnValue(mockUrl)
341-
342337
return handler.commitAuth('https://example.com/success', true).then((result) => {
343338
expect(result).toContain(`redirect_uri=${encodeURIComponent(newRedirectUri)}`)
344339
})
345340
})
346341

347342
it('Should work with different issuer and audience configurations', () => {
348343
const customHandler = new AuthCodePkceHandler(
349-
'google-pkce',
344+
'custom-provider',
350345
'https://custom-issuer.com',
346+
'https://custom-issuer.com/o/oauth2/v2/auth',
351347
'custom-client-id',
352348
mockNitroInstrument,
353349
mockSignatures,
@@ -357,7 +353,7 @@ describe('AuthCodePkceHandler', () => {
357353

358354
expect(customHandler['issuer']).toBe('https://custom-issuer.com')
359355
expect(customHandler['audience']).toBe('custom-client-id')
360-
expect(customHandler.signupKind).toBe('google-pkce')
356+
expect(customHandler.signupKind).toBe('custom-provider')
361357
})
362358
})
363359
})

packages/wallet/wdk/test/authcode.test.ts

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ describe('AuthCodeHandler', () => {
129129
authCodeHandler = new AuthCodeHandler(
130130
'google-pkce',
131131
'https://accounts.google.com',
132+
'https://accounts.google.com/o/oauth2/v2/auth',
132133
'test-audience',
133134
mockIdentityInstrument,
134135
mockSignatures,
@@ -148,6 +149,7 @@ describe('AuthCodeHandler', () => {
148149
const handler = new AuthCodeHandler(
149150
'google-pkce',
150151
'https://accounts.google.com',
152+
'https://accounts.google.com/o/oauth2/v2/auth',
151153
'google-client-id',
152154
mockIdentityInstrument,
153155
mockSignatures,
@@ -165,6 +167,7 @@ describe('AuthCodeHandler', () => {
165167
const handler = new AuthCodeHandler(
166168
'apple',
167169
'https://appleid.apple.com',
170+
'https://appleid.apple.com/auth/authorize',
168171
'apple-client-id',
169172
mockIdentityInstrument,
170173
mockSignatures,
@@ -189,6 +192,7 @@ describe('AuthCodeHandler', () => {
189192
const googleHandler = new AuthCodeHandler(
190193
'google-pkce',
191194
'https://accounts.google.com',
195+
'https://accounts.google.com/o/oauth2/v2/auth',
192196
'test-audience',
193197
mockIdentityInstrument,
194198
mockSignatures,
@@ -203,6 +207,7 @@ describe('AuthCodeHandler', () => {
203207
const appleHandler = new AuthCodeHandler(
204208
'apple',
205209
'https://appleid.apple.com',
210+
'https://appleid.apple.com/auth/authorize',
206211
'test-audience',
207212
mockIdentityInstrument,
208213
mockSignatures,
@@ -293,6 +298,7 @@ describe('AuthCodeHandler', () => {
293298
const appleHandler = new AuthCodeHandler(
294299
'apple',
295300
'https://appleid.apple.com',
301+
'https://appleid.apple.com/auth/authorize',
296302
'apple-client-id',
297303
mockIdentityInstrument,
298304
mockSignatures,
@@ -491,52 +497,40 @@ describe('AuthCodeHandler', () => {
491497
})
492498
})
493499

494-
// === OAUTH URL METHOD ===
500+
// === OAUTH URL PROPERTY ===
495501

496-
describe('oauthUrl()', () => {
502+
describe('oauthUrl', () => {
497503
it('Should return Google OAuth URL for Google issuer', () => {
498504
const googleHandler = new AuthCodeHandler(
499505
'google-pkce',
500506
'https://accounts.google.com',
507+
'https://accounts.google.com/o/oauth2/v2/auth',
501508
'test-audience',
502509
mockIdentityInstrument,
503510
mockSignatures,
504511
mockAuthCommitments,
505512
mockAuthKeys,
506513
)
507514

508-
const url = googleHandler['oauthUrl']()
515+
const url = googleHandler['oauthUrl']
509516
expect(url).toBe('https://accounts.google.com/o/oauth2/v2/auth')
510517
})
511518

512519
it('Should return Apple OAuth URL for Apple issuer', () => {
513520
const appleHandler = new AuthCodeHandler(
514521
'apple',
515522
'https://appleid.apple.com',
523+
'https://appleid.apple.com/auth/authorize',
516524
'test-audience',
517525
mockIdentityInstrument,
518526
mockSignatures,
519527
mockAuthCommitments,
520528
mockAuthKeys,
521529
)
522530

523-
const url = appleHandler['oauthUrl']()
531+
const url = appleHandler['oauthUrl']
524532
expect(url).toBe('https://appleid.apple.com/auth/authorize')
525533
})
526-
527-
it('Should throw error for unsupported issuer', () => {
528-
const unsupportedHandler = new AuthCodeHandler(
529-
'google-pkce',
530-
'https://unsupported.provider.com',
531-
'test-audience',
532-
mockIdentityInstrument,
533-
mockSignatures,
534-
mockAuthCommitments,
535-
mockAuthKeys,
536-
)
537-
538-
expect(() => unsupportedHandler['oauthUrl']()).toThrow('unsupported-issuer')
539-
})
540534
})
541535

542536
// === INHERITED METHODS FROM IDENTITYHANDLER ===
@@ -711,38 +705,6 @@ describe('AuthCodeHandler', () => {
711705
expect(metadata.email).toBe('[email protected]')
712706
})
713707

714-
it('Should handle different OAuth providers correctly', async () => {
715-
const providers = [
716-
{
717-
signupKind: 'google-pkce' as const,
718-
issuer: 'https://accounts.google.com',
719-
expectedUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
720-
},
721-
{
722-
signupKind: 'apple' as const,
723-
issuer: 'https://appleid.apple.com',
724-
expectedUrl: 'https://appleid.apple.com/auth/authorize',
725-
},
726-
]
727-
728-
for (const provider of providers) {
729-
const handler = new AuthCodeHandler(
730-
provider.signupKind,
731-
provider.issuer,
732-
'test-audience',
733-
mockIdentityInstrument,
734-
mockSignatures,
735-
mockAuthCommitments,
736-
mockAuthKeys,
737-
)
738-
handler.setRedirectUri('https://example.com/callback')
739-
740-
const url = await handler.commitAuth('/target', false)
741-
expect(url).toContain(provider.expectedUrl)
742-
expect(handler.kind).toBe(`login-${provider.signupKind}`)
743-
}
744-
})
745-
746708
it('Should handle signup vs login flows correctly', async () => {
747709
authCodeHandler.setRedirectUri('https://example.com/callback')
748710

0 commit comments

Comments
 (0)