0
0
Expressframework~5 mins

Testing authentication flows in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main goal of testing authentication flows in an Express app?
To ensure that users can securely log in, access protected routes only when authenticated, and that invalid credentials are handled properly.
Click to reveal answer
beginner
Which HTTP status code usually indicates a successful login in an authentication flow?
Status code 200 means success, but often 302 is used for redirect after login. For APIs, 200 with a token is common.
Click to reveal answer
intermediate
Why do we test protected routes with and without authentication tokens?
To verify that protected routes deny access without valid tokens and allow access when tokens are valid, ensuring security.
Click to reveal answer
beginner
What tool can you use to simulate HTTP requests when testing Express authentication flows?
Supertest is a popular tool to simulate HTTP requests and test Express routes including authentication.
Click to reveal answer
beginner
How can you test that an Express app correctly handles invalid login credentials?
By sending a login request with wrong username or password and checking the response status and error message.
Click to reveal answer
What should happen when a user tries to access a protected route without a valid token?
AThe server should respond with a 401 Unauthorized status.
BThe server should allow access.
CThe server should crash.
DThe server should redirect to a public page.
Which library is commonly used to test HTTP requests in Express apps?
AReact Testing Library
BSupertest
CJest DOM
DMocha UI
What is a common way to test login success in an API authentication flow?
ACheck for a 404 status code.
BCheck if the server logs an error.
CCheck if the page reloads.
DCheck for a token in the response body.
Why is it important to test both valid and invalid login attempts?
ATo verify the app handles all cases securely and correctly.
BTo ensure the app crashes gracefully.
CTo speed up the login process.
DTo make the UI look better.
What status code usually indicates that login credentials are incorrect?
A200 OK
B500 Internal Server Error
C401 Unauthorized
D302 Found
Explain how you would write a test to verify that a protected route in Express denies access without a token.
Think about what happens when someone tries to enter a locked door without a key.
You got /4 concepts.
    Describe the steps to test a login endpoint for both successful and failed login attempts.
    Imagine testing a door lock with the right and wrong keys.
    You got /4 concepts.