-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
login.cy.ts
169 lines (146 loc) · 5.95 KB
/
login.cy.ts
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
/**
* @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
*
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import type { User } from '@nextcloud/cypress'
import { getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'
describe('Login', () => {
let user: User
let disabledUser: User
after(() => cy.deleteUser(user))
before(() => {
// disable brute force protection
cy.runOccCommand('config:system:set auth.bruteforce.protection.enabled --value false --type bool')
cy.createRandomUser().then(($user) => {
user = $user
})
cy.createRandomUser().then(($user) => {
disabledUser = $user
cy.runOccCommand(`user:disable '${disabledUser.userId}'`)
})
})
beforeEach(() => {
cy.logout()
})
it('log in with valid user and password', () => {
// Given I visit the Home page
cy.visit('/')
// I see the login page
cy.get('form[name="login"]').should('be.visible')
// I log in with a valid user
cy.get('form[name="login"]').within(() => {
cy.get('input[name="user"]').type(user.userId)
cy.get('input[name="password"]').type(user.password)
cy.contains('button[data-login-form-submit]', 'Log in').click()
})
// see that the login is done
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in')
// Then I see that the current page is the Files app
cy.url().should('match', /apps\/dashboard(\/|$)/)
})
it('try to log in with valid user and invalid password', () => {
// Given I visit the Home page
cy.visit('/')
// I see the login page
cy.get('form[name="login"]').should('be.visible')
// I log in with a valid user but invalid password
cy.get('form[name="login"]').within(() => {
cy.get('input[name="user"]').type(user.userId)
cy.get('input[name="password"]').type(`${user.password}--wrong`)
cy.contains('button', 'Log in').click()
})
// see that the login is done
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in')
// Then I see that the current page is the Login page
cy.url().should('match', /\/login/)
// And I see that a wrong password message is shown
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Wrong.+password/i))
cy.get('input[name="password"]:invalid').should('exist')
})
it('try to log in with valid user and invalid password', () => {
// Given I visit the Home page
cy.visit('/')
// I see the login page
cy.get('form[name="login"]').should('be.visible')
// I log in with a valid user but invalid password
cy.get('form[name="login"]').within(() => {
cy.get('input[name="user"]').type(user.userId)
cy.get('input[name="password"]').type(`${user.password}--wrong`)
cy.contains('button', 'Log in').click()
})
// see that the login is done
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in')
// Then I see that the current page is the Login page
cy.url().should('match', /\/login/)
// And I see that a wrong password message is shown
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Wrong.+password/i).and.to.match(/Wrong.+username/))
cy.get('input[name="password"]:invalid').should('exist')
})
it('try to log in with invalid user', () => {
// Given I visit the Home page
cy.visit('/')
// I see the login page
cy.get('form[name="login"]').should('be.visible')
// I log in with an invalid user but valid password
cy.get('form[name="login"]').within(() => {
cy.get('input[name="user"]').type(`${user.userId}--wrong`)
cy.get('input[name="password"]').type(user.password)
cy.contains('button', 'Log in').click()
})
// see that the login is done
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in')
// Then I see that the current page is the Login page
cy.url().should('match', /\/login/)
// And I see that a wrong password message is shown
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Wrong.+password/i).and.to.match(/Wrong.+username/))
cy.get('input[name="password"]:invalid').should('exist')
})
it('try to log in as disabled user', () => {
// Given I visit the Home page
cy.visit('/')
// I see the login page
cy.get('form[name="login"]').should('be.visible')
// When I log in with user disabledUser and password
cy.get('form[name="login"]').within(() => {
cy.get('input[name="user"]').type(disabledUser.userId)
cy.get('input[name="password"]').type(disabledUser.password)
cy.contains('button', 'Log in').click()
})
// see that the login is done
cy.get('[data-login-form-submit]').if().should('not.contain', 'Logging in')
// Then I see that the current page is the Login page
cy.url().should('match', /\/login/)
// And I see that the disabled user message is shown
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/User.+disabled/i))
cy.get('input[name="password"]:invalid').should('exist')
})
it('try to logout', () => {
cy.login(user)
// Given I visit the Home page
cy.visit('/')
// I see the dashboard
cy.url().should('match', /apps\/dashboard(\/|$)/)
// When click logout
getNextcloudUserMenuToggle().should('exist').click()
getNextcloudUserMenu().contains('a', 'Log out').click()
// Then I see that the current page is the Login page
cy.url().should('match', /\/login/)
})
})