Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support 'AUTHTYPE' as alias for 'AUTH_TYPE' config property #153

Merged
merged 3 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions auth/utils/get-authenticator-from-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export function getAuthenticatorFromEnvironment(serviceName: string): Authentica
// if an apikey is provided, default to IAM
// if not, default to container auth
let { authType } = credentials;

if (!authType) {
// Support the alternate "AUTHTYPE" config property.
authType = credentials.authtype;
}
if (!authType || typeof authType !== 'string') {
authType = credentials.apikey ? 'iam' : 'container';
}
Expand Down
7 changes: 6 additions & 1 deletion test/resources/ibm-credentials.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ SERVICE_2_APIKEY=V4HXmoUtMjohnsnow=KotN
SERVICE_2_CLIENT_ID=somefake========id
SERVICE_2_CLIENT_SECRET===my-client-secret==
SERVICE_2_AUTH_URL=https://iamhost/iam/api=
SERVICE_2_SCOPE=A B C D
SERVICE_2_SCOPE=A B C D

# Service3 configured with basic auth
SERVICE_3_AUTHTYPE=basic
SERVICE_3_USERNAME=user1
SERVICE_3_PASSWORD=password1
9 changes: 2 additions & 7 deletions test/unit/get-authenticator-from-environment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ describe('Get Authenticator From Environment Module', () => {

it('should get basic authenticator', () => {
setUpBasicPayload();
readExternalSourcesMock.mockImplementation(() => ({
authType: 'basic',
username: 'a',
password: 'b',
}));
const authenticator = getAuthenticatorFromEnvironment(SERVICE_NAME);
expect(authenticator).toBeInstanceOf(BasicAuthenticator);
});
Expand Down Expand Up @@ -122,7 +117,7 @@ function setUpNoAuthPayload() {

function setUpBasicPayload() {
readExternalSourcesMock.mockImplementation(() => ({
authType: 'basic',
authtype: 'basic',
username: 'a',
password: 'b',
}));
Expand Down Expand Up @@ -152,7 +147,7 @@ function setUpIamPayloadWithScope() {

function setUpCp4dPayload() {
readExternalSourcesMock.mockImplementation(() => ({
authType: 'cp4d',
authtype: 'cp4d',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all good and probably sufficient, but if you wanted to throw in one extra test you could add something to read-external-sources.test.js that ensures something like SERVICE_NAME_AUTHTYPE is in fact converted to authtype in the object returned. Totally up to you, it's fine as is

username: 'a',
password: 'b',
authUrl: TOKEN_URL,
Expand Down
11 changes: 11 additions & 0 deletions test/unit/read-external-sources.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ describe('Read External Sources Module', () => {
expect(properties.scope).toBe(SCOPE);
});

it('should return properties for service_3 from creds file', () => {
setupCredsFile();
const properties = readExternalSources('service_3');
expect(properties).not.toBeNull();
// auth props
expect(properties.authType).not.toBeDefined();
expect(properties.authtype).toBe('basic');
expect(properties.username).toBe('user1');
expect(properties.password).toBe('password1');
});

// env
it('should return an object from environment variables', () => {
setupEnvVars();
Expand Down