[Question] How to act as logged user in tests?
See original GitHub issueDescribe your question
I’m using sessionAttribute
and AccessManager
for authentication / authorization. I do like writing acceptance tests on REST API level. Question: Is there any common pattern to act as a logged user in tests?
Currently, I added an optional endpoint (added only in tests) like:
if (testMode) {
app.post("/test-login", ctx -> {
ctx.sessionAttribute(PRINCIPAL_SESSION_KEY, ctx.bodyAsClass(Principal.class));
});
}
// ..
public record Principal(UUID userId, String username, Set<Role> roles) implements Serializable {
}
and then in tests I’m using this endpoint before tested endpoint, but that’s quite verbose (?)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to Write Test Cases For a Login Page (Sample Scenarios)
1, Verify if a user will be able to login with a valid username and valid password. Positive ; 2, Verify if a...
Read more >How to test the current logged in user in test class?
and then go into your IDE or Developer Console and ask to run the test, you would be the running user. UserInfo.
Read more >How do i get logged in user in another test case in laravel ...
I dont want to create user in testLoginFalse function, because user already in database and it's logged in by testLoginTrue function. – Hardik ......
Read more >Laravel unit testing issue with logged user - Laracasts
I need to test the login form and the users menu. Unfortunately the be() method does not logged me in. Here is my...
Read more >Interview Questions: How to Test a Login Form- 110 Test Cases
Test Cases · 1. Login with correct email and password, remember me = NO · 2. Login with correct username and password, remember...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another way is to perform a check against an environment variable, or check for localhost, inside the
AccessManager
:A tutorial would be cool !