Skip to content
Snippets Groups Projects
Commit c7d9a000 authored by André Angelantoni's avatar André Angelantoni
Browse files

Add reset password test.

parent ec3c6cde
No related branches found
No related tags found
No related merge requests found
Automated Testing Kit 2023-06-18
------------------------------------
- Initial release
Automated Testing Kit 1.0.0-beta1, 2023-06-18
---------------------------------------------
- Initial release.
Automated Testing Kit 1.0.0-beta2, 2023-06-29
---------------------------------------------
Changes since 1.0.0-beta1:
- Added reset password tests (ATK-CY-1030, ATK-PW-1030).
- Added test codes to tags.
- Added resetPasswordUrl to atkConfig.
- In Cypress, switched from execPantheonDrush:remote:drush to ssh tunnel.
- In Cypress, switched to cy.log.
......@@ -25,14 +25,14 @@ describe('User registration and login tasks.', () => {
//
// Register the Ethereal user and confirm email reaches Ethereal.
//
it('(ATK-CY-1000) Register with form and confirm email with Ethereal.', { tags: ['register-login', 'alters-db', 'smoke'] }, () => {
it('(ATK-CY-1000) Register with form and confirm email with Ethereal.', { tags: ['ATK-CY-1000', 'register-login', 'alters-db', 'smoke'] }, () => {
// Clean up user in case it exists.
cy.deleteUserWithEmail(userEtherealAccount.userEmail, ['--delete-content'])
// Ensure user is logged out.
cy.logOutViaUi()
// Begin registration.
// Begin registration. Use random string to identify user in Ethereal.email.
const extendedUserName = userEtherealAccount.userName + '-' + atkUtilities.createRandomString(6)
cy.visit(atkConfig.registerUrl).then(() => {
cy.get('#edit-mail').type(userEtherealAccount.userEmail)
......@@ -77,42 +77,101 @@ describe('User registration and login tasks.', () => {
//
// Log in with the login form into the authenticated account.
//
it('(ATK-CY-1010) Log in with form.', { tags: ['register-login', 'smoke'] }, () => {
it('(ATK-CY-1010) Log in with form.', { tags: ['ATK-CY-1010', 'register-login', 'smoke'] }, () => {
cy.logInViaForm(qaUserAccounts.authenticated)
})
//
// Log in with a POST request into the authenticated account.
// TODO: Not ready yet.
//
it.skip('(ATK-CY-1011) Log in with POST.', { tags: ['register-login', 'smoke'] }, () => {
// TODO: Not ready yet.
it.skip('(ATK-CY-1011) Log in with POST.', { tags: ['ATK-CY-1011', 'register-login', 'smoke'] }, () => {
// cy.logInViaPost(qaUserAccounts.authenticated)
})
//
// Log in with a ULI generated by Drupal.
//
it('(ATK-CY-1012) Log in via ULI.', { tags: ['register-login', 'smoke'] }, () => {
it('(ATK-CY-1012) Log in via ULI.', { tags: ['ATK-CY-1012', 'register-login', 'smoke'] }, () => {
cy.logInViaUli(1) // Log in as admin.
})
//
// Create a user with Drush from a fixture and delete it.
//
it('(ATK-CY-1020) Create user with Drush, delete by email.', { tags: ['register-login', 'smoke'] }, () => {
it('(ATK-CY-1020) Create user with Drush, delete by email.', { tags: ['ATK-CY-1020', 'register-login', 'smoke'] }, () => {
cy.deleteUserWithEmail(userEtherealAccount.userEmail, [], ['--delete-content'])
cy.createUserWithUserObject(userEtherealAccount, ['content_editor'])
cy.createUserWithUserObject(userEtherealAccount, [])
cy.deleteUserWithEmail(userEtherealAccount.userEmail, [], ['--delete-content'])
})
//
// Create a user with Drush from a fixture and delete it by UID.
//
it('(ATK-CY-1021) Create user with Drush, delete by UID.', { tags: ['register-login', 'smoke'] }, () => {
it('(ATK-CY-1021) Create user with Drush, delete by UID.', { tags: ['ATK-CY-1021', 'register-login', 'smoke'] }, () => {
cy.deleteUserWithEmail(userEtherealAccount.userEmail, [], ['--delete-content'])
cy.createUserWithUserObject(userEtherealAccount, ['content_editor'])
cy.createUserWithUserObject(userEtherealAccount, [])
cy.getUidWithEmail(userEtherealAccount.userEmail).then((uid) => {
cy.deleteUserWithUid(uid, [], ['--delete-content'])
})
})
//
// Validate reset password function.
//
it('(ATK-CY-1030) Reset password.', { tags: ['ATK-CY-1030', 'register-login', 'smoke'] }, () => {
cy.deleteUserWithEmail(userEtherealAccount.userEmail, [], ['--delete-content'])
// Use random string to identify user in Ethereal.email.
const extendedUserName = userEtherealAccount.userName + '-' + atkUtilities.createRandomString(6)
const resetAccount = {
userName: extendedUserName,
userEmail: userEtherealAccount.userEmail,
userPassword: userEtherealAccount.userEmail,
userRoles: []
}
cy.createUserWithUserObject(resetAccount, [])
cy.visit(atkConfig.resetPasswordUrl).then(() => {
cy.get('#edit-name').type(extendedUserName)
cy.get('#user-pass > #edit-actions > #edit-submit').click()
})
// Check for tail end of reset message.
cy.contains('an email will be sent with instructions to reset your password.')
// Give the email some time to arrive.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000)
// Check for registration email at Ethereal.
const sentArgs = {
userName: extendedUserName,
userEmail: resetAccount.userEmail,
userPassword: resetAccount.userPassword,
longUserName: extendedUserName
}
cy.origin('https://ethereal.email', { args: sentArgs }, ({ userName, userEmail, userPassword, longUserName }) => {
cy.visit('/login')
cy.get('#address').type(userEmail)
cy.get('#password').type(userPassword)
cy.get('form > :nth-child(5) > .btn').click()
cy.contains('Logged in as ' + userEmail)
cy.visit('/messages', true)
cy.contains('Messages for ' + userEmail)
// Look for email in the first column and the username + userCode generated above
// in the second column that's the user email.
const toValue = 'To: <' + userEmail + '>'
const subjectValue = 'Replacement login information for ' + longUserName
cy.get('table tr').contains('td', toValue).parent().contains('td', subjectValue)
})
cy.deleteUserWithEmail(userEtherealAccount.userEmail, [], ['--delete-content'])
})
})
......@@ -35,18 +35,18 @@ Cypress.Commands.add('createUserWithUserObject', (user, roles = [], args = [], o
let cmd = 'user:create '
if (args === undefined || !Array.isArray(args)) {
console.log('createUserWithUserObject: Pass an array for args.')
cy.log('createUserWithUserObject: Pass an array for args.')
return
}
if (options === undefined || !Array.isArray(options)) {
console.log('createUserWithUserObject: Pass an array for options.')
cy.log('createUserWithUserObject: Pass an array for options.')
return
}
args.unshift(`'${user.userName}'`)
options.push(`--mail='${user.userEmail}'`, `--password='${user.userPassword}'`)
console.log(`Attempting to create: ${user.userName}. `)
cy.log(`Attempting to create: ${user.userName}. `)
cy.execDrush(cmd, args, options).then((result) => {
// TODO: Bring this in when execDrush reliably
......@@ -68,7 +68,7 @@ Cypress.Commands.add('createUserWithUserObject', (user, roles = [], args = [], o
roles.forEach(function (role) {
cmd = `user:role:add '${role}' '${user.userName}'`
cy.execDrush(cmd)
console.log(`${role}: If role exists, role assigned to the user ${user.userName}`)
cy.log(`${role}: If role exists, role assigned to the user ${user.userName}`)
})
})
})
......@@ -81,7 +81,7 @@ Cypress.Commands.add('createUserWithUserObject', (user, roles = [], args = [], o
*/
Cypress.Commands.add('deleteUserWithEmail', (email, options = []) => {
if (options === undefined || !Array.isArray(options)) {
console.log('deleteUserWithEmail: Pass an array for options.')
cy.log('deleteUserWithEmail: Pass an array for options.')
}
// TODO: --mail doesn't working without an argument.
......@@ -102,7 +102,7 @@ Cypress.Commands.add('deleteUserWithEmail', (email, options = []) => {
*/
Cypress.Commands.add('deleteUserWithUid', (uid, options = []) => {
if (options === undefined || !Array.isArray(options)) {
console.log('deleteUserWithUid: Pass an array for options.')
cy.log('deleteUserWithUid: Pass an array for options.')
}
options.push(`--uid='${uid}'`)
......@@ -125,16 +125,16 @@ Cypress.Commands.add('deleteUserWithUserName', (userName, args = [], options = [
const cmd = `user:cancel -y '${userName}'`
if (args === undefined || !Array.isArray(args)) {
console.log('deleteUserWithUserName: Pass an array for args.')
cy.log('deleteUserWithUserName: Pass an array for args.')
return
}
if (options === undefined || !Array.isArray(options)) {
console.log('deleteUserWithUserName: Pass an array for options.')
cy.log('deleteUserWithUserName: Pass an array for options.')
return
}
console.log(`Attempting to delete: ${userName}. `)
cy.log(`Attempting to delete: ${userName}. `)
cy.execDrush(cmd, args, options)
})
......@@ -153,12 +153,12 @@ Cypress.Commands.add('execDrush', (cmd, args = [], options = []) => {
let output = ''
if (args === undefined || !Array.isArray(args)) {
console.log('execDrush: Pass an array for arguments.')
cy.log('execDrush: Pass an array for arguments.')
return
}
if (options === undefined || !Array.isArray(options)) {
console.log('execDrush: Pass an array for options.')
cy.log('execDrush: Pass an array for options.')
return
}
......@@ -174,28 +174,41 @@ Cypress.Commands.add('execDrush', (cmd, args = [], options = []) => {
} else {
cy.exec(command, { failOnNonZeroExit: false }).then((result) => {
output = result.stdout
console.log('cy.exec: ' + output)
return cy.wrap(output)
cy.log('cy.exec result: ' + output)
return cy.wrap(output, {log: false})
})
}
})
/**
* Run a Pantheon Drush command via Terminus.
* Run a Pantheon Drush command via SSH.
* Called by execDrush().
* TODO: Use Terminus instead, ssh is a workaround.
* As of 2023-07-01, various Terminus commands, such as "terminus remote:drush", never return.
* Using ssh tunnel instead.
*
* @param {string} cmd Drush command execDrush() contructs this with args and options.
* @returns {string} The output from executing the command in a shell.
*/
Cypress.Commands.add('execPantheonDrush', (cmd) => {
// Construct the Terminus command. Remove "drush" from argument.
const remoteCmd = `terminus remote:drush ${atkConfig.pantheon.site}.${atkConfig.pantheon.environment} -- ${cmd.substring(5)}`
const connectCmd = `terminus connection:info ${atkConfig.pantheon.site}.${atkConfig.pantheon.environment} --format=json`
cy.exec(remoteCmd, { failOnNonZeroExit: false, timeout: 20000 }).then((result) => {
output = result.stdout
console.log('cy.exec: ' + output)
return cy.wrap(output)
// Ask Terminus for SFTP command to send Drush to Pantheon.
cy.exec(connectCmd, { failOnNonZeroExit: false }).then((result) => {
debugger
const connections = JSON.parse(result.stdout)
const sftpConnection = connections.sftp_command
const envConnection = sftpConnection.replace('sftp -o Port=2222 ', '')
// Construct the command that will talk to the Pantheon server including
// the cmd argument.
const remoteCmd = `ssh -T ${envConnection} -p 2222 -o 'StrictHostKeyChecking=no' -o 'AddressFamily inet' '${cmd}'`
cy.exec(remoteCmd, { failOnNonZeroExit: false }).then((result) => {
let output = result.stdout
cy.log('cy.exec result: ' + output)
return cy.wrap(output, {log: false} )
})
})
})
......@@ -232,7 +245,7 @@ Cypress.Commands.add('getIframeBodyWithId', (iframeId) => {
// Wraps “body” DOM element to allow
// chaining more Cypress commands, like “.find(...)”
// https://on.cypress.io/wrap
.then(cy.wrap)
.then(cy.wrap, {log: false})
)
})
......@@ -253,7 +266,7 @@ Cypress.Commands.add('getUidWithEmail', (email) => {
for (const key in userJson) {
if (userJson[key].hasOwnProperty('uid')) {
const uidValue = userJson[key].uid
return cy.wrap(parseInt(uidValue)) // Exit the loop once the mail property is found.
return cy.wrap(parseInt(uidValue), {log: false}) // Exit the loop once the mail property is found.
}
}
}
......@@ -277,7 +290,7 @@ Cypress.Commands.add('getUsernameWithEmail', (email) => {
for (const key in userJson) {
if (userJson[key].hasOwnProperty('name')) {
const nameValue = userJson[key].name
return cy.wrap(nameValue) // Exit the loop once the mail property is found.
return cy.wrap(nameValue, {log: false}) // Exit the loop once the mail property is found.
}
}
}
......@@ -313,15 +326,15 @@ Cypress.Commands.add('logInViaForm', (account) => {
cy.get('#edit-pass').type(account.userPassword, { log: false, force: true })
// Click the log in button using ID.
cy.get('#edit-actions > #edit-submit').click({ force: true })
cy.get('head meta').then(console.log)
cy.get('#user-login-form > #edit-actions > #edit-submit').click({ force: true })
cy.get('head meta').then(cy.log)
},
{
validate() {
cy.visit('')
// Confirm log in worked.
cy.get('head meta').then(console.log)
cy.get('head meta').then(cy.log)
// Optional.
// should('include.text', 'user')
......
......@@ -7,6 +7,7 @@ module.exports = {
registerUrl: "user/register",
logInUrl: "user/login",
logOutUrl: "user/logout",
resetPasswordUrl: "user/password",
authDir: "cypress/support",
dataDir: "cypress/data",
supportDir: "cypress/support",
......@@ -15,5 +16,5 @@ module.exports = {
isTarget: false,
site: "aSite",
environment: "dev"
}
}
}
......@@ -7,6 +7,7 @@ module.exports = {
registerUrl: "user/register",
logInUrl: "user/login",
logOutUrl: "user/logout",
resetPasswordUrl: "user/password",
authDir: "tests/support",
dataDir: "tests/data",
supportDir: "tests/support",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment