Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST Helper doesn't respect resetHeaders setting #784

Closed
alexashley opened this issue Nov 18, 2017 · 2 comments
Closed

REST Helper doesn't respect resetHeaders setting #784

alexashley opened this issue Nov 18, 2017 · 2 comments

Comments

@alexashley
Copy link
Contributor

alexashley commented Nov 18, 2017

What are you trying to achieve?

I was trying to write some tests around endpoint authentication and I noticed that using I.haveRequestHeaders caused subsequent scenarios to include those headers when making get requests.

What do you get instead?

I see that later tests inherit headers from earlier tests even when resetHeaders is true.

Provide console output if related. Use --verbose mode for more details.

$ codeceptjs run --steps
CodeceptJS v1.0.3
Using test root "/home/alex/workspace/codecept-headers"

Repro test --
 with headers
 • I have request headers {"Authorization":"Bearer validToken"}
 • I send get request "/ping"
request headers  { Authorization: 'Bearer validToken', 'content-length': 0 }
 ✓ OK in 28ms

 without headers
 • I send get request "/ping"
request headers  { Authorization: 'Bearer validToken', 'content-length': 0 }
 ✖ FAILED in 4ms


-- FAILURES:

  1) Repro test: without headers:
     'Bearer validToken' == undefined
  
  Run with --verbose flag to see NodeJS stacktrace


  FAIL  | 1 passed, 1 failed   // 48ms
error Command failed with exit code 1.

Provide test source code if related

const assert = require('assert');

Feature('Repro test');

Scenario('with headers', function *(I) {
    I.haveRequestHeaders({
        'Authorization': 'Bearer validToken'
    });

    const {request: {headers}} = yield I.sendGetRequest('/ping');
    console.log("request headers ", headers);
    
    assert.equal(headers.Authorization, 'Bearer validToken');
});

Scenario('without headers', function *(I) {
    const {request: {headers}} = yield I.sendGetRequest('/ping');
    console.log("request headers ", headers);

    assert.equal(headers.Authorization, undefined);
});

Details

  • CodeceptJS version: 1.0.3

  • NodeJS Version: v8.8.0

  • Operating System: Ubuntu 16.04 Xenial

  • Unirest: 0.5.1

  • Configuration file:

{
  "tests": "./*_test.js",
  "timeout": 10000,
  "output": "./output",
  "helpers": {
    "REST": {
      "endpoint": "http://localhost:3030",
      "resetHeaders": true
    }
  },
  "include": {},
  "bootstrap": "./bootstrap.js",
  "teardown": "./bootstrap.js",
  "mocha": {},
  "name": "codecept-headers"
}

I also have a repo with a tiny Hapi server that reproduces the issue and includes my bootstrap code: https://github.com/alexashley/codecept-headers

Running the test without the authorization header first fixed the issue, but I ultimately decided to pass the headers along with every sendGetRequest instead of using haveRequestHeaders.

@DavertMik
Copy link
Contributor

I think you had investigated that pretty far :) Could you get this fixed? Please send a pull request

@alexashley
Copy link
Contributor Author

@DavertMik I'll give it a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants