-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-autoConsent.js
245 lines (192 loc) · 7.74 KB
/
test-autoConsent.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
'use strict'
/* eslint-env mocha */
const request = require('supertest')
const assert = require('assert')
const fs = require('fs')
const { strictEqual } = assert
const jwt = require('jsonwebtoken')
const jwks = require('./resources/jwks.json')
const configuration = {
clients: [{
client_id: 'myClient',
client_secret: 'mySecret',
redirect_uris: ['http://127.0.0.1:8080/cb'],
token_endpoint_auth_method: 'private_key_jwt',
token_endpoint_auth_signing_alg: 'RS256',
jwks: {
keys: [{
kty: 'RSA',
e: 'AQAB',
kid: '7Mr9wAwdM3cisMqeWZBDvgzPjopnFYnnhJs7M3kbHHE',
n: "2l8TswKqLqq3dhbnQHl4mG01FHL7s_CmOOZyyf53gf4BpbM43lrXXezSUOYqFddQaLI0HzOt6yqYt4RRl2O1p34dxADNR11dn0A863NqW6VmE3lkrxnU_db_JOk_ZXy6kp_GBO79n35LRp8YUIBz_og6n_5TZ_kbG24d5sG60QOffRo5ogtplAlwjN3kYp8Ik9AM4fsXWUGIXygKjHd9zOT1lFkb49oe_-kIEoNrDh4rv1pu3R5eSUwuih1ppRNstS3ufwtQJ6ZvA4uXNPuj6TvQyNgJXeA3HzaLetIArULHQQqns0UP8UApFYZoxZq0SqsgYcSndvSkmo5V_qxE7w"
}]
}
}],
claims: {
family_name: null,
given_name: null
},
scopes: ['scope1', 'scope2'],
jwks,
features: {
pushedAuthorizationRequests: {
enabled: true
},
claimsParameter: {
enabled: true
}
}
}
const app = require('./app')(configuration)
const jwtSign = (function () {
let jwtCounter = 0
const privateKey = fs.readFileSync('./resources/privateKey.pem')
return function (payload, expires) {
return jwt.sign(payload, privateKey, {
algorithm: 'RS256',
keyid: '7Mr9wAwdM3cisMqeWZBDvgzPjopnFYnnhJs7M3kbHHE',
expiresIn: expires,
notBefore: 0,
jwtid: `jwt-${jwtCounter++}`
})
}
}())
describe('Testing Issues', function () {
const CLIENT_ID = 'myClient'
const AUD = 'https://op.example.com'
const REDIRECT_URI = 'http://127.0.0.1:8080/cb'
before('Start server', function (cb) {
this.server = app.listen(5000, cb)
})
after('Stop server', function (cb) {
this.server.close(cb)
})
it('should ask for a consent if same End-User make two different request to and RP', async function () {
const jwtSec = jwtSign({
aud: 'https://op.example.com',
iss: CLIENT_ID,
sub: CLIENT_ID
}, 30)
// We use an agent to simulate the browser (cookies are kept)
const agent = request.agent(this.server)
const { body: { request_uri: requestURI } } = await agent.post('/request')
.send(`client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer`)
.send(`client_assertion=${jwtSec}`)
.send(`client_id=${CLIENT_ID}`)
.send('response_type=code')
.send('redirect_uri=http://127.0.0.1:8080/cb')
.send('scope=openid')
.send('claims={"id_token":{"family_name": {"essential": true}}}')
.expect(201)
console.log("HOLA")
const { header: { location: interactionURI } } = await agent.get('/auth')
.query({ request_uri: requestURI, client_id: CLIENT_ID })
.expect(302)
const interactionId = interactionURI.split('/').pop()
const response = await agent.get(interactionURI)
.expect(200)
await agent.post(interactionURI)
.send('prompt=login')
.send('login=test')
.send('password=any')
.expect(302)
const { header: { location: secondIntURI } } = await agent.get('/auth/' + interactionId)
.expect(302)
const responseInt = await agent.get(secondIntURI)
const otherResp = await agent.post(interactionURI)
.send('prompt=consent')
.expect(302)
const { header: { location: codeUri } } = await agent.get('/auth/' + interactionId)
.expect(302)
const code = new URL(codeUri).searchParams.get('code')
console.log(code)
// Second request same end-User
const jwtSec2 = jwtSign({
aud: 'https://op.example.com',
iss: CLIENT_ID,
sub: CLIENT_ID
}, 30)
const { body: { request_uri: requestURI2 } } = await agent.post('/request')
.send(`client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer`)
.send(`client_assertion=${jwtSec2}`)
.send(`client_id=${CLIENT_ID}`)
.send('response_type=code')
.send('redirect_uri=http://127.0.0.1:8080/cb')
.send('scope=openid')
.send('claims={"id_token":{"given_name": {"essential": true}}}')
.expect(201)
const { header: { location: interactionURI2 } } = await agent.get('/auth')
.query({ request_uri: requestURI2, client_id: CLIENT_ID })
.expect(302)
const response2 = await agent.get(interactionURI2)
.expect(200)
assert(response2.text.includes('<input type="hidden" name="prompt" value="consent"/>'))
// console.log(response2)
})
it('should ask for a consent if same End-User make two different request to and RP (JWT)', async function () {
const REQUEST_OBJECT = {
iss: CLIENT_ID,
nonce: 'JustANonce',
aud: AUD,
response_type: 'code',
client_id: CLIENT_ID,
redirect_uri: 'http://127.0.0.1:8080/cb',
scope: 'openid'
}
const jwtSec = jwtSign({
aud: 'https://op.example.com',
iss: CLIENT_ID,
sub: CLIENT_ID
}, 30)
const claims = { 'id_token': { 'family_name': { 'essential': true}} }
const requestObj = jwtSign({ ...REQUEST_OBJECT, claims} , 30)
// We use an agent to simulate the browser (cookies are kept)
const agent = request.agent(this.server)
const { body: { request_uri: requestURI } } = await agent.post('/request')
.send(`client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer`)
.send(`client_assertion=${jwtSec}`)
.send(`request=${requestObj}`)
.expect(201)
const { header: { location: interactionURI } } = await agent.get('/auth')
.query({ request_uri: requestURI, client_id: CLIENT_ID })
.expect(302)
const interactionId = interactionURI.split('/').pop()
const response = await agent.get(interactionURI)
.expect(200)
await agent.post(interactionURI)
.send('prompt=login')
.send('login=test')
.send('password=any')
.expect(302)
const { header: { location: secondIntURI } } = await agent.get('/auth/' + interactionId)
.expect(302)
const responseInt = await agent.get(secondIntURI)
const otherResp = await agent.post(interactionURI)
.send('prompt=consent')
.expect(302)
const { header: { location: codeUri } } = await agent.get('/auth/' + interactionId)
.expect(302)
const code = new URL(codeUri).searchParams.get('code')
console.log(code)
// Second request same end-User
const jwtSec2 = jwtSign({
aud: 'https://op.example.com',
iss: CLIENT_ID,
sub: CLIENT_ID
}, 30)
const claims2 = { 'id_token': { 'given_name': { 'essential': true}} }
const requestObj2 = jwtSign({ ...REQUEST_OBJECT, claims: claims2}, 30)
const { body: { request_uri: requestURI2 } } = await agent.post('/request')
.send(`client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer`)
.send(`client_assertion=${jwtSec2}`)
.send(`request=${requestObj2}`)
.expect(201)
const { header: { location: interactionURI2 } } = await agent.get('/auth')
.query({ request_uri: requestURI2, client_id: CLIENT_ID })
.expect(302)
const response2 = await agent.get(interactionURI2)
.expect(200)
assert(response2.text.includes('<input type="hidden" name="prompt" value="consent"/>'))
console.log(response2)
})
})