-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathauthStatus.test.ts
More file actions
92 lines (74 loc) · 4.14 KB
/
authStatus.test.ts
File metadata and controls
92 lines (74 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { describe, expect, it } from 'vitest';
import { handshake, machineAuthenticated, machineUnauthenticated, signedIn, signedOut } from '../authStatus';
describe('signed-in', () => {
it('does not include debug headers', () => {
const authObject = signedIn({} as any, {} as any, undefined, 'token');
expect(authObject.headers.get('x-clerk-auth-status')).toBeNull();
expect(authObject.headers.get('x-clerk-auth-reason')).toBeNull();
expect(authObject.headers.get('x-clerk-auth-message')).toBeNull();
});
it('authObject returned by toAuth() returns the token passed', async () => {
const signedInAuthObject = signedIn({} as any, { sid: 'sid' } as any, undefined, 'token').toAuth();
const token = await signedInAuthObject.getToken();
expect(token).toBe('token');
});
});
describe('signed-out', () => {
it('includes debug headers', () => {
const headers = new Headers({ 'custom-header': 'value' });
const authObject = signedOut({} as any, 'auth-reason', 'auth-message', headers);
expect(authObject.headers.get('custom-header')).toBe('value');
expect(authObject.headers.get('x-clerk-auth-status')).toBe('signed-out');
expect(authObject.headers.get('x-clerk-auth-reason')).toBe('auth-reason');
expect(authObject.headers.get('x-clerk-auth-message')).toBe('auth-message');
});
it('handles debug headers containing invalid unicode characters without throwing', () => {
const headers = new Headers({ 'custom-header': 'value' });
const authObject = signedOut({} as any, 'auth-reason+RR�56', 'auth-message+RR�56', headers);
expect(authObject.headers.get('custom-header')).toBe('value');
expect(authObject.headers.get('x-clerk-auth-status')).toBe('signed-out');
expect(authObject.headers.get('x-clerk-auth-reason')).toBeNull();
expect(authObject.headers.get('x-clerk-auth-message')).toBeNull();
});
});
describe('machine-unauthenticated', () => {
it('includes debug headers', () => {
const headers = new Headers({ 'custom-header': 'value' });
const authObject = machineUnauthenticated({} as any, 'auth-reason', 'auth-message', headers);
expect(authObject.headers.get('custom-header')).toBe('value');
expect(authObject.headers.get('x-clerk-auth-status')).toBe('machine-unauthenticated');
expect(authObject.headers.get('x-clerk-auth-reason')).toBe('auth-reason');
expect(authObject.headers.get('x-clerk-auth-message')).toBe('auth-message');
});
it('handles debug headers containing invalid unicode characters without throwing', () => {
const headers = new Headers({ 'custom-header': 'value' });
const authObject = machineUnauthenticated({} as any, 'auth-reason+RR�56', 'auth-message+RR�56', headers);
expect(authObject.headers.get('custom-header')).toBe('value');
expect(authObject.headers.get('x-clerk-auth-status')).toBe('machine-unauthenticated');
expect(authObject.headers.get('x-clerk-auth-reason')).toBeNull();
expect(authObject.headers.get('x-clerk-auth-message')).toBeNull();
});
});
describe('machine-authenticated', () => {
it('does not include debug headers', () => {
const authObject = machineAuthenticated({} as any, undefined, 'token', {} as any);
expect(authObject.headers.get('x-clerk-auth-status')).toBeNull();
expect(authObject.headers.get('x-clerk-auth-reason')).toBeNull();
expect(authObject.headers.get('x-clerk-auth-message')).toBeNull();
});
it('authObject returned by toAuth() returns the token passed', async () => {
const signedInAuthObject = signedIn({} as any, { sid: 'sid' } as any, undefined, 'token').toAuth();
const token = await signedInAuthObject.getToken();
expect(token).toBe('token');
});
});
describe('handshake', () => {
it('includes debug headers', () => {
const headers = new Headers({ location: '/' });
const authObject = handshake({} as any, 'auth-reason', 'auth-message', headers);
expect(authObject.headers.get('location')).toBe('/');
expect(authObject.headers.get('x-clerk-auth-status')).toBe('handshake');
expect(authObject.headers.get('x-clerk-auth-reason')).toBe('auth-reason');
expect(authObject.headers.get('x-clerk-auth-message')).toBe('auth-message');
});
});