|
| 1 | +const { assert } = require('chai'); |
| 2 | +const fs = require('fs-extra'); |
| 3 | +const path = require('path'); |
| 4 | +const bootstrap = require('../test-bootstrap.js'); |
| 5 | + |
| 6 | +describe('Client certificates', function() { |
| 7 | + let app; |
| 8 | + before(async () => { |
| 9 | + app = await bootstrap.runAppDeffered(2000); |
| 10 | + }); |
| 11 | + |
| 12 | + after(async () => { |
| 13 | + if (app && app.isRunning()) { |
| 14 | + await app.stop(); |
| 15 | + } |
| 16 | + const basePath = path.join('test', 'playground'); |
| 17 | + await fs.remove(basePath); |
| 18 | + }); |
| 19 | + |
| 20 | + it('has clientCertificateImport set', async () => { |
| 21 | + const result = await app.client.execute(async () => { |
| 22 | + const arc = document.querySelector('arc-electron'); |
| 23 | + return arc.clientCertificateImport; |
| 24 | + }); |
| 25 | + assert.isTrue(result.value); |
| 26 | + }); |
| 27 | + |
| 28 | + it('opens certificates panel', async () => { |
| 29 | + const result = await app.client.execute(async () => { |
| 30 | + const arc = document.querySelector('arc-electron'); |
| 31 | + arc.openClientCertificates(); |
| 32 | + await arc.updateComplete; |
| 33 | + const panel = arc.shadowRoot.querySelector('client-certificates-panel'); |
| 34 | + return { |
| 35 | + panel: panel.localName, |
| 36 | + page: arc.page, |
| 37 | + }; |
| 38 | + }); |
| 39 | + const { value } = result; |
| 40 | + assert.equal(value.panel, 'client-certificates-panel', 'panel is inserted into the DOM'); |
| 41 | + assert.equal(value.page, 'client-certificates', 'page is set'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('inserts <client-certificates-panel> into the DOM', async () => { |
| 45 | + const result = await app.client.execute(async () => { |
| 46 | + const arc = document.querySelector('arc-electron'); |
| 47 | + arc.page = 'client-certificates'; |
| 48 | + await arc.updateComplete; |
| 49 | + const panel = arc.shadowRoot.querySelector('client-certificates-panel'); |
| 50 | + return panel.localName; |
| 51 | + }); |
| 52 | + assert.equal(result.value, 'client-certificates-panel'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('has CC import dialog by default', async () => { |
| 56 | + const result = await app.client.execute(async () => { |
| 57 | + const arc = document.querySelector('arc-electron'); |
| 58 | + const dialog = arc.shadowRoot.querySelector('#ccImportDialog'); |
| 59 | + return dialog.localName; |
| 60 | + }); |
| 61 | + assert.equal(result.value, 'anypoint-dialog'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('opend CC dialog on client-certificate-import event', async () => { |
| 65 | + const result = await app.client.execute(async () => { |
| 66 | + window.dispatchEvent(new CustomEvent('client-certificate-import')); |
| 67 | + const arc = document.querySelector('arc-electron'); |
| 68 | + await arc.updateComplete; |
| 69 | + const dialog = arc.shadowRoot.querySelector('#ccImportDialog'); |
| 70 | + return { |
| 71 | + opened: dialog.opened, |
| 72 | + ccImportOpened: arc.ccImportOpened, |
| 73 | + }; |
| 74 | + }); |
| 75 | + const { value } = result; |
| 76 | + assert.isTrue(value.opened, 'dialog is opened'); |
| 77 | + assert.isTrue(value.ccImportOpened, 'ccImportOpened is set'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('re-sets ccImportOpened when import dialog is closed', async () => { |
| 81 | + const result = await app.client.execute(async () => { |
| 82 | + window.dispatchEvent(new CustomEvent('client-certificate-import')); |
| 83 | + const arc = document.querySelector('arc-electron'); |
| 84 | + await arc.updateComplete; |
| 85 | + const panel = arc.shadowRoot.querySelector('#ccImportDialog certificate-import'); |
| 86 | + panel.cancel(); |
| 87 | + await arc.updateComplete; |
| 88 | + const dialog = arc.shadowRoot.querySelector('#ccImportDialog'); |
| 89 | + return { |
| 90 | + opened: dialog.opened, |
| 91 | + ccImportOpened: arc.ccImportOpened, |
| 92 | + }; |
| 93 | + }); |
| 94 | + const { value } = result; |
| 95 | + assert.isFalse(value.opened, 'dialog is not opened'); |
| 96 | + assert.isFalse(value.ccImportOpened, 'ccImportOpened is re-set'); |
| 97 | + }); |
| 98 | +}); |
0 commit comments