|
1 | 1 | import {Organization} from '../../src/types' |
2 | 2 |
|
3 | 3 | describe('Secrets', () => { |
4 | | - beforeEach(() => { |
5 | | - cy.flush() |
6 | | - cy.signin() |
7 | | - cy.get('@org').then(({id}: Organization) => |
8 | | - cy.fixture('routes').then(({orgs}) => { |
9 | | - cy.visit(`${orgs}/${id}/settings/`) |
10 | | - }) |
11 | | - ) |
12 | | - cy.getByTestID('tree-nav') |
13 | | - cy.getByTestID('secrets--tab').click() |
14 | | - }) |
| 4 | + describe('settings page', () => { |
| 5 | + beforeEach(() => { |
| 6 | + cy.flush() |
| 7 | + cy.signin() |
| 8 | + cy.get('@org').then(({id}: Organization) => |
| 9 | + cy.fixture('routes').then(({orgs}) => { |
| 10 | + cy.visit(`${orgs}/${id}/settings/`) |
| 11 | + }) |
| 12 | + ) |
| 13 | + cy.getByTestID('tree-nav') |
| 14 | + cy.getByTestID('secrets--tab').click() |
| 15 | + }) |
| 16 | + |
| 17 | + it('Secrets page base functionality', () => { |
| 18 | + cy.intercept('PATCH', '**/secrets').as('upsertSecret') |
| 19 | + cy.intercept('DELETE', '**/secrets/**').as('deleteSecret') |
| 20 | + |
| 21 | + // Empty state exists and displays context appropriate text |
| 22 | + cy.getByTestID('empty-state').should('be.visible') |
| 23 | + cy.getByTestID('empty-state').contains('Secrets') |
| 24 | + |
| 25 | + // Create secrets via the API, check visibility and sorting |
| 26 | + cy.get('@org').then(({id: orgID}: Organization) => { |
| 27 | + cy.upsertSecret(orgID, {toEverybody: 'rupees baby'}) |
| 28 | + .then((resp: Response) => { |
| 29 | + expect(resp.status).to.eq(204) |
| 30 | + cy.reload() |
| 31 | + cy.getByTestID('secret-card--toEverybody').should('be.visible') |
| 32 | + cy.getByTestID('copy-to-clipboard--toEverybody').should('exist') |
| 33 | + |
| 34 | + // Cannot currently test copy to clipboard functionality as react copy to clipboard has a |
| 35 | + // fallback mechanism that forces Cypress to create a prompt that causes test execution to hang |
| 36 | + // This is being tracked in Cypress with this issue: https://github.com/cypress-io/cypress/issues/2851 |
| 37 | + |
| 38 | + // Once that is resolved and Cypress is upgraded accordingly this should work: |
| 39 | + // Test copy to clipboard via button |
| 40 | + // cy.getByTestID('copy-to-clipboard--toEverybody') |
| 41 | + // .click({force: true}) |
| 42 | + // .then(() => { |
| 43 | + // cy.task('getClipboard').should('eq', 'toEverybody') |
| 44 | + // }) |
| 45 | + }) |
| 46 | + // Create a second secret via the API, make sure it's visible and test sorting |
| 47 | + .upsertSecret(orgID, {CocaColaRecipe: 'lol'}) |
| 48 | + cy.reload() |
| 49 | + cy.getByTestID('secret-card--toEverybody').should('exist') |
| 50 | + cy.getByTestID('secret-card--toEverybody').should('be.visible') |
| 51 | + cy.getByTestID('secret-card--CocaColaRecipe').should('exist') |
| 52 | + cy.getByTestID('secret-card--CocaColaRecipe').should('be.visible') |
15 | 53 |
|
16 | | - it('Secrets page base functionality', () => { |
17 | | - cy.intercept('PATCH', '**/secrets').as('upsertSecret') |
18 | | - cy.intercept('DELETE', '**/secrets/**').as('deleteSecret') |
19 | | - |
20 | | - // Empty state exists and displays context appropriate text |
21 | | - cy.getByTestID('empty-state').should('be.visible') |
22 | | - cy.getByTestID('empty-state').contains('Secrets') |
23 | | - |
24 | | - // Create secrets via the API, check visibility and sorting |
25 | | - cy.get('@org').then(({id: orgID}: Organization) => { |
26 | | - cy.upsertSecret(orgID, {toEverybody: 'rupees baby'}) |
27 | | - .then((resp: Response) => { |
28 | | - expect(resp.status).to.eq(204) |
29 | | - cy.reload() |
30 | | - cy.getByTestID('secret-card--toEverybody').should('be.visible') |
31 | | - cy.getByTestID('copy-to-clipboard--toEverybody').should('exist') |
32 | | - |
33 | | - // Cannot currently test copy to clipboard functionality as react copy to clipboard has a |
34 | | - // fallback mechanism that forces Cypress to create a prompt that causes test execution to hang |
35 | | - // This is being tracked in Cypress with this issue: https://github.com/cypress-io/cypress/issues/2851 |
36 | | - |
37 | | - // Once that is resolved and Cypress is upgraded accordingly this should work: |
38 | | - // Test copy to clipboard via button |
39 | | - // cy.getByTestID('copy-to-clipboard--toEverybody') |
40 | | - // .click({force: true}) |
41 | | - // .then(() => { |
42 | | - // cy.task('getClipboard').should('eq', 'toEverybody') |
43 | | - // }) |
| 54 | + // Leaving commented out copy to clipboard tests per the above comment - JF |
| 55 | + // Test copy to clipboard via clicking key name |
| 56 | + // cy.getByTestID('secret-card--name CocaColaRecipe') |
| 57 | + // .click() |
| 58 | + // .then(() => { |
| 59 | + // cy.task('getClipboard').should('eq', 'CocaColaRecipe') |
| 60 | + // }) |
| 61 | + |
| 62 | + cy.get('span') |
| 63 | + .filter('[data-testid*="secret-card--"]') |
| 64 | + .should('have.length', 2) |
| 65 | + |
| 66 | + const aToZ = ['CocaColaRecipe', 'toEverybody'] |
| 67 | + const zToA = aToZ.slice().reverse() |
| 68 | + |
| 69 | + cy.get('span') |
| 70 | + .filter('[data-testid*="secret-card--"]') |
| 71 | + .each((val, index) => { |
| 72 | + expect(val.text()).to.equal(aToZ[index]) |
| 73 | + }) |
| 74 | + |
| 75 | + cy.getByTestID('resource-sorter').click() |
| 76 | + cy.getByTestID('resource-sorter--id-desc').click() |
| 77 | + cy.get('span') |
| 78 | + .filter('[data-testid*="secret-card--"]') |
| 79 | + .each((val, index) => { |
| 80 | + expect(val.text()).to.equal(zToA[index]) |
| 81 | + }) |
| 82 | + |
| 83 | + // Delete API created secrets via the UI |
| 84 | + cy.getByTestID('context-delete-menu toEverybody--button').click({ |
| 85 | + force: true, |
44 | 86 | }) |
45 | | - // Create a second secret via the API, make sure it's visible and test sorting |
46 | | - .upsertSecret(orgID, {CocaColaRecipe: 'lol'}) |
47 | | - cy.reload() |
48 | | - cy.getByTestID('secret-card--toEverybody').should('exist') |
49 | | - cy.getByTestID('secret-card--toEverybody').should('be.visible') |
50 | | - cy.getByTestID('secret-card--CocaColaRecipe').should('exist') |
51 | | - cy.getByTestID('secret-card--CocaColaRecipe').should('be.visible') |
52 | | - |
53 | | - // Leaving commented out copy to clipboard tests per the above comment - JF |
54 | | - // Test copy to clipboard via clicking key name |
55 | | - // cy.getByTestID('secret-card--name CocaColaRecipe') |
56 | | - // .click() |
57 | | - // .then(() => { |
58 | | - // cy.task('getClipboard').should('eq', 'CocaColaRecipe') |
59 | | - // }) |
60 | | - |
61 | | - cy.get('span') |
62 | | - .filter('[data-testid*="secret-card--"]') |
63 | | - .should('have.length', 2) |
64 | | - |
65 | | - const aToZ = ['CocaColaRecipe', 'toEverybody'] |
66 | | - const zToA = aToZ.slice().reverse() |
67 | | - |
68 | | - cy.get('span') |
69 | | - .filter('[data-testid*="secret-card--"]') |
70 | | - .each((val, index) => { |
71 | | - expect(val.text()).to.equal(aToZ[index]) |
| 87 | + cy.getByTestID( |
| 88 | + 'context-delete-menu toEverybody--confirm-button' |
| 89 | + ).should('exist') |
| 90 | + cy.getByTestID('context-delete-menu toEverybody--confirm-button').click( |
| 91 | + { |
| 92 | + force: true, |
| 93 | + } |
| 94 | + ) |
| 95 | + cy.wait('@deleteSecret') |
| 96 | + .its('response.statusCode') |
| 97 | + .should('eq', 204) |
| 98 | + // After deletion that secret should no longer exist |
| 99 | + cy.getByTestID('secret-card--toEverybody').should('not.exist') |
| 100 | + |
| 101 | + // Create new secret via UI, then edit it once created |
| 102 | + const secretName = 'Shhhhh' |
| 103 | + cy.getByTestID('button-add-secret') |
| 104 | + .first() // There's a second one in the empty state. |
| 105 | + .click() |
| 106 | + cy.getByTestID('variable-form-save').should('be.disabled') |
| 107 | + cy.getByTestID('input--secret-name') |
| 108 | + .first() |
| 109 | + .type(secretName) |
| 110 | + cy.getByTestID('variable-form-save').should('be.disabled') |
| 111 | + cy.getByTestID('input--secret-value') |
| 112 | + .last() |
| 113 | + .type("I'm a secret!") |
| 114 | + cy.getByTestID('variable-form-save').should('be.enabled') |
| 115 | + cy.getByTestID('variable-form-save').click() |
| 116 | + cy.wait('@upsertSecret') |
| 117 | + .its('response.statusCode') |
| 118 | + .should('eq', 204) |
| 119 | + cy.getByTestID(`secret-card--${secretName}`).should('exist') |
| 120 | + cy.getByTestID(`secret-card--${secretName}`).should('be.visible') |
| 121 | + cy.getByTestID(`secret-card--name-${secretName}`).click() |
| 122 | + cy.getByTestID('input-field').should('be.disabled') |
| 123 | + cy.getByTestID('input-field').should('have.value', secretName) |
| 124 | + cy.getByTestID('input-field') |
| 125 | + .last() |
| 126 | + .type("I'm hunting rabbits") |
| 127 | + cy.getByTestID('variable-form-save').should('be.enabled') |
| 128 | + cy.getByTestID('variable-form-save').click() |
| 129 | + cy.wait('@upsertSecret') |
| 130 | + .its('response.statusCode') |
| 131 | + .should('eq', 204) |
| 132 | + }) |
| 133 | + }) |
| 134 | + }) |
| 135 | + describe('usage in notebooks', () => { |
| 136 | + beforeEach(() => { |
| 137 | + cy.flush() |
| 138 | + cy.setFeatureFlags({ |
| 139 | + fluxInjectSecrets: true, |
| 140 | + }) |
| 141 | + cy.signin() |
| 142 | + cy.get('@org').then(({id}: Organization) => |
| 143 | + cy.fixture('routes').then(({orgs}) => { |
| 144 | + cy.visit(`${orgs}/${id}`) |
72 | 145 | }) |
| 146 | + ) |
| 147 | + cy.getByTestID('version-info') |
| 148 | + cy.getByTestID('nav-item-flows').should('be.visible') |
| 149 | + cy.getByTestID('nav-item-flows').click() |
| 150 | + cy.getByTestID('preset-script') |
| 151 | + .first() |
| 152 | + .click() |
| 153 | + cy.getByTestID('time-machine-submit-button').should('be.visible') |
| 154 | + }) |
| 155 | + |
| 156 | + it('sidebar can create and inject a secret', () => { |
| 157 | + cy.getByTestID('flux-editor') |
| 158 | + .should('be.visible') |
| 159 | + .monacoType('{selectall} {backspace}') |
| 160 | + |
| 161 | + cy.log('open secrets sidebar') |
| 162 | + cy.getByTestID('sidebar-button') |
| 163 | + .should('be.visible') |
| 164 | + .first() |
| 165 | + .click() |
| 166 | + cy.getByTestID('Inject Secret--list-item') |
| 167 | + .should('be.visible') |
| 168 | + .click() |
73 | 169 |
|
74 | | - cy.getByTestID('resource-sorter').click() |
75 | | - cy.getByTestID('resource-sorter--id-desc').click() |
76 | | - cy.get('span') |
77 | | - .filter('[data-testid*="secret-card--"]') |
78 | | - .each((val, index) => { |
79 | | - expect(val.text()).to.equal(zToA[index]) |
| 170 | + cy.log('create secret') |
| 171 | + const secretName = 'Bandersnatch' |
| 172 | + cy.getByTestID('button-add-secret') |
| 173 | + .should('be.visible') |
| 174 | + .click() |
| 175 | + cy.getByTestID('overlay--container') |
| 176 | + .should('be.visible') |
| 177 | + .within(() => { |
| 178 | + cy.getByTestID('input--secret-name') |
| 179 | + .should('be.visible') |
| 180 | + .type(secretName) |
| 181 | + cy.getByTestID('input--secret-value') |
| 182 | + .should('be.visible') |
| 183 | + .type('wordz') |
| 184 | + cy.getByTestID('variable-form-save') |
| 185 | + .should('be.visible') |
| 186 | + .click() |
80 | 187 | }) |
| 188 | + cy.getByTestID(`flux--select-secret-${secretName}`).should('be.visible') |
81 | 189 |
|
82 | | - // Delete API created secrets via the UI |
83 | | - cy.getByTestID('context-delete-menu toEverybody--button').click({ |
| 190 | + cy.log('inject secret') |
| 191 | + cy.getByTestID(`flux--select-secret-${secretName}`).should('be.visible') |
| 192 | + cy.getByTestID(`flux--select-secret-${secretName}--inject`).click({ |
84 | 193 | force: true, |
85 | 194 | }) |
86 | | - cy.getByTestID('context-delete-menu toEverybody--confirm-button').should( |
87 | | - 'exist' |
88 | | - ) |
89 | | - cy.getByTestID('context-delete-menu toEverybody--confirm-button').click({ |
90 | | - force: true, |
| 195 | + cy.getByTestID('flux-editor').within(() => { |
| 196 | + cy.get('.view-line') |
| 197 | + .first() |
| 198 | + .contains(`"influxdata/influxdb/secrets"`) |
| 199 | + cy.get('.view-line') |
| 200 | + .last() |
| 201 | + .contains(secretName) |
91 | 202 | }) |
92 | | - cy.wait('@deleteSecret') |
93 | | - .its('response.statusCode') |
94 | | - .should('eq', 204) |
95 | | - // After deletion that secret should no longer exist |
96 | | - cy.getByTestID('secret-card--toEverybody').should('not.exist') |
97 | | - |
98 | | - // Create new secret via UI, then edit it once created |
99 | | - const secretName = 'Shhhhh' |
100 | | - cy.getByTestID('button-add-secret') |
101 | | - .first() // There's a second one in the empty state. |
| 203 | + |
| 204 | + cy.log('confirm query payload') |
| 205 | + cy.intercept('POST', '/api/v2/query?*').as('query') |
| 206 | + cy.getByTestID('time-machine-submit-button') |
| 207 | + .should('be.visible') |
102 | 208 | .click() |
103 | | - cy.getByTestID('variable-form-save').should('be.disabled') |
104 | | - cy.getByTestID('input--secret-name') |
105 | | - .first() |
106 | | - .type(secretName) |
107 | | - cy.getByTestID('variable-form-save').should('be.disabled') |
108 | | - cy.getByTestID('input--secret-value') |
109 | | - .last() |
110 | | - .type("I'm a secret!") |
111 | | - cy.getByTestID('variable-form-save').should('be.enabled') |
112 | | - cy.getByTestID('variable-form-save').click() |
113 | | - cy.wait('@upsertSecret') |
114 | | - .its('response.statusCode') |
115 | | - .should('eq', 204) |
116 | | - cy.getByTestID(`secret-card--${secretName}`).should('exist') |
117 | | - cy.getByTestID(`secret-card--${secretName}`).should('be.visible') |
118 | | - cy.getByTestID(`secret-card--name-${secretName}`).click() |
119 | | - cy.getByTestID('input-field').should('be.disabled') |
120 | | - cy.getByTestID('input-field').should('have.value', secretName) |
121 | | - cy.getByTestID('input-field') |
122 | | - .last() |
123 | | - .type("I'm hunting rabbits") |
124 | | - cy.getByTestID('variable-form-save').should('be.enabled') |
125 | | - cy.getByTestID('variable-form-save').click() |
126 | | - cy.wait('@upsertSecret') |
127 | | - .its('response.statusCode') |
128 | | - .should('eq', 204) |
| 209 | + const expected = `import "influxdata/influxdb/secrets"\n\nsecrets.get(key: "${secretName}")` |
| 210 | + cy.wait('@query').then(({request}) => { |
| 211 | + expect(request.body.query).to.include(expected) |
| 212 | + }) |
129 | 213 | }) |
130 | 214 | }) |
131 | 215 | }) |
0 commit comments