summaryrefslogtreecommitdiffhomepage
path: root/test/auth.spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/auth.spec.js')
-rw-r--r--test/auth.spec.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/auth.spec.js b/test/auth.spec.js
new file mode 100644
index 0000000000..6bb23a7136
--- /dev/null
+++ b/test/auth.spec.js
@@ -0,0 +1,56 @@
+// @flow
+
+import { expect } from 'chai';
+import { setupIpcAndStore, setupBackendAndStore, failFast, checkNextTick } 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.require('auth')
+ .withInputValidation( secret => {
+ expect(secret).to.equal(credentials.sharedSecret);
+ })
+ .done();
+
+ chain.require('connect')
+ .done();
+
+ chain.onSuccessOrFailure(done);
+
+
+ const backend = new Backend(store, credentials, mockIpc);
+ backend.connect();
+ });
+
+ it('reauthenticates on reconnect', (done) => {
+ const { mockIpc, backend } = setupBackendAndStore();
+
+ let authCount = 0;
+ mockIpc.auth = () => {
+ authCount++;
+ return Promise.resolve();
+ };
+
+
+ mockIpc.killWebSocket();
+ failFast(() => {
+ expect(authCount).to.equal(0);
+ }, done);
+
+
+ backend.connect();
+ checkNextTick(() => {
+ expect(authCount).to.equal(1);
+ }, done);
+ });
+});