Skip to content

Commit

Permalink
added unit test case and fixed build (we can't rely on Uri being a cl…
Browse files Browse the repository at this point in the history
…ass)
  • Loading branch information
jstrachan committed Apr 19, 2013
1 parent 8e720c6 commit 789bca1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions hawtio-web/src/main/webapp/app/core/js/hawtio-plugin-loader.js
Expand Up @@ -45,16 +45,26 @@
return map;
};

hawtioPluginLoader.credentialsRegex = new RegExp(/.*:\/\/([^@]+)@.*/);

/**
* Parses the username:password from a http basic auth URL, e.g.
* http://foo:bar@example.com
*/
hawtioPluginLoader.getCredentials = function(url) {
/*
No Uri class outside of IE right?
var uri = new Uri(url);
var credentials = uri.userInfo();
if (credentials.indexOf(':') > -1) {
return credentials.split(':');
}
*/
var m = url.match(hawtioPluginLoader.credentialsRegex);
if (m && m.length > 1) {
var credentials = m[1];
if (credentials && credentials.indexOf(':') > -1) {
return credentials.split(':');
}
}
return [];
};

Expand Down
6 changes: 6 additions & 0 deletions hawtio-web/src/test/specs/spec/CoreSpec.js
Expand Up @@ -69,4 +69,10 @@ describe("Core", function () {
});
});


it("extracts credentials from URLs", function () {
var creds = hawtioPluginLoader.getCredentials("http://foo:bar@whatnot");
expect(creds[0]).toEqual("foo");
expect(creds[1]).toEqual("bar");
});
});

0 comments on commit 789bca1

Please sign in to comment.