[Pkg-javascript-commits] [sockjs-client] 270/350: Don't remove basic authentication credentials

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:04:29 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 9aecf21ec44e9f190ac1b8d0e5476920f5af012f
Author: Luigi Pinca <luigipinca at gmail.com>
Date:   Sun Dec 7 12:17:02 2014 +0100

    Don't remove basic authentication credentials
---
 lib/main.js       |  8 +++++++-
 tests/lib/main.js | 10 ++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/main.js b/lib/main.js
index d90d874..e02dc2b 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -90,8 +90,14 @@ function SockJS(url, protocols, options) {
   // remove the trailing slash
   parsedUrl.path = parsedUrl.pathname.replace(/[/]+$/, '') + (parsedUrl.query || '');
 
+  // basic authentication
+  parsedUrl.auth = parsedUrl.username
+    ? parsedUrl.username + ':' + parsedUrl.password + '@'
+    : '';
+
   // store the sanitized url
-  this.url = parsedUrl.protocol + '//' + parsedUrl.hostname + (parsedUrl.port ? (':' + parsedUrl.port) : '') + parsedUrl.path;
+  this.url = parsedUrl.protocol + '//' + parsedUrl.auth + parsedUrl.hostname +
+    (parsedUrl.port ? ':' + parsedUrl.port : '') + parsedUrl.path;
   debug('using url', this.url);
 
   // Step 7 - start connection in background
diff --git a/tests/lib/main.js b/tests/lib/main.js
index d507568..027e1df 100644
--- a/tests/lib/main.js
+++ b/tests/lib/main.js
@@ -23,6 +23,12 @@ describe('SockJS', function() {
       s.close();
     });
 
+    it('should not remove basic authentication credentials', function () {
+      var s = new SockJS('http://user:password@localhost');
+      expect(s).to.have.property('url', 'http://user:password@localhost');
+      s.close();
+    });
+
     describe('WebSocket specification step #1', function () {
       it('should throw SyntaxError for an invalid url', function () {
         expect(function () {
@@ -32,7 +38,7 @@ describe('SockJS', function() {
         });
       });
 
-      it('should throw TypeError for an null url', function () {
+      it('should throw TypeError for a null url', function () {
         expect(function () {
           new SockJS();
         }).to.throwException(function (e) {
@@ -41,7 +47,7 @@ describe('SockJS', function() {
       });
 
       it('should throw SyntaxError when the url contains a fragment', function () {
-         expect(function () {
+        expect(function () {
           new SockJS('http://localhost/#test');
         }).to.throwException(function (e) {
           expect(e).to.be.a(SyntaxError);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list