-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include additional data in token payloads of verification and proof JWTs
- Loading branch information
Showing
4 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { expect } from 'chai' | ||
import * as cheerio from 'cheerio' | ||
import fetch from 'cross-fetch' | ||
import * as jsonwebtoken from 'jsonwebtoken' | ||
import { describe } from 'mocha' | ||
import Mail from 'nodemailer/lib/mailer' | ||
import { SinonSandbox, SinonSpy, createSandbox } from 'sinon' | ||
import { baseUrl } from '../config' | ||
import * as config from '../config' | ||
import * as mailerService from '../services/mailerService' | ||
import { authenticatedFetch } from './testSetup.spec' | ||
import { authenticatedFetch, person } from './testSetup.spec' | ||
|
||
describe('email verification via /verify-email?token=jwt', () => { | ||
let sendMailSpy: SinonSpy<[options: Mail.Options], Promise<void>> | ||
|
@@ -25,7 +26,7 @@ describe('email verification via /verify-email?token=jwt', () => { | |
|
||
beforeEach(async () => { | ||
// initialize the integration | ||
const initResponse = await authenticatedFetch(`${baseUrl}/init`, { | ||
const initResponse = await authenticatedFetch(`${config.baseUrl}/init`, { | ||
method: 'post', | ||
headers: { 'content-type': 'application/json' }, | ||
body: JSON.stringify({ email: '[email protected]' }), | ||
|
@@ -44,10 +45,22 @@ describe('email verification via /verify-email?token=jwt', () => { | |
expect(response.status).to.equal(200) | ||
}) | ||
|
||
it( | ||
'[correct token] should return proof of verification for the user to save on their pod, or edit the pod directly', | ||
) | ||
// this is a JWT token, it keeps email and webId of the person as payload | ||
it('[correct token] should return proof of verification for the user to save on their pod', async () => { | ||
// the proof is a JWT token, it keeps email and webId of the person as payload | ||
const response = await fetch(verificationLink) | ||
expect(response.ok).to.be.true | ||
const jwt = await response.text() | ||
const payload = jsonwebtoken.decode(jwt) as jsonwebtoken.JwtPayload | ||
|
||
expect(payload).to.include({ | ||
iss: config.mailerCredentials.webId, | ||
webId: person.webId, | ||
email: '[email protected]', | ||
emailVerified: true, | ||
}) | ||
}) | ||
|
||
it("[correct token] (maybe) should save the verification proof to user's pod") | ||
|
||
it('[incorrect token] should respond with 400', async () => { | ||
const response = await fetch( | ||
|
@@ -58,7 +71,7 @@ describe('email verification via /verify-email?token=jwt', () => { | |
}) | ||
|
||
it('[missing token] should respond with 400', async () => { | ||
const response = await fetch(`${baseUrl}/verify-email`) | ||
const response = await fetch(`${config.baseUrl}/verify-email`) | ||
expect(response.status).to.equal(400) | ||
expect(await response.text()).to.equal( | ||
'This is not a valid verification link. Have you received the link in your email?', | ||
|