deno.land / x / oauth4webapi@v1.2.2 / test / revocation.test.ts

revocation.test.ts
View Documentation
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import anyTest, { type TestFn } from 'ava'import setup, { type Context, teardown, issuer, endpoint, client, getResponse, UA,} from './_setup.js'import * as lib from '../src/index.js'
const test = anyTest as TestFn<Context>
test.before(setup)test.after(teardown)
const tClient: lib.Client = { ...client, client_secret: 'foo' }
test('revocationRequest()', async (t) => { await t.throwsAsync(lib.revocationRequest(issuer, tClient, 'token'), { message: '"as.revocation_endpoint" must be a string', })
await t.throwsAsync(lib.revocationRequest(issuer, tClient, <any>null), { message: '"token" must be a non-empty string', })
const tIssuer: lib.AuthorizationServer = { ...issuer, revocation_endpoint: endpoint('revoke-1'), }
t.context .intercept({ path: '/revoke-1', method: 'POST', headers: { accept: '*/*', 'user-agent': UA, }, body(body) { return new URLSearchParams(body).get('token') === 'token' }, }) .reply(200, { access_token: 'token', token_type: 'Bearer' })
await t.notThrowsAsync(lib.revocationRequest(tIssuer, tClient, 'token'))})
test('revocationRequest() w/ Extra Parameters', async (t) => { const tIssuer: lib.AuthorizationServer = { ...issuer, revocation_endpoint: endpoint('revoke-2'), }
t.context .intercept({ path: '/revoke-2', method: 'POST', body(body) { return new URLSearchParams(body).get('token_type_hint') === 'access_token' }, }) .reply(200, { access_token: 'token', token_type: 'Bearer' })
await t.notThrowsAsync( lib.revocationRequest(tIssuer, tClient, 'token', { additionalParameters: new URLSearchParams('token_type_hint=access_token'), }), )})
test('revocationRequest() w/ Custom Headers', async (t) => { const tIssuer: lib.AuthorizationServer = { ...issuer, revocation_endpoint: endpoint('revoke-headers'), }
t.context .intercept({ path: '/revoke-headers', method: 'POST', headers(headers) { t.is(headers['user-agent'], 'foo') t.is(headers.foo, 'bar') t.is(headers.accept, '*/*') return true }, }) .reply(200, { access_token: 'token', token_type: 'Bearer' })
await t.notThrowsAsync( lib.revocationRequest(tIssuer, tClient, 'token', { headers: new Headers([ ['accept', 'will be overwritten'], ['user-agent', 'foo'], ['foo', 'bar'], ]), }), )})
test('processRevocationResponse()', async (t) => { await t.throwsAsync(lib.processRevocationResponse(<any>null), { message: '"response" must be an instance of Response', }) await t.throwsAsync(lib.processRevocationResponse(getResponse('', { status: 404 })), { message: '"response" is not a conform Revocation Endpoint response', })
t.is(await lib.processRevocationResponse(getResponse('')), undefined)
t.true( lib.isOAuth2Error( await lib.processRevocationResponse( getResponse(JSON.stringify({ error: 'invalid_client' }), { status: 401 }), ), ), )})
oauth4webapi

Version Info

Tagged at
2 years ago