diff --git a/app/client/cypress/integration/Smoke_TestSuite_Fat/ClientSideTests/FormLogin/EnableFormLogin_spec.js b/app/client/cypress/integration/Smoke_TestSuite_Fat/ClientSideTests/FormLogin/EnableFormLogin_spec.js new file mode 100644 index 0000000000..fb4197c382 --- /dev/null +++ b/app/client/cypress/integration/Smoke_TestSuite_Fat/ClientSideTests/FormLogin/EnableFormLogin_spec.js @@ -0,0 +1,154 @@ +const adminSettings = require("../../../../locators/AdminsSettings"); +const commonlocators = require("../../../../locators/commonlocators.json"); +import homePage from "../../../../locators/HomePage"; + +describe("Form Login test functionality", function() { + it("1. Go to admin settings and disable Form Signup", function() { + cy.LogOut(); + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.openAuthentication(); + cy.get(adminSettings.formloginButton) + .should("be.visible") + .should("contain", "EDIT"); + cy.get(adminSettings.formloginButton).click(); + cy.wait(2000); + // disable form signup + cy.get(adminSettings.formSignupDisabled) + .get("input") + .should("have.value", "true"); + cy.get(adminSettings.formSignupDisabled).click({ force: true }); + cy.wait(2000); + // assert server is restarting + cy.get(adminSettings.saveButton).should("be.visible"); + cy.get(adminSettings.saveButton).should("not.be.disabled"); + cy.get(adminSettings.saveButton).click(); + cy.get(adminSettings.restartNotice).should("be.visible"); + // adding wait for server to restart + cy.wait(120000); + cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible")); + cy.get(homePage.profileMenu).click(); + cy.get(homePage.signOutIcon).click(); + cy.wait(500); + // validating form signup is disabled + cy.get(".t--sign-up").click({ force: true }); + cy.generateUUID().then((uid) => { + cy.get("[type='email']").type(uid + "@appsmith.com"); + cy.get("[type='password']").type(uid); + cy.get("[type='submit']").click({ force: true }); + cy.get(".form-message-container").should( + "contain", + "Signup is restricted on this instance of Appsmith", + ); + // restore setting + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.get(".t--profile-menu-icon").click(); + cy.get(".t--admin-settings-menu").click(); + cy.get(adminSettings.authenticationTab).click(); + cy.get(adminSettings.formloginButton).click(); + cy.wait(2000); + cy.get(adminSettings.formSignupDisabled).click({ force: true }); + cy.wait(2000); + cy.get(adminSettings.saveButton).click(); + cy.get(adminSettings.restartNotice).should("be.visible"); + cy.wait(120000); + cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible")); + cy.get(homePage.profileMenu).click(); + cy.get(homePage.signOutIcon).click(); + }); + cy.wait(500); + // validating form signup is disabled + cy.get(".t--sign-up").click({ force: true }); + cy.generateUUID().then((uid) => { + cy.get("[type='email']").type(uid + "@appsmith.com"); + cy.get("[type='password']").type(uid); + cy.get("[type='submit']").click({ force: true }); + cy.get(".form-message-container").should("not.exist"); + }); + }); + + it("2. Go to admin settings and disable Form Login", function() { + cy.LogOut(); + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.openAuthentication(); + cy.get(adminSettings.formloginButton) + .should("be.visible") + .should("contain", "EDIT"); + + // enable github login + cy.get(adminSettings.githubButton).click(); + cy.wait(2000); + // fill github form + cy.fillGithubForm(); + cy.wait(120000); + cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible")); + cy.wait(5000); + cy.reload(); + cy.get(adminSettings.authenticationTab).click(); + cy.get(adminSettings.formloginButton).click(); + cy.wait(2000); + // disable form signup + cy.get(adminSettings.formLoginDisabled) + .get("input") + .should("have.value", "true"); + cy.get(adminSettings.formLoginDisabled).click({ force: true }); + cy.wait(2000); + // assert server is restarting + cy.get(adminSettings.saveButton).should("be.visible"); + cy.get(adminSettings.saveButton).should("not.be.disabled"); + cy.get(adminSettings.saveButton).click(); + cy.get(adminSettings.restartNotice).should("be.visible"); + // adding wait for server to restart + cy.wait(120000); + cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible")); + cy.get(homePage.profileMenu).click(); + cy.get(homePage.signOutIcon).click(); + cy.wait(500); + cy.reload(); + cy.wait(5000); + // validating form signup is disabled + cy.get("form").should("not.exist"); + cy.get(".t--sign-up").should("not.exist"); + // cy.wait(30000); // restart nginx docker + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.openAuthentication(); + + // enable form login + cy.get(adminSettings.formloginButton) + .should("be.visible") + .should("contain", "ENABLE"); + cy.get(adminSettings.formloginButton).click(); + cy.get(adminSettings.formLoginDisabled).click({ force: true }); + cy.wait(2000); + // assert server is restarting + cy.get(adminSettings.saveButton).should("be.visible"); + cy.get(adminSettings.saveButton).should("not.be.disabled"); + cy.get(adminSettings.saveButton).click(); + cy.get(adminSettings.restartNotice).should("be.visible"); + // adding wait for server to restart + cy.wait(120000); + cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible")); + cy.reload(); + + // disable github + cy.get(adminSettings.authenticationTab).click(); + cy.get(adminSettings.githubButton).click(); + cy.wait(2000); + cy.get(adminSettings.disconnectBtn) + .click() + .should("contain", "Are you sure?"); + cy.get(adminSettings.disconnectBtn).click(); + cy.wait(120000); + cy.waitUntil(() => cy.get(homePage.profileMenu).should("be.visible")); + cy.reload(); + cy.get(homePage.profileMenu).click(); + cy.get(homePage.signOutIcon).click(); + cy.wait(500); + cy.get(adminSettings.loginWithGithub).should("not.exist"); + cy.get("form").should("exist"); + cy.get(".t--sign-up").should("exist"); + }); +}); diff --git a/app/client/cypress/locators/AdminsSettings.js b/app/client/cypress/locators/AdminsSettings.js index 23f2acf0ae..ebfc82bd16 100644 --- a/app/client/cypress/locators/AdminsSettings.js +++ b/app/client/cypress/locators/AdminsSettings.js @@ -23,4 +23,6 @@ export default { loginWithGoogle: "[data-testid='login-with-Google']", loginWithGithub: "[data-testid='login-with-Github']", disconnectBtn: "[data-testid='disconnect-service-button']", + formSignupDisabled: "[data-cy='APPSMITH_SIGNUP_DISABLED']", + formLoginDisabled: "[data-cy='APPSMITH_FORM_LOGIN_DISABLED']", }; diff --git a/app/client/cypress/support/AdminSettingsCommands.js b/app/client/cypress/support/AdminSettingsCommands.js index a32f6d094d..ab91d2b50b 100644 --- a/app/client/cypress/support/AdminSettingsCommands.js +++ b/app/client/cypress/support/AdminSettingsCommands.js @@ -7,6 +7,7 @@ require("cypress-file-upload"); const googleForm = require("../locators/GoogleForm.json"); const googleData = require("../fixtures/googleSource.json"); const githubForm = require("../locators/GithubForm.json"); +const adminSettings = require("../locators/AdminsSettings"); Cypress.Commands.add("fillGoogleFormPartly", () => { cy.get(googleForm.googleClientId).type( @@ -43,3 +44,15 @@ Cypress.Commands.add("fillGithubForm", () => { ); cy.get(githubForm.saveBtn).click({ force: true }); }); + +// open authentication page +Cypress.Commands.add("openAuthentication", () => { + cy.get(".t--profile-menu-icon").should("be.visible"); + cy.get(".t--profile-menu-icon").click(); + cy.get(".t--admin-settings-menu").should("be.visible"); + cy.get(".t--admin-settings-menu").click(); + cy.url().should("contain", "/settings/general"); + // click authentication tab + cy.get(adminSettings.authenticationTab).click(); + cy.url().should("contain", "/settings/authentication"); +}); diff --git a/app/client/src/pages/Settings/FormGroup/Toggle.tsx b/app/client/src/pages/Settings/FormGroup/Toggle.tsx index c3de4b6da9..c5714f48d6 100644 --- a/app/client/src/pages/Settings/FormGroup/Toggle.tsx +++ b/app/client/src/pages/Settings/FormGroup/Toggle.tsx @@ -19,7 +19,10 @@ const ToggleStatus = styled.span` margin-left: 64px; `; -function FieldToggleWithToggleText(toggleText?: (value: boolean) => string) { +function FieldToggleWithToggleText( + toggleText?: (value: boolean) => string, + id?: string, +) { return function FieldToggle( componentProps: FormTextFieldProps & { meta: Partial; @@ -35,7 +38,11 @@ function FieldToggleWithToggleText(toggleText?: (value: boolean) => string) { */ return ( - + {typeof toggleText == "function" ? createMessage(() => toggleText(!componentProps.input.value)) @@ -57,7 +64,7 @@ export function ToggleComponent({ setting }: SettingComponentProps) {