|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | | -import { handshake, signedIn, signedOut } from '../authStatus'; |
| 3 | +import { handshake, machineAuthenticated, machineUnauthenticated, signedIn, signedOut } from '../authStatus'; |
4 | 4 |
|
5 | 5 | describe('signed-in', () => { |
6 | 6 | it('does not include debug headers', () => { |
@@ -41,6 +41,45 @@ describe('signed-out', () => { |
41 | 41 | }); |
42 | 42 | }); |
43 | 43 |
|
| 44 | +describe('machine-unauthenticated', () => { |
| 45 | + it('includes debug headers', () => { |
| 46 | + const headers = new Headers({ 'custom-header': 'value' }); |
| 47 | + const authObject = machineUnauthenticated({} as any, 'auth-reason', 'auth-message', headers); |
| 48 | + |
| 49 | + expect(authObject.headers.get('custom-header')).toBe('value'); |
| 50 | + expect(authObject.headers.get('x-clerk-auth-status')).toBe('machine-unauthenticated'); |
| 51 | + expect(authObject.headers.get('x-clerk-auth-reason')).toBe('auth-reason'); |
| 52 | + expect(authObject.headers.get('x-clerk-auth-message')).toBe('auth-message'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('handles debug headers containing invalid unicode characters without throwing', () => { |
| 56 | + const headers = new Headers({ 'custom-header': 'value' }); |
| 57 | + const authObject = machineUnauthenticated({} as any, 'auth-reason+RR�56', 'auth-message+RR�56', headers); |
| 58 | + |
| 59 | + expect(authObject.headers.get('custom-header')).toBe('value'); |
| 60 | + expect(authObject.headers.get('x-clerk-auth-status')).toBe('machine-unauthenticated'); |
| 61 | + expect(authObject.headers.get('x-clerk-auth-reason')).toBeNull(); |
| 62 | + expect(authObject.headers.get('x-clerk-auth-message')).toBeNull(); |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
| 66 | +describe('machine-authenticated', () => { |
| 67 | + it('does not include debug headers', () => { |
| 68 | + const authObject = machineAuthenticated({} as any, undefined, 'token', {} as any); |
| 69 | + |
| 70 | + expect(authObject.headers.get('x-clerk-auth-status')).toBeNull(); |
| 71 | + expect(authObject.headers.get('x-clerk-auth-reason')).toBeNull(); |
| 72 | + expect(authObject.headers.get('x-clerk-auth-message')).toBeNull(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('authObject returned by toAuth() returns the token passed', async () => { |
| 76 | + const signedInAuthObject = signedIn({} as any, { sid: 'sid' } as any, undefined, 'token').toAuth(); |
| 77 | + const token = await signedInAuthObject.getToken(); |
| 78 | + |
| 79 | + expect(token).toBe('token'); |
| 80 | + }); |
| 81 | +}); |
| 82 | + |
44 | 83 | describe('handshake', () => { |
45 | 84 | it('includes debug headers', () => { |
46 | 85 | const headers = new Headers({ location: '/' }); |
|
0 commit comments