Open HirokiUchikawa opened 5 years ago
@HirokiUchikawa many thanks!! I wonder how is your patch being used, could you post a demo test spec?
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)
We really need this fix to be merged to test some endpoints in our nodes.
Proposed changes
Currently
helper.request()
supports testing editor/admin URL, but it cannot request the URL which defined byhttp in node
. This is becausehelper.request()
does not handleruntime.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
grunt
to verify the unit tests pass