@ossy/users 3.11.0 → 3.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/users.integration.spec.js +131 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/users",
|
|
3
3
|
"description": "User domain - aggregate, events, and validators for the Ossy user model",
|
|
4
|
-
"version": "3.11.
|
|
4
|
+
"version": "3.11.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.js",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"/src",
|
|
50
50
|
"README.md"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "f279de3535b6bc76631cbc6b943dae8f92a1565f"
|
|
53
53
|
}
|
|
@@ -221,6 +221,130 @@ describe('[authentication/actions/request-sign-in]', () => {
|
|
|
221
221
|
|
|
222
222
|
})
|
|
223
223
|
|
|
224
|
+
describe('[authentication/actions/verify-sign-in]', () => {
|
|
225
|
+
|
|
226
|
+
describe('given email + code from request-sign-in', () => {
|
|
227
|
+
it('must return a WebAuth session and set an auth cookie via POST /actions', async () => {
|
|
228
|
+
const email = casual.email
|
|
229
|
+
|
|
230
|
+
await TestUtil.AssertActionResponse({
|
|
231
|
+
actionId: '@ossy/authentication/actions/sign-up',
|
|
232
|
+
body: TestUtil.signUpBody({ email }),
|
|
233
|
+
expectedResponseStatus: 200,
|
|
234
|
+
expectedResponseBody: { ok: true },
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
await TestUtil.AssertActionResponse({
|
|
238
|
+
actionId: '@ossy/authentication/actions/request-sign-in',
|
|
239
|
+
payload: { email },
|
|
240
|
+
expectedResponseStatus: 200,
|
|
241
|
+
expectedResponseBody: { ok: true },
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
const createdEvent = await TestUtil.GetEvent({
|
|
245
|
+
type: USER_SCHEMA,
|
|
246
|
+
event: 'Created',
|
|
247
|
+
'payload.email': email,
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
const code = await TestUtil.getLatestVerificationCodeForSubject(createdEvent.resourceId)
|
|
251
|
+
|
|
252
|
+
const response = await TestUtil.InvokeAction({
|
|
253
|
+
actionId: '@ossy/authentication/actions/verify-sign-in',
|
|
254
|
+
payload: { email, code },
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
const body = await response.json()
|
|
258
|
+
const signInVerifiedEvent = await TestUtil.GetEvent({
|
|
259
|
+
type: USER_SCHEMA,
|
|
260
|
+
resourceId: createdEvent.resourceId,
|
|
261
|
+
event: 'SignInVerified',
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
expect(response.status).toBe(200)
|
|
265
|
+
expect(body).toMatchObject({ sub: createdEvent.resourceId, token: expect.any(String) })
|
|
266
|
+
expect(!!signInVerifiedEvent).toBe(true)
|
|
267
|
+
expect(getSetCookieHeader(response).includes(signInVerifiedEvent.payload.token)).toEqual(true)
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('must reject reuse of the same code with 401', async () => {
|
|
271
|
+
const email = casual.email
|
|
272
|
+
|
|
273
|
+
await TestUtil.AssertActionResponse({
|
|
274
|
+
actionId: '@ossy/authentication/actions/sign-up',
|
|
275
|
+
body: TestUtil.signUpBody({ email }),
|
|
276
|
+
expectedResponseStatus: 200,
|
|
277
|
+
expectedResponseBody: { ok: true },
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
await TestUtil.AssertActionResponse({
|
|
281
|
+
actionId: '@ossy/authentication/actions/request-sign-in',
|
|
282
|
+
payload: { email },
|
|
283
|
+
expectedResponseStatus: 200,
|
|
284
|
+
expectedResponseBody: { ok: true },
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
const createdEvent = await TestUtil.GetEvent({
|
|
288
|
+
type: USER_SCHEMA,
|
|
289
|
+
event: 'Created',
|
|
290
|
+
'payload.email': email,
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const code = await TestUtil.getLatestVerificationCodeForSubject(createdEvent.resourceId)
|
|
294
|
+
|
|
295
|
+
const first = await TestUtil.InvokeAction({
|
|
296
|
+
actionId: '@ossy/authentication/actions/verify-sign-in',
|
|
297
|
+
payload: { email, code },
|
|
298
|
+
})
|
|
299
|
+
expect(first.status).toBe(200)
|
|
300
|
+
|
|
301
|
+
const second = await TestUtil.InvokeAction({
|
|
302
|
+
actionId: '@ossy/authentication/actions/verify-sign-in',
|
|
303
|
+
payload: { email, code },
|
|
304
|
+
})
|
|
305
|
+
expect(second.status).toBe(401)
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it('must reject the magic link JWT after sign-in via code with 401', async () => {
|
|
309
|
+
const email = casual.email
|
|
310
|
+
|
|
311
|
+
await TestUtil.AssertActionResponse({
|
|
312
|
+
actionId: '@ossy/authentication/actions/sign-up',
|
|
313
|
+
body: TestUtil.signUpBody({ email }),
|
|
314
|
+
expectedResponseStatus: 200,
|
|
315
|
+
expectedResponseBody: { ok: true },
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
await TestUtil.AssertActionResponse({
|
|
319
|
+
actionId: '@ossy/authentication/actions/request-sign-in',
|
|
320
|
+
payload: { email },
|
|
321
|
+
expectedResponseStatus: 200,
|
|
322
|
+
expectedResponseBody: { ok: true },
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
const createdEvent = await TestUtil.GetEvent({
|
|
326
|
+
type: USER_SCHEMA,
|
|
327
|
+
event: 'Created',
|
|
328
|
+
'payload.email': email,
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const code = await TestUtil.getLatestVerificationCodeForSubject(createdEvent.resourceId)
|
|
332
|
+
const verificationJwt = await TestUtil.getLatestVerificationJwtForSubject(createdEvent.resourceId)
|
|
333
|
+
|
|
334
|
+
const codeResponse = await TestUtil.InvokeAction({
|
|
335
|
+
actionId: '@ossy/authentication/actions/verify-sign-in',
|
|
336
|
+
payload: { email, code },
|
|
337
|
+
})
|
|
338
|
+
expect(codeResponse.status).toBe(200)
|
|
339
|
+
|
|
340
|
+
const linkResponse = await fetch(
|
|
341
|
+
`${getApiTestBaseUrl()}/users/verify-sign-in?token=${verificationJwt}`,
|
|
342
|
+
{ method: 'GET' },
|
|
343
|
+
)
|
|
344
|
+
expect(linkResponse.status).toBe(401)
|
|
345
|
+
})
|
|
346
|
+
})
|
|
347
|
+
|
|
224
348
|
describe('[/users/verify-sign-in][GET]', () => {
|
|
225
349
|
|
|
226
350
|
describe('given a valid token created from a Created event', () => {
|
|
@@ -333,6 +457,13 @@ describe('[/users/verify-sign-in][GET]', () => {
|
|
|
333
457
|
}))
|
|
334
458
|
})
|
|
335
459
|
|
|
460
|
+
it('must return 400 when email+code are provided without a token (codes are POST-only)', () => TestUtil.AssertResponse({
|
|
461
|
+
endpoint: '/users/verify-sign-in?email=test@example.com&code=123456',
|
|
462
|
+
method: 'GET',
|
|
463
|
+
expectedResponseStatus: 400,
|
|
464
|
+
expectedResponseBody: '',
|
|
465
|
+
}))
|
|
466
|
+
|
|
336
467
|
})
|
|
337
468
|
|
|
338
469
|
})
|