supertest icon indicating copy to clipboard operation
supertest copied to clipboard

Set Authorization header to get request

Open AndonMitev opened this issue 4 years ago • 5 comments

Versions: "supertest": "6.0.1",

Code example:

 it('should fail getting all users, reason role = user', async () => {
    const authHeaders = {Authorization: 'test'}    

    await request(app)
            .get('/user/all')
            .set(authHeaders)
            .expect(({ headers }) => {
                console.log(headers);
            })
            .expect(HttpStatus.NOT_FOUND);
    });

Actual behavior: header is missing.

Expected Behavior: authheader to be part of the headers body

AndonMitev avatar Dec 17 '20 11:12 AndonMitev

Reproducible on Node v14.15.2

Is not reproducible on v12.20.0

maksym-hryshkov-gl avatar Dec 17 '20 14:12 maksym-hryshkov-gl

Versions: "supertest": "6.0.1",

Code example:

 it('should fail getting all users, reason role = user', async () => {
    const authHeaders = {Authorization: 'test'}    

    await request(app)
            .get('/user/all')
            .set(authHeaders)
            .expect(({ headers }) => {
                console.log(headers);
            })
            .expect(HttpStatus.NOT_FOUND);
    });

Actual behavior: header is missing.

Expected Behavior: authheader to be part of the headers body

See https://github.com/visionmedia/supertest/issues/693#issuecomment-785052983

Dezzpil avatar Feb 24 '21 12:02 Dezzpil

same for me, I cant attach any header

DarthRevanXX avatar Jun 27 '22 09:06 DarthRevanXX

Versions: "supertest": "6.0.1",

Code example:

 it('should fail getting all users, reason role = user', async () => {
    const authHeaders = {Authorization: 'test'}    

    await request(app)
            .get('/user/all')
            .set(authHeaders)
            .expect(({ headers }) => {
                console.log(headers);
            })
            .expect(HttpStatus.NOT_FOUND);
    });

Actual behavior: header is missing.

Expected Behavior: authheader to be part of the headers body

did you find a solution?

DarthRevanXX avatar Jun 27 '22 09:06 DarthRevanXX