Expected "Location" header field
- Dominant language
- JavaScript
- Stars
- 442
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
I am at 10-authentication, trying to get past the test that says "POST /login should 303 with good auth details"
```
/**
* If successful, the logged in user should be redirected to `/`.
*/
app.use(function* login(next) {
if (this.request.path !== '/login') return yield* next;
if (this.request.method === 'GET') return this.response.body = form.replace('{{csrf}}', this.csrf);
if (this.request.method === 'POST') {
var body = yield parse.json(this);
if (body.username !== 'username' || body.password !== 'password') {
return this.response.status = 400;
}
if (body._csrf !== this.csrf) {
return this.response.status = 403;
}
if (body.username === 'username' && body.password === 'password' && body._csrf === this.csrf) {
this.response.status = 303;
this.response.set('Location', '/');
}
}
})
```
here is the test result
```
1) Authentication logging in POST /login should 303 with good auth details:
Error: expected "Location" header field
at Test.assert (/Users/christiansakai/Desktop/workshop/node_modules/supertest/lib/test.js:190:35)
at assert (/Users/christiansakai/Desktop/workshop/node_modules/supertest/lib/test.js:132:12)
at /Users/christiansakai/Desktop/workshop/node_modules/supertest/lib/test.js:129:5
at Test.Request.callback (/Users/christiansakai/Desktop/workshop/node_modules/supertest/node_modules/superagent/lib/node/index.js:746:30)
at Test. (/Users/christiansakai/Desktop/workshop/node_modules/supertest/node_modules/superagent/lib/node/index.js:135:10)
at IncomingMessage. (/Users/christiansakai/Desktop/workshop/node_modules/supertest/node_modules/superagent/lib/node/index.js:938:12)
at endReadableNT (_stream_readable.js:893:12)
```
Can you point me in the right direction?
Contributor guide
Research direction
Start in the 10-authentication lesson and inspect the test for POST /login with valid credentials, then compare its expected response with the login middleware shown here. Done means the authentication test receives a 303 response with the expected Location header.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100