Skip to content

Commit 4208871

Browse files
committed
More functional tests.
1 parent 0d3b4c6 commit 4208871

File tree

1 file changed

+181
-73
lines changed

1 file changed

+181
-73
lines changed

test/functional/editor.js

Lines changed: 181 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ describe('Editor', function() {
336336

337337
for(const alg of algs) {
338338
it(alg.toUpperCase(), async function() {
339+
this.timeout(20000);
340+
339341
await this.page.click('.js-input');
340342
await this.page.keyboard.down('ControlLeft');
341343
await this.page.keyboard.press('KeyA');
@@ -369,71 +371,86 @@ describe('Editor', function() {
369371
}
370372
});
371373

372-
describe('Encodes RS/ES/PS tokens', function() {
373-
const algs = Object.keys(defaultTokens)
374-
.filter(alg => !alg.includes('hs') && alg !== 'none');
375-
376-
for(const alg of algs) {
377-
it(alg.toUpperCase(), async function() {
374+
describe('Encodes RS/ES/PS tokens', function() {
375+
describe('RS/PS', async function() {
376+
before(async function() {
378377
this.timeout(30000);
379378

380-
await this.page.select('#algorithm-select', alg.toUpperCase());
381-
382-
const oldToken = await this.page.evaluate(() => {
383-
return window.test.tokenEditor.getValue();
384-
});
379+
await this.page.select('#algorithm-select', 'RS256');
385380

386381
await this.page.click('textarea[name="public-key"]');
387382
await this.page.keyboard.down('ControlLeft');
388383
await this.page.keyboard.press('KeyA');
389384
await this.page.keyboard.up('ControlLeft');
390-
await this.page.keyboard.type(defaultTokens[alg].publicKey, {
385+
await this.page.keyboard.type(defaultTokens['rs256'].publicKey, {
391386
delay: 5
392387
});
393388

394389
await this.page.click('textarea[name="private-key"]');
395390
await this.page.keyboard.down('ControlLeft');
396391
await this.page.keyboard.press('KeyA');
397392
await this.page.keyboard.up('ControlLeft');
398-
await this.page.keyboard.type(defaultTokens[alg].privateKey, {
399-
delay: 5
400-
});
401-
402-
await this.page.click('.js-header');
403-
await this.page.keyboard.down('ControlLeft');
404-
await this.page.keyboard.press('KeyA');
405-
await this.page.keyboard.up('ControlLeft');
406-
await this.page.keyboard.type(JSON.stringify({
407-
alg: alg.toUpperCase(),
408-
typ: 'JWT'
409-
}, null, 2), {
410-
delay: 5
411-
});
412-
413-
await this.page.click('.js-payload');
414-
await this.page.keyboard.down('ControlLeft');
415-
await this.page.keyboard.press('KeyA');
416-
await this.page.keyboard.up('ControlLeft');
417-
await this.page.keyboard.type(JSON.stringify({
418-
sub: 'test'
419-
}, null, 2), {
393+
await this.page.keyboard.type(defaultTokens['rs256'].privateKey, {
420394
delay: 5
421395
});
396+
});
422397

423-
const newToken = await this.page.evaluate(() => {
424-
return window.test.tokenEditor.getValue();
425-
});
398+
const algs =
399+
Object.keys(defaultTokens)
400+
.filter(alg => alg.includes('rs') || alg.includes('ps'));
401+
402+
for(const alg of algs) {
403+
it(alg.toUpperCase(), async function() {
404+
this.timeout(30000);
405+
406+
await this.page.evaluate(token => {
407+
window.test.tokenEditor.setValue(token);
408+
}, defaultTokens[alg].token);
409+
410+
await this.page.select('#algorithm-select', alg.toUpperCase());
411+
412+
const oldToken = await this.page.evaluate(() => {
413+
return window.test.tokenEditor.getValue();
414+
});
415+
416+
await this.page.click('.js-header');
417+
await this.page.keyboard.down('ControlLeft');
418+
await this.page.keyboard.press('KeyA');
419+
await this.page.keyboard.up('ControlLeft');
420+
await this.page.keyboard.type(JSON.stringify({
421+
alg: alg.toUpperCase(),
422+
typ: 'JWT'
423+
}, null, 2), {
424+
delay: 5
425+
});
426+
427+
await this.page.click('.js-payload');
428+
await this.page.keyboard.down('ControlLeft');
429+
await this.page.keyboard.press('KeyA');
430+
await this.page.keyboard.up('ControlLeft');
431+
await this.page.keyboard.type(JSON.stringify({
432+
sub: 'test'
433+
}, null, 2), {
434+
delay: 5
435+
});
436+
437+
const newToken = await this.page.evaluate(() => {
438+
return window.test.tokenEditor.getValue();
439+
});
440+
441+
expect(newToken).to.not.be.empty;
442+
expect(newToken).to.not.equal(oldToken);
443+
444+
const valid = await this.page.$eval('.validation-status',
445+
status => {
446+
return status.classList.contains('valid-token') &&
447+
status.textContent.indexOf('verified') !== -1;
448+
});
426449

427-
expect(newToken).to.not.equal(oldToken);
428-
429-
const valid = await this.page.$eval('.validation-status', status => {
430-
return status.classList.contains('valid-token') &&
431-
status.textContent.indexOf('verified') !== -1;
450+
expect(valid).to.be.true;
432451
});
433-
434-
expect(valid).to.be.true;
435-
});
436-
}
452+
}
453+
});
437454
});
438455

439456
describe('Should download public-keys when possible', function() {
@@ -450,7 +467,9 @@ describe('Editor', function() {
450467
});
451468

452469
it('Clears the token when the header is edited and there ' +
453-
'is no private key', async function() {
470+
'is no private key', async function() {
471+
await this.page.select('#algorithm-select', 'RS256');
472+
454473
const secretInput = await this.page.$('textarea[name="private-key"]');
455474
await secretInput.click();
456475
await this.page.keyboard.down('ControlLeft');
@@ -481,33 +500,37 @@ describe('Editor', function() {
481500

482501
it('Clears the token when the payload is edited and there ' +
483502
'is no private key', async function() {
484-
const secretInput = await this.page.$('textarea[name="private-key"]');
485-
await secretInput.click();
486-
await this.page.keyboard.down('ControlLeft');
487-
await this.page.keyboard.press('KeyA');
488-
await this.page.keyboard.up('ControlLeft');
489-
await this.page.keyboard.press('Delete');
490-
491-
await this.page.click('.js-payload');
492-
await this.page.keyboard.down('ControlLeft');
493-
await this.page.keyboard.press('KeyA');
494-
await this.page.keyboard.up('ControlLeft');
495-
496-
const payload = {
497-
sub: 'test'
498-
};
499-
await this.page.keyboard.type(JSON.stringify(payload, null, 2), {
500-
delay: 5
501-
});
502-
503-
const token = await this.page.evaluate(() => {
504-
return window.test.tokenEditor.getValue();
505-
});
506-
507-
expect(token).to.be.empty;
503+
await this.page.select('#algorithm-select', 'RS256');
504+
505+
const secretInput = await this.page.$('textarea[name="private-key"]');
506+
await secretInput.click();
507+
await this.page.keyboard.down('ControlLeft');
508+
await this.page.keyboard.press('KeyA');
509+
await this.page.keyboard.up('ControlLeft');
510+
await this.page.keyboard.press('Delete');
511+
512+
await this.page.click('.js-payload');
513+
await this.page.keyboard.down('ControlLeft');
514+
await this.page.keyboard.press('KeyA');
515+
await this.page.keyboard.up('ControlLeft');
516+
517+
const payload = {
518+
sub: 'test'
519+
};
520+
await this.page.keyboard.type(JSON.stringify(payload, null, 2), {
521+
delay: 5
522+
});
523+
524+
const token = await this.page.evaluate(() => {
525+
return window.test.tokenEditor.getValue();
526+
});
527+
528+
expect(token).to.be.empty;
508529
});
509530

510531
it('Marks token as invalid when there is no public key', async function() {
532+
this.timeout(20000);
533+
511534
await this.page.select('#algorithm-select', 'RS256');
512535

513536
await this.page.click('.js-input');
@@ -588,8 +611,91 @@ describe('Editor', function() {
588611
expect(invalid).to.be.true;
589612
});
590613

591-
it('Marks token as valid when the public key is OK and private key is wrong');
592-
it('Marks token as valid when the public key is OK and private key is missing');
614+
it('Marks token as valid when the public key is OK and private ' +
615+
'key is wrong', async function() {
616+
this.timeout(30000);
617+
618+
await this.page.select('#algorithm-select', 'RS256');
619+
620+
const secretInput = await this.page.$('textarea[name="public-key"]');
621+
await secretInput.click();
622+
await this.page.keyboard.down('ControlLeft');
623+
await this.page.keyboard.press('KeyA');
624+
await this.page.keyboard.up('ControlLeft');
625+
await secretInput.type(defaultTokens['rs256'].publicKey, {
626+
delay: 5
627+
});
628+
629+
const privateKeyInput = await this.page.$('textarea[name="private-key"]');
630+
await privateKeyInput.click();
631+
await this.page.keyboard.down('ControlLeft');
632+
await this.page.keyboard.press('KeyA');
633+
await this.page.keyboard.up('ControlLeft');
634+
635+
const head = defaultTokens['rs256'].privateKey.slice(0, 20);
636+
const tail = defaultTokens['rs256'].privateKey.slice(20);
637+
638+
await privateKeyInput.type(`${head}sadfasdf${tail}`, {
639+
delay: 5
640+
});
641+
642+
await this.page.click('.js-input');
643+
await this.page.keyboard.down('ControlLeft');
644+
await this.page.keyboard.press('KeyA');
645+
await this.page.keyboard.up('ControlLeft');
646+
await this.page.keyboard.type(defaultTokens['rs256'].token, {
647+
delay: 5
648+
});
649+
650+
await this.page.waitFor(1000);
651+
652+
const valid = await this.page.$eval('.validation-status', status => {
653+
return status.classList.contains('valid-token') &&
654+
status.textContent.indexOf('verified') !== -1;
655+
});
656+
657+
expect(valid).to.be.true;
658+
});
659+
660+
it('Marks token as valid when the public key is OK and private ' +
661+
'key is missing', async function() {
662+
this.timeout(30000);
663+
664+
await this.page.select('#algorithm-select', 'RS256');
665+
666+
const secretInput = await this.page.$('textarea[name="public-key"]');
667+
await secretInput.click();
668+
await this.page.keyboard.down('ControlLeft');
669+
await this.page.keyboard.press('KeyA');
670+
await this.page.keyboard.up('ControlLeft');
671+
await secretInput.type(tokens['rs256'].publicKey, {
672+
delay: 5
673+
});
674+
675+
const privateKeyInput = await this.page.$('textarea[name="private-key"]');
676+
await privateKeyInput.click();
677+
await this.page.keyboard.down('ControlLeft');
678+
await this.page.keyboard.press('KeyA');
679+
await this.page.keyboard.up('ControlLeft');
680+
await this.page.keyboard.press('Delete');
681+
682+
await this.page.click('.js-input');
683+
await this.page.keyboard.down('ControlLeft');
684+
await this.page.keyboard.press('KeyA');
685+
await this.page.keyboard.up('ControlLeft');
686+
await this.page.keyboard.type(tokens['rs256'].token, {
687+
delay: 5
688+
});
689+
690+
await this.page.waitFor(1000);
691+
692+
const valid = await this.page.$eval('.validation-status', status => {
693+
return status.classList.contains('valid-token') &&
694+
status.textContent.indexOf('verified') !== -1;
695+
});
696+
697+
expect(valid).to.be.true;
698+
});
593699
});
594700

595701
it('Updates the header when the token algorithm ' +
@@ -614,6 +720,8 @@ describe('Editor', function() {
614720
});
615721

616722
it('Marks token as invalid when "alg" is "none"', async function() {
723+
this.timeout(20000);
724+
617725
await this.page.click('.js-input');
618726
await this.page.keyboard.down('ControlLeft');
619727
await this.page.keyboard.press('KeyA');

0 commit comments

Comments
 (0)