forked from czervenka/ws-proxy-poc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker support for external key manager and verbosity configuration
- Loading branch information
Robin Gottfried
committed
May 15, 2020
1 parent
32bedeb
commit 9467292
Showing
7 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,59 @@ | ||
// vim: ft=javascript tabstop=2 softtabstop=2 expandtab shiftwidth=2 | ||
const test = require('ava'), | ||
nock = require('nock'), | ||
authenticator = require('../server/api-authenticator'); | ||
authenticator = require('../server/api-authenticator'), | ||
fakeRequest = {headers: {host: 'http://example.com'}}; | ||
|
||
test('valid key passes', t => { | ||
const key = 'some-secret-key', | ||
authServerUri = 'http://example.com', | ||
response = {sub: 'userinfo', iss: 'iss'}; | ||
nock(`${authServerUri}`).get(`/key/${key}`).reply(200, response); | ||
nock(authServerUri).get(`/key/${key}`).reply(200, response); | ||
const authenticate = authenticator.getAuthenticator(authServerUri); | ||
return authenticate(key).then(clientInfo => { | ||
t.deepEqual(clientInfo, response); | ||
return authenticate(key, fakeRequest).then(clientInfo => { | ||
t.deepEqual(clientInfo, {authenticated: true, token: response}); | ||
}); | ||
}); | ||
|
||
test('auth is skipped for selected hostnames even when the key is invalid', t => { | ||
const key = 'some-secret-key', | ||
authServerUri = 'http://example.com', | ||
authenticate = authenticator.getAuthenticator(authServerUri, 'a.example.com,b.example.com'), | ||
request = {headers: {host: 'b.example.com'}}, | ||
promises = []; | ||
|
||
promises.push( | ||
authenticate(key, request).then(clientInfo => { | ||
t.is(clientInfo.authenticated, false); | ||
}) | ||
); | ||
// nock(authServerUri).get(`/key/${key}`).reply(422); | ||
// promises.push( | ||
// authenticate(key, fakeRequest).catch((err) => { | ||
// t.assert(err instanceof authenticator.InvalidKey) | ||
// }) | ||
// ); | ||
return Promise.all(promises); | ||
}); | ||
|
||
test('fail on invalid key', t => { | ||
const key = 'some-secret-key', | ||
authServerUri = 'http://example.com'; | ||
nock(`${authServerUri}`).get(`/key/${key}`).reply(422); | ||
const authenticate = authenticator.getAuthenticator(authServerUri); | ||
return authenticate(key).catch((err) => { | ||
const authenticate = authenticator.getAuthenticator(authServerUri, 'a.example.com,b.example.com'); | ||
return authenticate(key, fakeRequest).catch((err) => { | ||
t.assert(err instanceof authenticator.InvalidKey) | ||
}); | ||
}); | ||
|
||
|
||
|
||
test('authentication rejected on server error', t => { | ||
const key = 'some-secret-key', | ||
authServerUri = 'http://example.com'; | ||
nock(`${authServerUri}`).get(`/key/${key}`).reply(500); | ||
const authenticate = authenticator.getAuthenticator(authServerUri); | ||
return authenticate(key).catch((err) => { | ||
return authenticate(key, fakeRequest).catch((err) => { | ||
t.assert(!(err instanceof authenticator.InvalidKey)) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters