Skip to content

Commit

Permalink
Don't include username+password in URL (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
CGamesPlay authored Apr 13, 2020
1 parent d4fc0b6 commit 0437484
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
3 changes: 0 additions & 3 deletions services/esUrlSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ angular.module('o19s.splainer-search')

function buildBaseUrl (uri) {
var url = uri.protocol + '://';
if (uri.password && uri.username) {
url += uri.username + ':' + uri.password + '@';
}
url += (uri.host);

return url;
Expand Down
14 changes: 11 additions & 3 deletions test/spec/esSearchSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('Service: searchSvc: ElasticSearch', function() {

var searcher;
var searchSvc;
var esUrlSvc;
var $httpBackend;
var fieldSpecSvc = null;
var mockEsUrl = 'http://localhost:9200/statedecoded/_search';
Expand All @@ -34,9 +35,10 @@ describe('Service: searchSvc: ElasticSearch', function() {
$httpBackend = $injector.get('$httpBackend');
}));

beforeEach(inject(function (_searchSvc_, _fieldSpecSvc_) {
beforeEach(inject(function (_searchSvc_, _fieldSpecSvc_, _esUrlSvc_) {
searchSvc = _searchSvc_;
fieldSpecSvc = _fieldSpecSvc_;
esUrlSvc = _esUrlSvc_;
mockFieldSpec = fieldSpecSvc.createFieldSpec('field field1');
}));

Expand Down Expand Up @@ -304,7 +306,10 @@ describe('Service: searchSvc: ElasticSearch', function() {
'es'
);

$httpBackend.expectPOST(authEsUrl, undefined, function(headers) {
// The headers need to be removed from the URL, which we accomplish
// using the esUrlSvc.
var targetUrl = esUrlSvc.buildUrl(esUrlSvc.parseUrl(authEsUrl))
$httpBackend.expectPOST(targetUrl, undefined, function(headers) {
return headers['Authorization'] == 'Basic ' + btoa('username:password');
}).
respond(200, mockES4Results);
Expand Down Expand Up @@ -504,7 +509,10 @@ describe('Service: searchSvc: ElasticSearch', function() {
'es'
);

$httpBackend.expectPOST(authEsUrl, undefined, function(headers) {
// The headers need to be removed from the URL, which we accomplish
// using the esUrlSvc.
var targetUrl = esUrlSvc.buildUrl(esUrlSvc.parseUrl(authEsUrl))
$httpBackend.expectPOST(targetUrl, undefined, function(headers) {
return headers['Authorization'] == 'Basic ' + btoa('username:password');
}).
respond(200, mockES5Results);
Expand Down
6 changes: 0 additions & 6 deletions test/spec/esUrlSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ describe('Service: esUrlSvc', function () {
expect(uri.username).toBe('username');
expect(uri.password).toBe('password');

var rebuiltUri = esUrlSvc.buildUrl(uri);
var uriAgain = esUrlSvc.parseUrl(rebuiltUri);

expect(uriAgain.username).toBe('username');
expect(uriAgain.password).toBe('password');

});

it('understands when bulk endpoint used', function() {
Expand Down

0 comments on commit 0437484

Please sign in to comment.