diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-06-14 16:17:16 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-06-20 15:36:17 +0200 |
| commit | 7e7bcabb699f60ea93bc391dbea313511dc864d8 (patch) | |
| tree | 2bb2d30d026e716b9051340d19003c4a93008cb5 /test | |
| parent | 01d23b0d5f1140e70c7b20247dff0e842e6555cf (diff) | |
| download | mullvadvpn-7e7bcabb699f60ea93bc391dbea313511dc864d8.tar.xz mullvadvpn-7e7bcabb699f60ea93bc391dbea313511dc864d8.zip | |
Refactor auth tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/auth.spec.js | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/test/auth.spec.js b/test/auth.spec.js index bdb890a59b..c4330b4559 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -1,53 +1,38 @@ // @flow -import { expect } from 'chai'; -import { - setupIpcAndStore, - setupBackendAndStore, - failFast, - checkNextTick, -} from './helpers/ipc-helpers'; +import { expect, spy } from 'chai'; +import { setupIpcAndStore, setupBackendAndStore } from './helpers/ipc-helpers'; import { IpcChain } from './helpers/IpcChain'; import { Backend } from '../app/lib/backend'; describe('authentication', () => { it('authenticates before ipc call if unauthenticated', (done) => { const { store, mockIpc } = setupIpcAndStore(); - const credentials = { - sharedSecret: 'foo', - connectionString: '', - }; const chain = new IpcChain(mockIpc); + chain.onSuccessOrFailure(done); chain.expect('authenticate').withInputValidation((secret) => { expect(secret).to.equal(credentials.sharedSecret); }); - chain.expect('connect'); - chain.onSuccessOrFailure(done); - + const credentials = { + sharedSecret: '', + connectionString: '', + }; const backend = new Backend(store, credentials, mockIpc); backend.connect(); }); - it('reauthenticates on reconnect', (done) => { + it('reauthenticates on reconnect', async () => { const { mockIpc, backend } = setupBackendAndStore(); - let authCount = 0; - mockIpc.authenticate = () => { - authCount++; - return Promise.resolve(); - }; - + mockIpc.authenticate = spy(mockIpc.authenticate); mockIpc.killWebSocket(); - failFast(() => { - expect(authCount).to.equal(0); - }, done); - backend.connect(); - checkNextTick(() => { - expect(authCount).to.equal(1); - }, done); + expect(mockIpc.authenticate).to.not.have.been.called(); + + await backend.connect(); + expect(mockIpc.authenticate).to.have.been.called.once; }); }); |
