-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathoverview-test.js
214 lines (185 loc) · 7.52 KB
/
overview-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import syncScenario from 'vault/mirage/scenarios/sync';
import syncHandlers from 'vault/mirage/handlers/sync';
import authPage from 'vault/tests/pages/auth';
import { click, waitFor, visit, currentURL } from '@ember/test-helpers';
import { PAGE as ts } from 'vault/tests/helpers/sync/sync-selectors';
import { runCmd } from 'vault/tests/helpers/commands';
// sync is an enterprise feature but since mirage is used the enterprise label has been intentionally omitted from the module name
module('Acceptance | sync | overview', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(async function () {
this.version = this.owner.lookup('service:version');
this.version.features = ['Secrets Sync'];
});
module('when feature is activated', function (hooks) {
hooks.beforeEach(async function () {
syncHandlers(this.server);
await authPage.login();
});
test('it fetches destinations and associations', async function (assert) {
assert.expect(2);
this.server.get('/sys/sync/destinations', () => {
assert.true(true, 'destinations is called');
});
this.server.get('/sys/sync/associations', () => {
assert.true(true, 'associations is called');
});
await visit('/vault/sync/secrets/overview');
});
module('when there are pre-existing destinations', function (hooks) {
hooks.beforeEach(async function () {
syncScenario(this.server);
await authPage.login();
});
test('it should transition to correct routes when performing actions', async function (assert) {
await click(ts.navLink('Secrets Sync'));
await click(ts.destinations.list.create);
await click(ts.createCancel);
await click(ts.overviewCard.actionLink('Create new'));
await click(ts.createCancel);
await waitFor(ts.overview.table.actionToggle(0));
await click(ts.overview.table.actionToggle(0));
await click(ts.overview.table.action('sync'));
await click(ts.destinations.sync.cancel);
await click(ts.breadcrumbLink('Secrets Sync'));
await waitFor(ts.overview.table.actionToggle(0));
await click(ts.overview.table.actionToggle(0));
await click(ts.overview.table.action('details'));
assert.dom(ts.tab('Secrets')).hasClass('active', 'Navigates to secrets view for destination');
});
});
});
module('when feature is not activated', function (hooks) {
hooks.beforeEach(async function () {
let wasActivatePOSTCalled = false;
// simulate the feature being activated once /secrets-sync/activate has been called
this.server.get('/sys/activation-flags', () => {
if (wasActivatePOSTCalled) {
return {
data: {
activated: ['secrets-sync'],
unactivated: [''],
},
};
} else {
return {
data: {
activated: [''],
unactivated: ['secrets-sync'],
},
};
}
});
this.server.post('/sys/activation-flags/secrets-sync/activate', () => {
wasActivatePOSTCalled = true;
return {};
});
await authPage.login();
});
test('it does not fetch destinations and associations', async function (assert) {
assert.expect(0);
this.server.get('/sys/sync/destinations', () => {
assert.true(false, 'destinations is not called');
});
this.server.get('/sys/sync/associations', () => {
assert.true(false, 'associations is not called');
});
await visit('/vault/sync/secrets/overview');
});
test('the activation workflow works', async function (assert) {
await visit('/vault/sync/secrets/overview');
assert
.dom(ts.cta.button)
.doesNotExist('create first destination is not available until feature has been activated');
assert.dom(ts.overview.optInBanner.container).exists();
await click(ts.overview.optInBanner.enable);
assert
.dom(ts.overview.activationModal.container)
.exists('modal to opt-in and activate feature is shown');
await click(ts.overview.activationModal.checkbox);
await click(ts.overview.activationModal.confirm);
assert
.dom(ts.overview.activationModal.container)
.doesNotExist('modal is gone once activation has been submitted');
assert
.dom(ts.overview.optInBanner.container)
.doesNotExist('opt-in banner is gone once activation has been submitted');
await click(ts.cta.button);
assert.strictEqual(
currentURL(),
'/vault/sync/secrets/destinations/create',
'create new destination is available once feature is activated'
);
});
module('enterprise with namespaces', function (hooks) {
hooks.beforeEach(async function () {
this.version.features = ['Secrets Sync', 'Namespaces'];
await runCmd(`write sys/namespaces/admin -f`, false);
await authPage.loginNs('admin');
await runCmd(`write sys/namespaces/foo -f`, false);
await authPage.loginNs('admin/foo');
});
test('it should make activation-flag requests to correct namespace', async function (assert) {
assert.expect(3);
this.server.get('/sys/activation-flags', (_, req) => {
assert.deepEqual(req.requestHeaders, {}, 'Request is unauthenticated and in root namespace');
return {
data: {
activated: [''],
unactivated: ['secrets-sync'],
},
};
});
this.server.post('/sys/activation-flags/secrets-sync/activate', (_, req) => {
assert.strictEqual(
req.requestHeaders['X-Vault-Namespace'],
undefined,
'Request is made to undefined namespace'
);
return {};
});
// confirm we're in admin/foo
assert.dom('[data-test-badge-namespace]').hasText('foo');
await click(ts.navLink('Secrets Sync'));
await click(ts.overview.optInBanner.enable);
await click(ts.overview.activationModal.checkbox);
await click(ts.overview.activationModal.confirm);
});
test('it should make activation-flag requests to correct namespace when managed', async function (assert) {
assert.expect(3);
this.owner.lookup('service:flags').featureFlags = ['VAULT_CLOUD_ADMIN_NAMESPACE'];
this.server.get('/sys/activation-flags', (_, req) => {
assert.deepEqual(req.requestHeaders, {}, 'Request is unauthenticated and in root namespace');
return {
data: {
activated: [''],
unactivated: ['secrets-sync'],
},
};
});
this.server.post('/sys/activation-flags/secrets-sync/activate', (_, req) => {
assert.strictEqual(
req.requestHeaders['X-Vault-Namespace'],
'admin',
'Request is made to the admin namespace'
);
return {};
});
// confirm we're in admin/foo
assert.dom('[data-test-badge-namespace]').hasText('foo');
await click(ts.navLink('Secrets Sync'));
await click(ts.overview.optInBanner.enable);
await click(ts.overview.activationModal.checkbox);
await click(ts.overview.activationModal.confirm);
});
});
});
});