|
4 | 4 | * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
5 | 5 | * @ignore
|
6 | 6 | */
|
7 |
| -"use strict"; |
| 7 | +'use strict'; |
| 8 | + |
8 | 9 | const proxyquire = require('proxyquire');
|
9 | 10 | const { assert, expect } = require('chai');
|
| 11 | +const { before, describe, it } = require('mocha'); |
10 | 12 | const osUtils = require('../js/osUtils');
|
11 | 13 |
|
12 |
| -const wktLoggerMock = { |
13 |
| - getLogger: () => { |
14 |
| - return console; |
15 |
| - } |
16 |
| -} |
| 14 | +/* global process */ |
| 15 | +describe('Credential Store tests', () => { |
| 16 | + const wktLoggerMock = { |
| 17 | + getLogger: () => { |
| 18 | + return console; |
| 19 | + } |
| 20 | + }; |
17 | 21 |
|
18 |
| -const CredentialStore = proxyquire('../js/credentialStore', { './wktLogging': wktLoggerMock }); |
19 |
| -let credStore; |
| 22 | + const CredentialStore = proxyquire('../js/credentialStore', { './wktLogging': wktLoggerMock }); |
| 23 | + let credStore; |
20 | 24 |
|
21 |
| -let skipTestsInJenkins = false; |
22 |
| -if (osUtils.isMac() && 'JENKINS_NODE_COOKIE' in process.env) { |
23 |
| - skipTestsInJenkins = true; |
24 |
| -} |
| 25 | + let skipTestsInJenkins = false; |
| 26 | + if (osUtils.isMac() && 'JENKINS_NODE_COOKIE' in process.env) { |
| 27 | + skipTestsInJenkins = true; |
| 28 | + } |
25 | 29 |
|
26 |
| -before(async () => { |
27 |
| - credStore = new CredentialStore('wktui-test'); |
28 |
| - await cleanStaleCredentials(); |
29 |
| -}); |
| 30 | + before(async () => { |
| 31 | + credStore = new CredentialStore('wktui-test'); |
| 32 | + await cleanStaleCredentials(); |
| 33 | + }); |
30 | 34 |
|
31 |
| -async function cleanStaleCredentials() { |
32 |
| - const staleCreds = credStore.findCredentials(); |
33 |
| - if (staleCreds && Array.isArray(staleCreds)) { |
34 |
| - for (const staleCred of staleCreds) { |
35 |
| - await credStore.deleteCredential(staleCred.account); |
| 35 | + async function cleanStaleCredentials() { |
| 36 | + const staleCreds = credStore.findCredentials(); |
| 37 | + if (staleCreds && Array.isArray(staleCreds)) { |
| 38 | + for (const staleCred of staleCreds) { |
| 39 | + await credStore.deleteCredential(staleCred.account); |
| 40 | + } |
36 | 41 | }
|
37 | 42 | }
|
38 |
| -} |
39 | 43 |
|
40 |
| -if (!skipTestsInJenkins) { |
41 |
| - it('store new credential works', async () => { |
42 |
| - try { |
43 |
| - await credStore.storeCredential('test1', 'f00b@r!'); |
44 |
| - } catch (err) { |
45 |
| - assert.fail(`Failed to store credential test1: ${err}`); |
46 |
| - } |
47 |
| - }); |
| 44 | + if (!skipTestsInJenkins) { |
| 45 | + it('store new credential works', async () => { |
| 46 | + try { |
| 47 | + await credStore.storeCredential('test1', 'f00b@r!'); |
| 48 | + } catch (err) { |
| 49 | + assert.fail(`Failed to store credential test1: ${err}`); |
| 50 | + } |
| 51 | + }); |
48 | 52 |
|
49 |
| - // On the Jenkins MacOS slaves, this test fails at least half the time with the error: |
50 |
| - // The specified item already exists in the keychain. This causes some of the subsequent |
51 |
| - // tests to fail. |
52 |
| - // |
53 |
| - // This has never once reproduced on a developer's MacOS machine so we will just not run |
54 |
| - // the tests in the Jenkins MacOS environment. |
55 |
| - // |
56 |
| - it('replace existing credential works', async () => { |
57 |
| - try { |
58 |
| - await credStore.storeCredential('test1', '8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
59 |
| - const newCredentialValue = await credStore.getCredential('test1'); |
60 |
| - expect(newCredentialValue).to.equal('8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
61 |
| - } catch (err) { |
62 |
| - assert.fail(`Failed to replace existing credential test1: ${err}`); |
63 |
| - } |
64 |
| - }); |
| 53 | + // On the Jenkins MacOS slaves, this test fails at least half the time with the error: |
| 54 | + // The specified item already exists in the keychain. This causes some of the subsequent |
| 55 | + // tests to fail. |
| 56 | + // |
| 57 | + // This has never once reproduced on a developer's MacOS machine so we will just not run |
| 58 | + // the tests in the Jenkins MacOS environment. |
| 59 | + // |
| 60 | + it('replace existing credential works', async () => { |
| 61 | + try { |
| 62 | + await credStore.storeCredential('test1', '8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
| 63 | + const newCredentialValue = await credStore.getCredential('test1'); |
| 64 | + expect(newCredentialValue).to.equal('8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
| 65 | + } catch (err) { |
| 66 | + assert.fail(`Failed to replace existing credential test1: ${err}`); |
| 67 | + } |
| 68 | + }); |
65 | 69 |
|
66 |
| - it('get existing credential works', async () => { |
67 |
| - try { |
68 |
| - const credentialValue = await credStore.getCredential('test1'); |
69 |
| - expect(credentialValue).to.equal('8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
70 |
| - } catch (err) { |
71 |
| - assert.fail(`Failed to get existing credential test1: ${err}`); |
72 |
| - } |
73 |
| - }); |
| 70 | + it('get existing credential works', async () => { |
| 71 | + try { |
| 72 | + const credentialValue = await credStore.getCredential('test1'); |
| 73 | + expect(credentialValue).to.equal('8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
| 74 | + } catch (err) { |
| 75 | + assert.fail(`Failed to get existing credential test1: ${err}`); |
| 76 | + } |
| 77 | + }); |
74 | 78 |
|
75 |
| - it('get non-existent credential works as expected', async () => { |
76 |
| - try { |
77 |
| - const credentialValue = await credStore.getCredential('test2'); |
78 |
| - expect(credentialValue).to.be.null; |
79 |
| - } catch (err) { |
80 |
| - assert.fail(`Failed to get non-existent credential test2: ${err}`); |
81 |
| - } |
82 |
| - }); |
| 79 | + it('get non-existent credential works as expected', async () => { |
| 80 | + try { |
| 81 | + const credentialValue = await credStore.getCredential('test2'); |
| 82 | + expect(credentialValue).to.be.null; |
| 83 | + } catch (err) { |
| 84 | + assert.fail(`Failed to get non-existent credential test2: ${err}`); |
| 85 | + } |
| 86 | + }); |
83 | 87 |
|
84 |
| - it('find credentials to work', async () => { |
85 |
| - try { |
86 |
| - const credentials = await credStore.findCredentials(); |
87 |
| - expect(credentials).to.not.be.null; |
88 |
| - expect(credentials).to.have.length(1); |
89 |
| - expect(credentials[0].name).to.equal('test1'); |
90 |
| - expect(credentials[0].value).to.equal('8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
91 |
| - } catch (err) { |
92 |
| - assert.fail(`Failed to get credentials: ${err}`); |
93 |
| - } |
94 |
| - }); |
| 88 | + it('find credentials to work', async () => { |
| 89 | + try { |
| 90 | + const credentials = await credStore.findCredentials(); |
| 91 | + expect(credentials).to.not.be.null; |
| 92 | + expect(credentials).to.have.length(1); |
| 93 | + expect(credentials[0].name).to.equal('test1'); |
| 94 | + expect(credentials[0].value).to.equal('8e7rty9wrfhofhd98@92382093ue09udjo8dfsyu'); |
| 95 | + } catch (err) { |
| 96 | + assert.fail(`Failed to get credentials: ${err}`); |
| 97 | + } |
| 98 | + }); |
95 | 99 |
|
96 |
| - it('delete non-existent credential works as expected', async () => { |
97 |
| - try { |
98 |
| - const result = await credStore.deleteCredential('test2'); |
99 |
| - expect(result).to.be.false; |
100 |
| - } catch (err) { |
101 |
| - assert.fail(`Failed to handle delete for non-existent credential: ${err}`); |
102 |
| - } |
103 |
| - }); |
| 100 | + it('delete non-existent credential works as expected', async () => { |
| 101 | + try { |
| 102 | + const result = await credStore.deleteCredential('test2'); |
| 103 | + expect(result).to.be.false; |
| 104 | + } catch (err) { |
| 105 | + assert.fail(`Failed to handle delete for non-existent credential: ${err}`); |
| 106 | + } |
| 107 | + }); |
104 | 108 |
|
105 |
| - it('delete existing credential works as expected', async () => { |
106 |
| - try { |
107 |
| - const result = await credStore.deleteCredential('test1'); |
108 |
| - expect(result).to.be.true; |
109 |
| - } catch (err) { |
110 |
| - assert.fail(`Failed to handle delete for existing credential: ${err}`); |
111 |
| - } |
112 |
| - }); |
| 109 | + it('delete existing credential works as expected', async () => { |
| 110 | + try { |
| 111 | + const result = await credStore.deleteCredential('test1'); |
| 112 | + expect(result).to.be.true; |
| 113 | + } catch (err) { |
| 114 | + assert.fail(`Failed to handle delete for existing credential: ${err}`); |
| 115 | + } |
| 116 | + }); |
113 | 117 |
|
114 |
| - it('find credentials when there are none works as expected', async () => { |
115 |
| - try { |
116 |
| - const credentials = await credStore.findCredentials(); |
117 |
| - expect(credentials).to.not.be.null; |
118 |
| - expect(credentials).to.have.length(0); |
119 |
| - } catch (err) { |
120 |
| - assert.fail(`Failed to get credentials when there were none: ${err}`); |
121 |
| - } |
122 |
| - }); |
123 |
| -} |
| 118 | + it('find credentials when there are none works as expected', async () => { |
| 119 | + try { |
| 120 | + const credentials = await credStore.findCredentials(); |
| 121 | + expect(credentials).to.not.be.null; |
| 122 | + expect(credentials).to.have.length(0); |
| 123 | + } catch (err) { |
| 124 | + assert.fail(`Failed to get credentials when there were none: ${err}`); |
| 125 | + } |
| 126 | + }); |
| 127 | + } |
| 128 | +}); |
0 commit comments