mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Merge pull request #3017 from hardillb/dev
Fix for basic auth with @ in username
This commit is contained in:
		@@ -207,12 +207,23 @@ module.exports = function(RED) {
 | 
			
		||||
            }
 | 
			
		||||
            if (this.credentials) {
 | 
			
		||||
                if (this.authType === "basic") {
 | 
			
		||||
                    // Workaround for https://github.com/sindresorhus/got/issues/1169
 | 
			
		||||
                    var cred = ""
 | 
			
		||||
                    var parsedURL = new URL(url)
 | 
			
		||||
                    if (this.credentials.user) {
 | 
			
		||||
                        opts.username = this.credentials.user;
 | 
			
		||||
                        // opts.username = this.credentials.user;
 | 
			
		||||
                        cred = this.credentials.user
 | 
			
		||||
                    } else if (parsedURL.username) {
 | 
			
		||||
                        cred = parsedURL.username
 | 
			
		||||
                    }
 | 
			
		||||
                    if (this.credentials.password) {
 | 
			
		||||
                        opts.password = this.credentials.password;
 | 
			
		||||
                        // opts.password = this.credentials.password;
 | 
			
		||||
                        cred += ":" + this.credentials.password
 | 
			
		||||
                    } else if (parsedURL.password) {
 | 
			
		||||
                        cred += ":" + parsedURL.password
 | 
			
		||||
                    }
 | 
			
		||||
                    // build own basic auth header
 | 
			
		||||
                    opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64");
 | 
			
		||||
                } else if (this.authType === "digest") {
 | 
			
		||||
                    let digestCreds = this.credentials;
 | 
			
		||||
                    let sentCreds = false;
 | 
			
		||||
 
 | 
			
		||||
@@ -1624,6 +1624,26 @@ describe('HTTP Request Node', function() {
 | 
			
		||||
                n1.receive({payload:"foo"});
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
        it('should authenticate on server - basic', function(done) {
 | 
			
		||||
            var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/authenticate')},
 | 
			
		||||
                {id:"n2", type:"helper"}];
 | 
			
		||||
            helper.load(httpRequestNode, flow, function() {
 | 
			
		||||
                var n1 = helper.getNode("n1");
 | 
			
		||||
                var n2 = helper.getNode("n2");
 | 
			
		||||
                n1.credentials = {user:'foo@example.com', password:'passwordfoo'};
 | 
			
		||||
                n2.on("input", function(msg) {
 | 
			
		||||
                    try {
 | 
			
		||||
                        msg.should.have.property('statusCode',200);
 | 
			
		||||
                        msg.payload.should.have.property('user', 'foo@example.com');
 | 
			
		||||
                        msg.payload.should.have.property('pass', 'passwordfoo');
 | 
			
		||||
                        done();
 | 
			
		||||
                    } catch(err) {
 | 
			
		||||
                        done(err);
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
                n1.receive({payload:"foo"});
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
        it('should authenticate on server - bearer', function(done) {
 | 
			
		||||
            var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",authType:"bearer", url:getTestURL('/authenticate')},
 | 
			
		||||
                {id:"n2", type:"helper"}];
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user