-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix input fields not disabled correctly on login page and improve tes…
…ts (#1794) * Fix input fields not disabled correctly on login page * Improve frontend tests for login page * Update changelog
- Loading branch information
Showing
4 changed files
with
214 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,19 @@ describe("Login", function () { | |
|
||
// Check if ldap login tab is shown correctly and click on login button | ||
cy.get('[data-test="login-tab-ldap"]').within(() => { | ||
cy.get("#ldap-username").type("user"); | ||
cy.get("#ldap-password").type("password"); | ||
cy.get('[data-test="username-field"]') | ||
.should("be.visible") | ||
.and("include.text", "auth.ldap.username") | ||
.within(() => { | ||
cy.get("#ldap-username").should("have.value", "").type("user"); | ||
}); | ||
|
||
cy.get('[data-test="password-field"]') | ||
.should("be.visible") | ||
.and("include.text", "auth.password") | ||
.within(() => { | ||
cy.get("#ldap-password").should("have.value", "").type("password"); | ||
}); | ||
|
||
// Intercept requests that will be needed to show the room index page (needed to check redirect) | ||
cy.intercept("GET", "api/v1/currentUser", { | ||
|
@@ -47,6 +58,10 @@ describe("Login", function () { | |
cy.interceptRoomIndexRequests(); | ||
|
||
cy.get("button").should("have.text", "auth.login").click(); | ||
// Check loading | ||
cy.get("#ldap-username").should("be.disabled"); | ||
cy.get("#ldap-password").should("be.disabled"); | ||
|
||
// Check if button is disabled after being clicked and loading and send response | ||
cy.get("button") | ||
.should("be.disabled") | ||
|
@@ -108,7 +123,7 @@ describe("Login", function () { | |
}).as("loginRequest"); | ||
|
||
// Visit page that can only be visited by logged in users | ||
cy.visit("admin"); | ||
cy.visit("/admin"); | ||
|
||
// Check redirect to the login page | ||
cy.url().should("include", "/login?redirect=/admin"); | ||
|
@@ -169,10 +184,23 @@ describe("Login", function () { | |
|
||
cy.visit("/login"); | ||
|
||
// Check if ldap login tab is shown correctly and click on login button | ||
// Check if local login tab is shown correctly and click on login button | ||
cy.get('[data-test="login-tab-local"]').within(() => { | ||
cy.get("#local-email").type("[email protected]"); | ||
cy.get("#local-password").type("password"); | ||
cy.get('[data-test="email-field"]') | ||
.should("be.visible") | ||
.and("include.text", "app.email") | ||
.within(() => { | ||
cy.get("#local-email") | ||
.should("have.value", "") | ||
.type("[email protected]"); | ||
}); | ||
|
||
cy.get('[data-test="password-field"]') | ||
.should("be.visible") | ||
.and("include.text", "auth.password") | ||
.within(() => { | ||
cy.get("#local-password").should("have.value", "").type("password"); | ||
}); | ||
|
||
// Intercept requests that will be needed to show the room index page (needed to check redirect) | ||
cy.intercept("GET", "api/v1/currentUser", { | ||
|
@@ -183,6 +211,11 @@ describe("Login", function () { | |
cy.get('[data-test="login-button"]') | ||
.should("have.text", "auth.login") | ||
.click(); | ||
|
||
// Check loading | ||
cy.get("#local-email").should("be.disabled"); | ||
cy.get("#local-password").should("be.disabled"); | ||
|
||
// Check if button is disabled after being clicked and loading and send response | ||
cy.get('[data-test="login-button"]') | ||
.should("be.disabled") | ||
|
@@ -243,7 +276,7 @@ describe("Login", function () { | |
}).as("loginRequest"); | ||
|
||
// Visit page that can only be visited by logged in users | ||
cy.visit("admin"); | ||
cy.visit("/admin"); | ||
|
||
// Check redirect to the login page | ||
cy.url().should("include", "/login?redirect=/admin"); | ||
|
@@ -271,7 +304,7 @@ describe("Login", function () { | |
cy.url().should("include", "/admin").and("not.include", "/login"); | ||
}); | ||
|
||
it("login errors", function () { | ||
it("local login errors", function () { | ||
// Intercept config request to only show local login tab | ||
cy.fixture("config.json").then((config) => { | ||
config.data.auth.local = true; | ||
|
@@ -303,7 +336,35 @@ describe("Login", function () { | |
cy.wait("@loginRequest"); | ||
|
||
// Check if error gets displayed | ||
cy.contains("Password or Email wrong!").should("be.visible"); | ||
cy.get('[data-test="email-field"]') | ||
.should("be.visible") | ||
.and("include.text", "Password or Email wrong!"); | ||
|
||
// Check with different 422 error | ||
cy.intercept("POST", "api/v1/login/local", { | ||
statusCode: 422, | ||
body: { | ||
errors: { | ||
password: ["The Password field is required."], | ||
}, | ||
}, | ||
}).as("loginRequest"); | ||
|
||
cy.get('[data-test="login-tab-local"]').within(() => { | ||
cy.get('[data-test="login-button"]').click(); | ||
}); | ||
|
||
cy.wait("@loginRequest"); | ||
|
||
// Check that previous error message is hidden | ||
cy.get('[data-test="email-field"]') | ||
.should("be.visible") | ||
.and("not.include.text", "Password or Email wrong!"); | ||
|
||
// Check if error gets displayed | ||
cy.get('[data-test="password-field"]') | ||
.should("be.visible") | ||
.and("include.text", "The Password field is required."); | ||
|
||
// Error for to many login requests gets displayed | ||
cy.intercept("POST", "api/v1/login/local", { | ||
|
@@ -325,8 +386,9 @@ describe("Login", function () { | |
cy.contains("Too many logins. Please try again later!").should( | ||
"be.visible", | ||
); | ||
// Check that 422 error message is hidden | ||
// Check that 422 error messages are hidden | ||
cy.contains("Password or Email wrong!").should("not.exist"); | ||
cy.contains("The Password field is required.").should("not.exist"); | ||
|
||
// Other api errors | ||
cy.intercept("POST", "api/v1/login/local", { | ||
|
@@ -362,6 +424,135 @@ describe("Login", function () { | |
cy.url().should("not.include", "/login"); | ||
}); | ||
|
||
it("ldap login errors", function () { | ||
// Intercept config request to only show ldap login tab | ||
cy.fixture("config.json").then((config) => { | ||
config.data.auth.ldap = true; | ||
|
||
cy.intercept("GET", "api/v1/config", { | ||
statusCode: 200, | ||
body: config, | ||
}); | ||
}); | ||
// Intercept csrf-cookie request to set defined cookie that can be checked later | ||
cy.intercept("GET", "/sanctum/csrf-cookie", { | ||
statusCode: 200, | ||
headers: { | ||
"Set-Cookie": "XSRF-TOKEN=test-csrf; Path=/", | ||
}, | ||
}).as("cookieRequest"); | ||
|
||
// Unprocessable entity error | ||
cy.intercept("POST", "api/v1/login/ldap", { | ||
statusCode: 422, | ||
body: { | ||
errors: { | ||
username: ["These credentials do not match our records."], | ||
}, | ||
}, | ||
}).as("loginRequest"); | ||
|
||
cy.visit("/login"); | ||
|
||
cy.get('[data-test="login-tab-ldap"]').within(() => { | ||
cy.get("#ldap-username").type("user"); | ||
cy.get("#ldap-password").type("password"); | ||
cy.get('[data-test="login-button"]').click(); | ||
}); | ||
|
||
cy.wait("@loginRequest"); | ||
|
||
// Check if error gets displayed | ||
cy.get('[data-test="username-field"]') | ||
.should("be.visible") | ||
.and("include.text", "These credentials do not match our records."); | ||
|
||
// Check with different error | ||
cy.intercept("POST", "api/v1/login/ldap", { | ||
statusCode: 422, | ||
body: { | ||
errors: { | ||
password: ["The Password field is required."], | ||
}, | ||
}, | ||
}).as("loginRequest"); | ||
|
||
cy.get('[data-test="login-tab-ldap"]').within(() => { | ||
cy.get('[data-test="login-button"]').click(); | ||
}); | ||
|
||
cy.wait("@loginRequest"); | ||
|
||
// Check that previous error message is hidden | ||
cy.get('[data-test="username-field"]') | ||
.should("be.visible") | ||
.and("not.include.text", "These credentials do not match our records."); | ||
|
||
// Check if error gets displayed | ||
cy.get('[data-test="password-field"]') | ||
.should("be.visible") | ||
.and("include.text", "The Password field is required."); | ||
|
||
// Error for to many login requests gets displayed | ||
cy.intercept("POST", "api/v1/login/ldap", { | ||
statusCode: 429, | ||
body: { | ||
errors: { | ||
username: ["Too many logins. Please try again later!"], | ||
}, | ||
}, | ||
}).as("loginRequest"); | ||
|
||
cy.get('[data-test="login-tab-ldap"]').within(() => { | ||
cy.get('[data-test="login-button"]').click(); | ||
}); | ||
|
||
cy.wait("@loginRequest"); | ||
|
||
// Check if error gets displayed | ||
cy.contains("Too many logins. Please try again later!").should( | ||
"be.visible", | ||
); | ||
// Check that 422 error messages are hidden | ||
cy.contains("These credentials do not match our records.").should( | ||
"not.exist", | ||
); | ||
cy.contains("The Password field is required.").should("not.exist"); | ||
|
||
// Other api errors | ||
cy.intercept("POST", "api/v1/login/ldap", { | ||
statusCode: 500, | ||
}).as("loginRequest"); | ||
|
||
cy.get('[data-test="login-tab-ldap"]').within(() => { | ||
cy.get('[data-test="login-button"]').click(); | ||
}); | ||
|
||
cy.wait("@loginRequest"); | ||
|
||
// Check that other error messages are hidden | ||
cy.contains("Too many logins. Please try again later!").should("not.exist"); | ||
|
||
// Check that error message is shown | ||
cy.checkToastMessage([ | ||
"app.flash.server_error.empty_message", | ||
'app.flash.server_error.error_code_{"statusCode":500}', | ||
]); | ||
|
||
// Intercept login request with different error | ||
cy.intercept("POST", "api/v1/login/ldap", { | ||
statusCode: 420, | ||
}).as("loginRequest"); | ||
|
||
cy.get('[data-test="login-tab-ldap"]').within(() => { | ||
cy.get('[data-test="login-button"]').click(); | ||
}); | ||
cy.wait("@loginRequest"); | ||
|
||
cy.checkToastMessage("app.flash.guests_only"); | ||
cy.url().should("not.include", "/login"); | ||
}); | ||
|
||
it("visit login page with already logged in user", function () { | ||
cy.intercept("GET", "api/v1/currentUser", { fixture: "currentUser.json" }); | ||
cy.interceptRoomIndexRequests(); | ||
|
@@ -429,7 +620,7 @@ describe("Login", function () { | |
}); | ||
|
||
// Visit page that can only be visited by logged in users | ||
cy.visit("admin"); | ||
cy.visit("/admin"); | ||
|
||
// Check redirect to the login page | ||
cy.url().should("include", "/login?redirect=/admin"); | ||
|