test: handle login success & errors properly (#22524)
Fixes #22537 - [x] check for test failures in CE & EE - [ ] check for merge conflicts in EE (index.js) ## Description cy command : `LoginFromAPI` We were calling the login API as a XHR call and navigated to `/applications` manually in cases where login has actually failed. Login success & errors are now handled properly. - Now it will behave like submitting a form. (https://docs.cypress.io/api/commands/visit#Submit-a-form) - Performs navigation to `/applications` automatically on login success. - Performs navigation to `/login?error=true` automatically on login failure. - Added origin as a header. ## Media Before: (navigates to /application even when login fails) https://www.loom.com/share/086ef8c743ab460194b785a4d22e87cf Now: (stops when login fails) https://www.loom.com/share/cc78be2ee2944d0ab9f094f8fd709539 ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag
This commit is contained in:
parent
8345937dff
commit
9af64f7310
|
|
@ -18,7 +18,6 @@ describe("Admin settings page", function () {
|
|||
it("1. Should test that settings page is accessible to super user", () => {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
@ -29,7 +28,6 @@ describe("Admin settings page", function () {
|
|||
it("2. Should test that settings page is not accessible to normal users", () => {
|
||||
cy.wait(2000);
|
||||
cy.LoginFromAPI(Cypress.env("TESTUSERNAME1"), Cypress.env("TESTPASSWORD1"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("not.exist");
|
||||
cy.visit("/settings/general");
|
||||
// non super users are redirected to home page
|
||||
|
|
@ -39,7 +37,6 @@ describe("Admin settings page", function () {
|
|||
|
||||
it("3. Should test that settings page is redirected to default tab", () => {
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.wait(3000);
|
||||
cy.visit("/settings");
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ describe("Audit logs", () => {
|
|||
if (CURRENT_REPO === REPO.CE) {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(locators.AdminSettingsEntryLink).should("be.visible");
|
||||
cy.get(locators.AdminSettingsEntryLink).click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ describe("Branding", () => {
|
|||
it("1. Super user can access branding page", () => {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(locators.AdminSettingsEntryLink).should("be.visible");
|
||||
cy.get(locators.AdminSettingsEntryLink).click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ describe("Admin settings page", function () {
|
|||
it("should test that settings page is accessible to super user", () => {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit(routes.APPLICATIONS);
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", routes.GENERAL);
|
||||
|
|
@ -44,7 +43,6 @@ describe("Admin settings page", function () {
|
|||
it("should test that settings page is not accessible to normal users", () => {
|
||||
cy.wait(2000);
|
||||
cy.LoginFromAPI(Cypress.env("TESTUSERNAME1"), Cypress.env("TESTPASSWORD1"));
|
||||
cy.visit(routes.APPLICATIONS);
|
||||
cy.get(".admin-settings-menu-option").should("not.exist");
|
||||
cy.visit(routes.GENERAL);
|
||||
// non super users are redirected to home page
|
||||
|
|
@ -71,7 +69,6 @@ describe("Admin settings page", function () {
|
|||
|
||||
it("should test that settings page is redirected to default tab", () => {
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit(routes.APPLICATIONS);
|
||||
cy.wait(3000);
|
||||
cy.visit(routes.SETTINGS);
|
||||
cy.url().should("contain", routes.GENERAL);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ describe("SSO with Github test functionality", function () {
|
|||
it("1. Go to admin settings and enable Github with not all mandatory fields filled", function () {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
@ -30,7 +29,6 @@ describe("SSO with Github test functionality", function () {
|
|||
it("2. Go to admin settings and enable Github", function () {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
@ -63,7 +61,6 @@ describe("SSO with Github test functionality", function () {
|
|||
it("3. Go to admin settings and disable Github", function () {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ describe("SSO with Google test functionality", function () {
|
|||
it("1. Go to admin settings and enable Google with not all mandatory fields filled", function () {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
@ -30,7 +29,6 @@ describe("SSO with Google test functionality", function () {
|
|||
it("2. Go to admin settings and enable Google", function () {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
@ -63,7 +61,6 @@ describe("SSO with Google test functionality", function () {
|
|||
it("3. Go to admin settings and disable Google", function () {
|
||||
cy.LogOut();
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").should("be.visible");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ describe("Create app same name in different workspace", function () {
|
|||
});
|
||||
it("1. create app with same name in a different workspace", function () {
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.wait("@applications").should(
|
||||
"have.nested.property",
|
||||
"response.body.responseMeta.status",
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ describe("Create new workspace and share with a user", function () {
|
|||
|
||||
it("3. Enable public access to Application", function () {
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.wait("@applications").should(
|
||||
"have.nested.property",
|
||||
"response.body.responseMeta.status",
|
||||
|
|
@ -118,7 +117,6 @@ describe("Create new workspace and share with a user", function () {
|
|||
|
||||
it("login as Owner and disable public access", function () {
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.wait("@applications").should(
|
||||
"have.nested.property",
|
||||
"response.body.responseMeta.status",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ describe("Admin settings page", function () {
|
|||
|
||||
it("1. should test that settings page is redirected to default tab", () => {
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.wait(3000);
|
||||
cy.visit("/settings");
|
||||
cy.url().should("contain", "/settings/general");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ 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")
|
||||
|
|
@ -41,7 +40,6 @@ describe("Form Login test functionality", function () {
|
|||
);
|
||||
// restore setting
|
||||
cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD"));
|
||||
cy.visit("/applications");
|
||||
cy.get(".admin-settings-menu-option").click();
|
||||
cy.get(adminSettings.authenticationTab).click();
|
||||
cy.get(adminSettings.formloginButton).click();
|
||||
|
|
@ -69,7 +67,6 @@ describe("Form Login test functionality", function () {
|
|||
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")
|
||||
|
|
@ -111,7 +108,6 @@ describe("Form Login test functionality", function () {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -268,21 +268,23 @@ Cypress.Commands.add("Signup", (uname, pword) => {
|
|||
});
|
||||
|
||||
Cypress.Commands.add("LoginFromAPI", (uname, pword) => {
|
||||
cy.request({
|
||||
method: "POST",
|
||||
url: "api/v1/login",
|
||||
headers: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
followRedirect: false,
|
||||
form: true,
|
||||
body: {
|
||||
username: uname,
|
||||
password: pword,
|
||||
},
|
||||
}).then((response) => {
|
||||
expect(response.status).equal(302);
|
||||
//cy.log(response.body);
|
||||
cy.location().then((loc) => {
|
||||
cy.visit({
|
||||
method: "POST",
|
||||
url: "api/v1/login",
|
||||
headers: {
|
||||
origin: loc.origin,
|
||||
},
|
||||
followRedirect: true,
|
||||
body: {
|
||||
username: uname,
|
||||
password: pword,
|
||||
},
|
||||
})
|
||||
.then(() => cy.location())
|
||||
.then((loc) => {
|
||||
expect(loc.href).to.equal(loc.origin + "/applications");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@ before(function () {
|
|||
const username = Cypress.env("USERNAME");
|
||||
const password = Cypress.env("PASSWORD");
|
||||
cy.LoginFromAPI(username, password);
|
||||
cy.visit("/applications");
|
||||
cy.wait("@getMe");
|
||||
cy.wait(3000);
|
||||
cy.get(".t--applications-container .createnew")
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user