Skip to content

Commit c554176

Browse files
committed
More functional tests. All passing.
1 parent 4208871 commit c554176

File tree

3 files changed

+142
-4
lines changed

3 files changed

+142
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"chai-arrays": "^2.0.0",
1717
"chai-as-promised": "^7.1.1",
1818
"codemirror": "^5.33.0",
19+
"express": "^4.16.2",
1920
"flipclock": "^0.7.8",
2021
"grunt": "^1.0.1",
2122
"grunt-cli": "^1.2.0",

test/functional/editor.js

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ const chai = require('chai');
22
const chaiAsPromised = require('chai-as-promised');
33
const chaiArrays = require('chai-arrays');
44

5+
const express = require('express');
6+
const jsrsasign = require('jsrsasign');
7+
58
const utils = require('./utils.js');
69
const tokens = require('./tokens.js');
710
const defaultTokens = require('./default-tokens.js');
11+
const jwks = require('./jwks.json');
812

913
const isVisible = utils.isVisible;
1014

@@ -454,16 +458,135 @@ describe('Editor', function() {
454458
});
455459

456460
describe('Should download public-keys when possible', function() {
457-
before(function() {
461+
before(async function() {
462+
this.app = express();
463+
464+
this.app.get('/.well-known/jwks.json', (req, res) => {
465+
res.set('Access-Control-Allow-Origin', '*');
466+
res.json(jwks);
467+
});
468+
469+
this.server = this.app.listen(3000);
458470

471+
await this.page.select('#algorithm-select', 'RS256');
472+
});
473+
474+
beforeEach(async function() {
475+
const publicKeyInput = await this.page.$('textarea[name="public-key"]');
476+
await publicKeyInput.click();
477+
await this.page.keyboard.down('ControlLeft');
478+
await this.page.keyboard.press('KeyA');
479+
await this.page.keyboard.up('ControlLeft');
480+
await this.page.keyboard.press('Delete');
459481
});
460482

461483
after(function() {
484+
this.server.close();
485+
});
486+
487+
it('iss URL + .well-known', async function() {
488+
this.timeout(20000);
489+
490+
const token = jsrsasign.jws.JWS.sign(null, JSON.stringify({
491+
alg: 'RS256',
492+
typ: 'JWT',
493+
kid: '1'
494+
}), JSON.stringify({
495+
sub: 'test',
496+
iss: 'http://localhost:3000/'
497+
}), defaultTokens.rs256.privateKey);
498+
499+
await this.page.click('.js-input');
500+
await this.page.keyboard.down('ControlLeft');
501+
await this.page.keyboard.press('KeyA');
502+
await this.page.keyboard.up('ControlLeft');
503+
await this.page.keyboard.type(token, {
504+
delay: 5
505+
});
462506

463-
});
507+
await this.page.waitFor(2000);
508+
509+
const publicKey = await this.page.$eval('textarea[name="public-key"]',
510+
publicKeyElement => publicKeyElement.value);
511+
512+
expect(publicKey).to.include(jwks.keys[0].x5c[0]);
513+
514+
const valid = await this.page.$eval('.validation-status', status => {
515+
return status.classList.contains('valid-token') &&
516+
status.textContent.indexOf('verified') !== -1;
517+
});
518+
519+
expect(valid).to.be.true;
520+
});
521+
522+
it('jku', async function() {
523+
this.timeout(20000);
524+
525+
const token = jsrsasign.jws.JWS.sign(null, JSON.stringify({
526+
alg: 'RS256',
527+
typ: 'JWT',
528+
kid: '1',
529+
jku: 'http://localhost:3000/.well-known/jwks.json'
530+
}), JSON.stringify({
531+
sub: 'test'
532+
}), defaultTokens.rs256.privateKey);
533+
534+
await this.page.click('.js-input');
535+
await this.page.keyboard.down('ControlLeft');
536+
await this.page.keyboard.press('KeyA');
537+
await this.page.keyboard.up('ControlLeft');
538+
await this.page.keyboard.type(token, {
539+
delay: 5
540+
});
464541

465-
it('iss URL + .well-known');
466-
it('jku');
542+
await this.page.waitFor(2000);
543+
544+
const publicKey = await this.page.$eval('textarea[name="public-key"]',
545+
publicKeyElement => publicKeyElement.value);
546+
547+
expect(publicKey).to.include(jwks.keys[0].x5c[0]);
548+
549+
const valid = await this.page.$eval('.validation-status', status => {
550+
return status.classList.contains('valid-token') &&
551+
status.textContent.indexOf('verified') !== -1;
552+
});
553+
554+
expect(valid).to.be.true;
555+
});
556+
557+
it('x5c', async function() {
558+
this.timeout(35000);
559+
560+
const token = jsrsasign.jws.JWS.sign(null, JSON.stringify({
561+
alg: 'RS256',
562+
typ: 'JWT',
563+
x5c: jwks.keys[0].x5c[0]
564+
}), JSON.stringify({
565+
sub: 'test'
566+
}), defaultTokens.rs256.privateKey);
567+
568+
await this.page.click('.js-input');
569+
await this.page.keyboard.down('ControlLeft');
570+
await this.page.keyboard.press('KeyA');
571+
await this.page.keyboard.up('ControlLeft');
572+
await this.page.keyboard.type(token, {
573+
delay: 5
574+
});
575+
576+
await this.page.waitFor(2000);
577+
578+
const publicKey = await this.page.$eval('textarea[name="public-key"]',
579+
publicKeyElement => publicKeyElement.value);
580+
581+
expect(publicKey).to.include(jwks.keys[0].x5c[0]);
582+
583+
const valid = await this.page.$eval('.validation-status', status => {
584+
return status.classList.contains('valid-token') &&
585+
status.textContent.indexOf('verified') !== -1;
586+
});
587+
588+
expect(valid).to.be.true;
589+
});
467590
});
468591

469592
it('Clears the token when the header is edited and there ' +

test/functional/jwks.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"keys": [
3+
{
4+
"alg": "RS256",
5+
"kty": "RSA",
6+
"use": "sig",
7+
"x5c": [
8+
"MIICWzCCAcSgAwIBAgIJANbzPoQsRLVvMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTgwMjA5MTc1NDExWhcNMTgwMzExMTc1NDExWjBFMQswCQYDVQQGEwJVUzETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQABo1MwUTAdBgNVHQ4EFgQUe2Yz57fovxPFVMuLYp8YtPh+b20wHwYDVR0jBBgwFoAUe2Yz57fovxPFVMuLYp8YtPh+b20wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQBdQJdFYpWe05D6uGq4nHROscqiIgNv07VSkVtSZ6GTvaeAAgQMz9In9fh/LQw37bf2pwsusGAvL6m3EicI/XxrkaxagNRkcqMJeYi0lcx1Kw4tmbu7MGn8Az9K7Czi5SM0N1/3FowuVhVvMIPosfUDuC4CBMJ+tiQYk/NPOF2k+Q=="
9+
],
10+
"kid": "1",
11+
"x5t": "1"
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)