Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes committed Sep 30, 2019
1 parent 86fd903 commit 1c08002
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/basic-auth-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const buildError = (body) => {

async function getTokenFromBasicAuth (settings) {
return new Promise((resolve, reject) => {
const authUrl = `${settings.url}/oauth/authorize?response_type=token&client_id=openshift-challenging-client`;
const authUrl = `${settings.authUrl ? settings.authUrl : settings.url}/oauth/authorize?response_type=token&client_id=openshift-challenging-client`;
const credentials = `${settings.user}:${settings.password}`;
const auth = `Basic ${Buffer.from(credentials).toString('base64')}`;

Expand Down
2 changes: 1 addition & 1 deletion lib/openshift-rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function openshiftClient (settings = {}) {
// They are trying the basic auth.
// Get the access token using the username and password
// Check to see if we are passing in a username/password
const accessToken = await getTokenFromBasicAuth({ insecureSkipTlsVerify: kubeconfig.insecureSkipTlsVerify, url: kubeconfig.url, user: kubeconfig.auth.username || kubeconfig.auth.user, password: kubeconfig.auth.password || kubeconfig.auth.pass });
const accessToken = await getTokenFromBasicAuth({ insecureSkipTlsVerify: kubeconfig.insecureSkipTlsVerify, url: kubeconfig.url, user: kubeconfig.auth.username || kubeconfig.auth.user, password: kubeconfig.auth.password || kubeconfig.auth.pass, authUrl: kubeconfig.authUrl });

kubeconfig = {
url: kubeconfig.url,
Expand Down
33 changes: 33 additions & 0 deletions test/basic-auth-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,39 @@ test('basic auth request with 401 error', (t) => {
});
});

test('basic auth request with defined auth url', (t) => {
const basicAuthRequest = proxyquire('../lib/basic-auth-request', {
request: (requestObject, cb) => {
t.true(requestObject.url.includes('https://test'), `Unexpected auth url value`);
return cb(null, {
statusCode: 200,
request: {
uri: {
hash: '#access_token=9jXMEO87d7Rtf6FVQTFjumwIDbGeMzAtr2U010Z_ZG0&expires_in=86400&scope=user%3Afull&token_type=Bearer'
}
}
});
}
});

const settings = {
url: 'http://',
authUrl: 'https://test',
user: 'username',
password: 'password',
insecureSkipTlsVerify: true
};

const p = basicAuthRequest.getTokenFromBasicAuth(settings);

t.equal(p instanceof Promise, true, 'is an Promise');

p.then((token) => {
t.equal(token, '9jXMEO87d7Rtf6FVQTFjumwIDbGeMzAtr2U010Z_ZG0', 'should be equal');
t.end();
});
});

// test('test common request - Has a token - Request Error', (t) => {
// const common = proxyquire('../lib/common-request', {
// request: (requestObject, cb) => {
Expand Down

0 comments on commit 1c08002

Please sign in to comment.