You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nextcloud/cypress/e2e/login/login.cy.ts

153 lines
5.3 KiB
TypeScript

/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
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 account 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 account
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 account 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 account 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 account 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 account 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.+login/))
cy.get('input[name="password"]:invalid').should('exist')
})
it('try to log in with invalid account', () => {
// 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.+login/))
cy.get('input[name="password"]:invalid').should('exist')
})
it('try to log in as disabled account', () => {
// 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 account message is shown
cy.get('form[name="login"]').then(($el) => expect($el.text()).to.match(/Account.+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/)
})
})