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

Allow helper to test the URL defined by http in node #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HirokiUchikawa
Copy link
Member

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

Currently helper.request() supports testing editor/admin URL, but it cannot request the URL which defined by http in node.
This is because helper.request() does not handle runtime.httpNode which routes a request to the path defined by the node.

I fixed it in order to support runtime.httpNode.
This PR will fix #29.

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the mailing list/slack team.
  • I have run grunt to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@axgkl
Copy link

axgkl commented Feb 24, 2020

@HirokiUchikawa many thanks!!
I wonder how is your patch being used, could you post a demo test spec?

@szell
Copy link

szell commented Apr 13, 2021

Hi,

I tried out this PR with this spec. (merged to 0.2.3 release)

Its works for me

(I have custom HttpIn node )

var helper = require("node-red-node-test-helper");
var httpInNode = require("../httpinauth.js");
helper.init(require.resolve('node-red'));

describe('http in auth Node', function () {

  afterEach(function () {
    helper.unload();
  });
  
  var flow = [{id:"n1",type:"http in auth",name:"testname",url:"/test",method:"get",upload:false,swaggerDoc:"",
wires:[["n2"]]},{id:"n2",type:"http response",name:"",statusCode:"200",wires:[]}];
    var credentials = {n1: {'apikey': '****'}};
    var b64ApiKey = '****=';
  
  it('test api without auth header', function (done) {
    helper.load(httpInNode, flow, credentials, function () {
      var n1 = helper.getNode("n1");
      helper.request("httpNode").get('/test').expect(400).end(done);
    });
  });

  it('test api with correct auth header', function (done) {
    helper.load(httpInNode, flow, credentials, function () {
      var n2 = helper.getNode("n2");
      var n1 = helper.getNode("n1");
      helper.request("httpNode").get('/test').set('Authorization', b64ApiKey).expect(200).end(done);
    });
  });


  it('test api with wrong auth header', function (done) {
    helper.load(httpInNode, flow, credentials, function () {
      var n2 = helper.getNode("n2");
      var n1 = helper.getNode("n1");
      helper.request("httpNode").get('/test').set('Authorization', 'differentPassword').expect(401).end(done);
    });
  });
});
√ test api without auth header
√ test api with correct auth header
√ test api with wrong auth header

3 passing (235ms)

@WS-Daniel
Copy link

We really need this fix to be merged to test some endpoints in our nodes.

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

Successfully merging this pull request may close these issues.

Http requests always returns 404
4 participants