From 6a0c6682ff4702f465b7c126786973d6840cd075 Mon Sep 17 00:00:00 2001 From: Joseph Baylon Date: Thu, 22 Oct 2020 13:08:51 -0700 Subject: [PATCH 1/5] Cypress/E2E: Fix disabled bot accounts section verification --- .../managing_bot_accounts_spec.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js index 6bd2c3a7c4f4..75892dd68c23 100644 --- a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js +++ b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js @@ -133,7 +133,7 @@ describe('Managing bot accounts', () => { cy.visit('/login'); // # Enter bot name in the email field - cy.findByPlaceholderText('Email, Username or AD/LDAP Username', {timeout: TIMEOUTS.ONE_MIN}).clear().type(botName); + cy.findByPlaceholderText('Email or Username', {timeout: TIMEOUTS.ONE_MIN}).clear().type(botName); // # Enter random password in the password field cy.findByPlaceholderText('Password').clear().type('invalidPassword@#%(^!'); @@ -159,13 +159,10 @@ describe('Managing bot accounts', () => { cy.findByText(`Test Bot (@${botName})`, {timeout: TIMEOUTS.ONE_MIN}).scrollIntoView().then((el) => { // # Click the disable button cy.wrap(el[0].parentElement.parentElement).find('button:nth-child(3)').should('be.visible').click(); - - // # Bring 'disabled' section into view - cy.get('.bot-list__disabled').scrollIntoView(); - - // * Check that the bot is in the 'disabled' section - cy.get('.bot-list__disabled').findByText(`Test Bot (@${botName})`).should('be.visible'); }); + + // * Check that the bot is in the 'disabled' section + cy.get('.bot-list__disabled').scrollIntoView().findByText(`Test Bot (@${botName})`).should('be.visible'); }); it('MM-T1857 Enable Bot', () => { @@ -182,13 +179,14 @@ describe('Managing bot accounts', () => { cy.get('#searchInput', {timeout: TIMEOUTS.ONE_MIN}).type(`${botName}`); // # Re-enable the bot - cy.findByText(`Test Bot (@${botName})`, {timeout: TIMEOUTS.ONE_MIN}).scrollIntoView().then((el) => { + cy.get('.bot-list__disabled').scrollIntoView().findByText(`Test Bot (@${botName})`, {timeout: TIMEOUTS.ONE_MIN}).scrollIntoView().then((el) => { // # Click the enable button cy.wrap(el[0].parentElement.parentElement).find('button:nth-child(1)').should('be.visible').click(); - - // * Check that the bot is in the 'enabled' section - cy.get('.bot-list__disabled').siblings(':not([class])').scrollIntoView().findByText(`Test Bot (@${botName})`).scrollIntoView().should('be.visible'); }); + + // * Check that the bot is in the 'enabled' section + cy.findByText(`Test Bot (@${botName})`).scrollIntoView().should('be.visible'); + cy.get('.bot-list__disabled').should('not.be.visible'); }); it('MM-T1858 Search active and disabled Bot accounts', () => { @@ -299,8 +297,7 @@ describe('Managing bot accounts', () => { cy.get('#searchInput', {timeout: TIMEOUTS.ONE_MIN}).type('Bot That Stays Enabled'); // * Validate that the plugin is disabled since it's owner is deactivate - cy.get('.bot-list__disabled').scrollIntoView().should('be.visible'); - cy.get('.bot-list__disabled').findByText(`Bot That Stays Enabled (@${botName3})`).scrollIntoView().should('be.visible'); + cy.get('.bot-list__disabled').scrollIntoView().findByText(`Bot That Stays Enabled (@${botName3})`).scrollIntoView().should('be.visible'); cy.visit(`/${newTeam.name}/messages/@sysadmin`); From 74fcd971ca6d8984e71e2a63e4e3a3442b8ebb8b Mon Sep 17 00:00:00 2001 From: Joseph Baylon Date: Fri, 23 Oct 2020 06:46:47 -0700 Subject: [PATCH 2/5] Remove extra cy.apiAdminLogin --- .../integration/bot_accounts/managing_bot_accounts_spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js index 75892dd68c23..31021938814d 100644 --- a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js +++ b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js @@ -143,9 +143,6 @@ describe('Managing bot accounts', () => { // * Verify appropriate error message is displayed for bot login cy.findByText('Bot login is forbidden.').should('exist').and('be.visible'); - - // # Re-login admin - cy.apiAdminLogin(); }); it('MM-T1856 Disable Bot', () => { From f80dcb94d63573efed3afeb64cef0885b39eb478 Mon Sep 17 00:00:00 2001 From: Joseph Baylon Date: Fri, 23 Oct 2020 06:51:08 -0700 Subject: [PATCH 3/5] Moved cy.apiAdminLogin to top of beforeEach --- .../integration/bot_accounts/managing_bot_accounts_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js index 31021938814d..7901ea3cd143 100644 --- a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js +++ b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js @@ -18,6 +18,7 @@ describe('Managing bot accounts', () => { let botName; beforeEach(() => { + cy.apiAdminLogin(); botName = 'bot-' + Date.now(); // # Set ServiceSettings to expected values @@ -40,7 +41,6 @@ describe('Managing bot accounts', () => { cy.apiInitSetup().then(({team}) => { newTeam = team; }); - cy.apiAdminLogin(); }); it('MM-T1851 No option to create BOT accounts when Enable Bot Account Creation is set to False.', () => { From 89187a303a145724b2c209460d815e86dbf59b7b Mon Sep 17 00:00:00 2001 From: Joseph Baylon Date: Fri, 23 Oct 2020 07:12:49 -0700 Subject: [PATCH 4/5] Moved bot cannot login case to enterprise --- .../managing_bot_accounts_spec.js | 19 +------ .../managing_bot_accounts_spec.js | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 e2e/cypress/integration/enterprise/bot_accounts/managing_bot_accounts_spec.js diff --git a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js index 7901ea3cd143..d5b6e0a60799 100644 --- a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js +++ b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js @@ -128,23 +128,6 @@ describe('Managing bot accounts', () => { cy.get('#addBotAccount', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible'); }); - it('MM-T1855 Bot cannot login', () => { - cy.apiLogout(); - cy.visit('/login'); - - // # Enter bot name in the email field - cy.findByPlaceholderText('Email or Username', {timeout: TIMEOUTS.ONE_MIN}).clear().type(botName); - - // # Enter random password in the password field - cy.findByPlaceholderText('Password').clear().type('invalidPassword@#%(^!'); - - // # Hit enter to login - cy.findByText('Sign in').click(); - - // * Verify appropriate error message is displayed for bot login - cy.findByText('Bot login is forbidden.').should('exist').and('be.visible'); - }); - it('MM-T1856 Disable Bot', () => { // # Visit the integrations cy.visit(`/${newTeam.name}/integrations/bots`); @@ -250,7 +233,7 @@ describe('Managing bot accounts', () => { cy.visit(`/${newTeam.name}/integrations/bots`); // # Search for the other bot - cy.get('#searchInput', {timeout: TIMEOUTS.ONE_MIN}).type('Bot That Stays Enabled'); + cy.get('#searchInput', {timeout: TIMEOUTS.ONE_MIN}).type(`Bot That Stays Enabled (@${botName3})`); // * Validate that the plugin is still active, even though it's owner is disabled cy.get('.bot-list__disabled').should('not.be.visible'); diff --git a/e2e/cypress/integration/enterprise/bot_accounts/managing_bot_accounts_spec.js b/e2e/cypress/integration/enterprise/bot_accounts/managing_bot_accounts_spec.js new file mode 100644 index 000000000000..c5d6ebfea308 --- /dev/null +++ b/e2e/cypress/integration/enterprise/bot_accounts/managing_bot_accounts_spec.js @@ -0,0 +1,56 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +// *************************************************************** +// - [#] indicates a test step (e.g. # Go to a page) +// - [*] indicates an assertion (e.g. * Check the title) +// - Use element ID when selecting an element. Create one if none. +// *************************************************************** + +// Group: @enterprise @bot_accounts + +import * as TIMEOUTS from '../../../fixtures/timeouts'; + +describe('Managing bot accounts', () => { + let botName; + + beforeEach(() => { + cy.apiRequireLicenseForFeature('LDAP'); + + cy.apiAdminLogin(); + botName = 'bot-' + Date.now(); + + // # Set ServiceSettings to expected values + const newSettings = { + ServiceSettings: { + EnableBotAccountCreation: true, + DisableBotsWhenOwnerIsDeactivated: true, + }, + PluginSettings: { + Enable: true, + RequirePluginSignature: false, + }, + }; + cy.apiUpdateConfig(newSettings); + + // # Create a test bot + cy.apiCreateBot(botName, 'Test Bot', 'test bot'); + }); + + it('MM-T1855 Bot cannot login', () => { + cy.apiLogout(); + cy.visit('/login'); + + // # Enter bot name in the email field + cy.findByPlaceholderText('Email, Username or AD/LDAP Username', {timeout: TIMEOUTS.ONE_MIN}).clear().type(botName); + + // # Enter random password in the password field + cy.findByPlaceholderText('Password').clear().type('invalidPassword@#%(^!'); + + // # Hit enter to login + cy.findByText('Sign in').click(); + + // * Verify appropriate error message is displayed for bot login + cy.findByText('Bot login is forbidden.').should('exist').and('be.visible'); + }); +}); From f965c7c859ad6bbb8aaa32031ed0d0f172b112d6 Mon Sep 17 00:00:00 2001 From: Joseph Baylon Date: Fri, 23 Oct 2020 07:19:19 -0700 Subject: [PATCH 5/5] Moved function to bottom --- .../managing_bot_accounts_spec.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js index d5b6e0a60799..1537f7143705 100644 --- a/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js +++ b/e2e/cypress/integration/bot_accounts/managing_bot_accounts_spec.js @@ -195,15 +195,6 @@ describe('Managing bot accounts', () => { cy.get('.bot-list__disabled').should('not.be.visible'); }); - function createCustomAdmin() { - const sysadminUser = generateRandomUser('other-admin'); - - return cy.apiCreateUser({user: sysadminUser}).then(({user}) => { - return cy.apiPatchUserRoles(user.id, ['system_admin', 'system_user']).then(() => { - return cy.wrap({sysadmin: user}); - }); - }); - } it('MM-T1859 Bot is kept active when owner is disabled', () => { // # Visit bot config cy.visit('/admin_console/integrations/bot_accounts'); @@ -233,7 +224,7 @@ describe('Managing bot accounts', () => { cy.visit(`/${newTeam.name}/integrations/bots`); // # Search for the other bot - cy.get('#searchInput', {timeout: TIMEOUTS.ONE_MIN}).type(`Bot That Stays Enabled (@${botName3})`); + cy.get('#searchInput', {timeout: TIMEOUTS.ONE_MIN}).type('Bot That Stays Enabled'); // * Validate that the plugin is still active, even though it's owner is disabled cy.get('.bot-list__disabled').should('not.be.visible'); @@ -294,3 +285,13 @@ describe('Managing bot accounts', () => { }); }); }); + +function createCustomAdmin() { + const sysadminUser = generateRandomUser('other-admin'); + + return cy.apiCreateUser({user: sysadminUser}).then(({user}) => { + return cy.apiPatchUserRoles(user.id, ['system_admin', 'system_user']).then(() => { + return cy.wrap({sysadmin: user}); + }); + }); +}