Skip to content

Commit 63e6b59

Browse files
author
Eduard Brehm
committed
Add second, not privileged user, increase timeout, and fix several minor bugs
1 parent c6a8867 commit 63e6b59

File tree

3 files changed

+216
-33
lines changed

3 files changed

+216
-33
lines changed

conf.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"url": "http://localhost:3000/oauth2/token",
33
"client": "tester",
44
"clientsecret": "secret",
5-
"user": "agile",
5+
"adminuser": "agile",
6+
"adminusersecret": "secret",
7+
"user": "bob",
68
"usersecret": "secret",
79
"tabs": {
810
"discover": {

cypress.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"chromeWebSecurity": false,
3-
"defaultCommandTimeout": 7000
3+
"defaultCommandTimeout": 10000
44
}

cypress/integration/agile-ui.js

+212-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
let conf = require('../../conf.json')
22

3-
let auth_options = {
3+
let admin_auth = {
4+
method: 'POST',
5+
url: conf.url,
6+
auth: {
7+
user: conf.client,
8+
pass: conf.clientsecret
9+
},
10+
form: true,
11+
body: {
12+
grant_type: 'password',
13+
username: conf.adminuser,
14+
password: conf.adminusersecret
15+
}
16+
}
17+
18+
let user_auth = {
419
method: 'POST',
520
url: conf.url,
621
auth: {
@@ -15,9 +30,18 @@ let auth_options = {
1530
}
1631
}
1732

18-
function authAndVisitUI() {
33+
function adminAuthAndVisitUI() {
34+
return new Promise(() => {
35+
cy.request(admin_auth).then(res => {
36+
let token = res.body.access_token
37+
cy.visit('http://localhost:2000?token=' + token)
38+
})
39+
})
40+
}
41+
42+
function userAuthAndVisitUI() {
1943
return new Promise(() => {
20-
cy.request(auth_options).then(res => {
44+
cy.request(user_auth).then(res => {
2145
let token = res.body.access_token
2246
cy.visit('http://localhost:2000?token=' + token)
2347
})
@@ -26,17 +50,18 @@ function authAndVisitUI() {
2650

2751
function expand() {
2852
return cy.location().then(loc => {
53+
cy.wait(1000)
2954
let parts = loc.pathname.split('/')
3055
let id = parts.find(part => {
3156
return part.includes('!@!')
3257
})
33-
cy.get('#' + id.replace('!@!', '-')).click()
58+
cy.get('#' + id.replace('!@!', '-')).click('left')
3459
})
3560
}
3661

37-
describe('User view privileges', () => {
62+
describe('Security User', () => {
3863
beforeEach(() => {
39-
authAndVisitUI()
64+
userAuthAndVisitUI()
4065
cy.wait(3000) //Let react load all state objects
4166
})
4267

@@ -62,13 +87,13 @@ describe('User view privileges', () => {
6287
cy.get('#navigation').get('button').then(tabs => {
6388
tabs[conf.tabs.userlist.index].click()
6489
cy.location('pathname').should('eq', conf.tabs.userlist.path)
65-
cy.get('#group_agile-agile-local').click()
90+
cy.get('#group_' + conf.adminuser + '-agile-local').click()
6691
cy.get('#root_groups').should('exist')
6792
cy.get('#root_groups').contains('cypress-group').find(':checkbox').should('be.not.checked')
6893
cy.get('#root_groups').contains('cypress-group').find(':checkbox').check()
6994
cy.get('button[type="submit"]').then(submit => {
7095
submit.click()
71-
cy.wait(500)
96+
cy.wait(3000)
7297
tabs[conf.tabs.groups.index].click()
7398
})
7499
cy.get('#view_cypress-group').click()
@@ -80,17 +105,177 @@ describe('User view privileges', () => {
80105
cy.get('#navigation').get('button').then(tabs => {
81106
tabs[conf.tabs.userlist.index].click()
82107
cy.location('pathname').should('eq', conf.tabs.userlist.path)
83-
cy.get('#group_agile-agile-local').click()
108+
cy.get('#group_' + conf.adminuser + '-agile-local').click()
109+
cy.wait(1000)
84110
cy.get('#root_groups').should('exist')
85111
cy.get('#root_groups').contains('cypress-group').find(':checkbox').should('be.checked')
86112
cy.get('#root_groups').contains('cypress-group').find(':checkbox').uncheck()
87113
cy.get('button[type="submit"]').then(submit => {
88114
submit.click()
89-
cy.wait(500)
115+
cy.wait(3000)
90116
tabs[conf.tabs.groups.index].click()
91117
})
92118
cy.get('#view_cypress-group').click()
93-
cy.get('.container--app').should('not.contain', 'agile!@!agile-local')
119+
cy.get('.container--app').should('not.contain', conf.adminuser + '!@!agile-local')
120+
})
121+
122+
//Delete group
123+
cy.get('#navigation').get('button').then(tabs => {
124+
tabs[conf.tabs.groups.index].click()
125+
cy.get('#cypress-group').should('exist')
126+
cy.get('#delete_cypress-group').click()
127+
cy.wait(1000)
128+
cy.get('#cypress-group').should('not.exist')
129+
})
130+
})
131+
132+
it('Create and delete entities', () => {
133+
cy.get('#navigation').get('button').then(tabs => {
134+
tabs[conf.tabs.userlist.index].click()
135+
cy.get('#cypress-agile-local').should('not.exist')
136+
})
137+
138+
cy.get('#navigation').get('button').then(tabs => {
139+
tabs[conf.tabs.userlist.index].click()
140+
let regex = new RegExp(conf.tabs.userlist.path.replace(/:[a-zA-Z]*/, '.*'))
141+
cy.url().should('match', regex)
142+
cy.wait(1500)
143+
cy.get('#new_entity_button').click()
144+
cy.location('pathname').should('eq', conf.views.addUser.path)
145+
cy.get('#root_user_name').type('cypress')
146+
cy.get('#root_auth_type').select('agile-local')
147+
cy.get('#root_password').type('secret')
148+
cy.get('#root_role').select('admin')
149+
cy.get('button[type="submit"]').click()
150+
cy.wait(3000)
151+
152+
})
153+
154+
cy.get('#navigation').get('button').then(tabs => {
155+
let workingtab = conf.tabs.userlist
156+
tabs[workingtab.index].click()
157+
cy.get('#cypress-agile-local').should('not.exist')
158+
})
159+
})
160+
161+
it('Add and update attribute to own user entity and delete it', () => {
162+
cy.get('#navigation').get('button').then(tabs => {
163+
let workingtab = conf.tabs.profile
164+
tabs[workingtab.index].click()
165+
let regex = new RegExp(workingtab.path.replace(/:[a-zA-Z]*/, '.*'))
166+
cy.url().should('match', regex)
167+
expand()
168+
cy.get('#cypress').should('not.exist')
169+
cy.get('span').contains('cypress').should('not.exist')
170+
cy.get('span').contains('cypress.value').should('not.exist')
171+
cy.get('#new-attribute').type('cypress')
172+
cy.get('#new-attribute-value').type('cypress.value')
173+
cy.get('#new-attribute-submit').click()
174+
cy.get('#cypress').should('exist')
175+
cy.get('#cypress_value').should('have.value', 'cypress.value')
176+
cy.get('#cypress_value').clear()
177+
cy.get('#cypress_value').type('updated.value')
178+
cy.get('#navigation')
179+
cy.get('#cypress_value').should('have.value', 'updated.value')
180+
cy.get('#delete_cypress').click()
181+
cy.get('#cypress').should('not.exist')
182+
})
183+
})
184+
185+
it('Switch to user overview tab and view first user attributes', () => {
186+
cy.get('#navigation').get('button').then(tabs => {
187+
let workingtab = conf.tabs.userlist
188+
tabs[workingtab.index].click()
189+
cy.location('pathname').should('eq', workingtab.path)
190+
cy.wait(1500)
191+
cy.get('#view_' + conf.adminuser + '-agile-local').click() //First user attributes
192+
let regex = new RegExp(conf.views.user.path.replace(/:[a-zA-Z]*/, '.*'))
193+
cy.url().should('match', regex)
194+
cy.get('#' + conf.adminuser + '-agile-local')
195+
cy.get('#new_password').should('not.exist')
196+
cy.get('#old_password').should('not.exist')
197+
expand()
198+
cy.get('span').contains('id').should('be.visible')
199+
})
200+
})
201+
202+
it('Switch to user overview tab and view second user attributes', () => {
203+
cy.get('#navigation').get('button').then(tabs => {
204+
let workingtab = conf.tabs.userlist
205+
tabs[workingtab.index].click()
206+
cy.location('pathname').should('eq', workingtab.path)
207+
cy.wait(1500)
208+
cy.get('#view_' + conf.user + '-agile-local').click() //First user attributes
209+
let regex = new RegExp(conf.views.user.path.replace(/:[a-zA-Z]*/, '.*'))
210+
cy.url().should('match', regex)
211+
cy.wait(1500)
212+
cy.get('#new_password').should('exist')
213+
cy.get('#old_password').should('exist')
214+
expand()
215+
cy.get('span').contains('id').should('be.visible')
216+
})
217+
})
218+
})
219+
220+
describe('Security Admin', () => {
221+
beforeEach(() => {
222+
adminAuthAndVisitUI()
223+
cy.wait(3000) //Let react load all state objects
224+
})
225+
226+
it('Create, assign and delete group', () => {
227+
cy.get('#navigation').get('button').then(tabs => {
228+
tabs[conf.tabs.groups.index].click()
229+
cy.get('#cypress-agile-local').should('not.exist')
230+
})
231+
232+
//Create group
233+
cy.get('#navigation').get('button').then(tabs => {
234+
tabs[conf.tabs.groups.index].click()
235+
let regex = new RegExp(conf.tabs.groups.path.replace(/:[a-zA-Z]*/, '.*'))
236+
cy.url().should('match', regex)
237+
cy.wait(500)
238+
cy.get('#new_entity_button').click()
239+
cy.get('#root_group_name').type('cypress-group')
240+
cy.get('button[type="submit"]').click()
241+
cy.wait(500)
242+
})
243+
244+
//Assign group
245+
cy.get('#navigation').get('button').then(tabs => {
246+
tabs[conf.tabs.userlist.index].click()
247+
cy.location('pathname').should('eq', conf.tabs.userlist.path)
248+
cy.get('#group_' + conf.adminuser + '-agile-local').click()
249+
cy.wait(1000)
250+
cy.get('#root_groups').should('exist')
251+
cy.get('#root_groups').contains('cypress-group').find(':checkbox').should('be.not.checked')
252+
cy.get('#root_groups').contains('cypress-group').find(':checkbox').check()
253+
cy.get('button[type="submit"]').then(submit => {
254+
submit.click()
255+
cy.wait(3000)
256+
tabs[conf.tabs.groups.index].click()
257+
})
258+
cy.get('#view_cypress-group').click()
259+
cy.wait(1000)
260+
cy.get('.container--app').should('contain', conf.adminuser + '!@!agile-local')
261+
})
262+
263+
//Remove user from group
264+
cy.get('#navigation').get('button').then(tabs => {
265+
tabs[conf.tabs.userlist.index].click()
266+
cy.location('pathname').should('eq', conf.tabs.userlist.path)
267+
cy.get('#group_' + conf.adminuser + '-agile-local').click()
268+
cy.wait(1000)
269+
cy.get('#root_groups').should('exist')
270+
cy.get('#root_groups').contains('cypress-group').find(':checkbox').should('be.checked')
271+
cy.get('#root_groups').contains('cypress-group').find(':checkbox').uncheck()
272+
cy.get('button[type="submit"]').then(submit => {
273+
submit.click()
274+
cy.wait(3000)
275+
tabs[conf.tabs.groups.index].click()
276+
})
277+
cy.get('#view_cypress-group').click()
278+
cy.get('.container--app').should('not.contain', conf.adminuser + '!@!agile-local')
94279
})
95280

96281
//Delete group
@@ -165,16 +350,14 @@ describe('User view privileges', () => {
165350
tabs[workingtab.index].click()
166351
cy.location('pathname').should('eq', workingtab.path)
167352
cy.wait(1500)
168-
cy.get('.container--app').get('a').then(viewbuttons => {
169-
viewbuttons[workingtab.buttons.view].click() //First user attributes
170-
let regex = new RegExp(conf.views.user.path.replace(/:[a-zA-Z]*/, '.*'))
171-
cy.url().should('match', regex)
172-
cy.wait(1500)
173-
cy.get('#new_password').should('exist')
174-
cy.get('#old_password').should('exist')
175-
expand()
176-
cy.get('span').contains('id').should('be.visible')
177-
})
353+
cy.get('#view_' + conf.adminuser + '-agile-local').click() //First user attributes //First user attributes
354+
let regex = new RegExp(conf.views.user.path.replace(/:[a-zA-Z]*/, '.*'))
355+
cy.url().should('match', regex)
356+
cy.wait(1500)
357+
cy.get('#new_password').should('exist')
358+
cy.get('#old_password').should('exist')
359+
expand()
360+
cy.get('span').contains('id').should('be.visible')
178361
})
179362
})
180363

@@ -184,16 +367,14 @@ describe('User view privileges', () => {
184367
tabs[workingtab.index].click()
185368
cy.location('pathname').should('eq', workingtab.path)
186369
cy.wait(1500)
187-
cy.get('.container--app').get('a').then(viewbuttons => {
188-
viewbuttons[workingtab.buttons.view + Object.keys(workingtab.buttons).length].click() //Second user attributes
189-
let regex = new RegExp(conf.views.user.path.replace(/:[a-zA-Z]*/, '.*'))
190-
cy.url().should('match', regex)
191-
cy.wait(1500)
192-
cy.get('#new_password').should('exist')
193-
cy.get('#old_password').should('not.exist')
194-
expand()
195-
cy.get('span').contains('id').should('be.visible')
196-
})
370+
cy.get('#view_' + conf.user + '-agile-local').click() //First user attributes //Second user attributes
371+
let regex = new RegExp(conf.views.user.path.replace(/:[a-zA-Z]*/, '.*'))
372+
cy.url().should('match', regex)
373+
cy.wait(1500)
374+
cy.get('#new_password').should('exist')
375+
cy.get('#old_password').should('not.exist')
376+
expand()
377+
cy.get('span').contains('id').should('be.visible')
197378
})
198379
})
199380
})

0 commit comments

Comments
 (0)