Skip to content

Commit

Permalink
Resolving Hard coded secret in repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanshug committed Jan 5, 2024
1 parent 2f7b94e commit e45fdcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion frontend/src/__mocks__/mockStatus.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { StatusResponse } from '~/redux/types';
import { createMockToken } from '~/utilities/string';

export const mockStatus = (): StatusResponse => ({
kube: {
currentContext: 'opendatahub/admin-user-datahub-redhat-com:6443/admin-user',
currentUser: {
name: 'admin-user/api-admin-user-dev-datahub-redhat-com:6443',
token: 'sha256~9iRWHnXnoQusPNr11Hda_rqwerfasdfQWERasdfasdf',
token: createMockToken(),
},
namespace: 'opendatahub',
userName: 'admin-user',
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/utilities/__tests__/string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { replaceNonNumericPartWithString, replaceNumericPartWithString } from '~/utilities/string';
import {
createMockToken,
replaceNonNumericPartWithString,
replaceNumericPartWithString,
} from '~/utilities/string';

describe('replaceNumericPartWithString', () => {
it('should replace the numeric part of a string with a number', () => {
Expand Down Expand Up @@ -71,3 +75,11 @@ describe('replaceNonNumericPartWithString', () => {
expect(replaceNonNumericPartWithString('1Week', 'Minute')).toBe('1Minute');
});
});

describe('createMockToken', () => {
it('should generate a valid mock token', () => {
const token = createMockToken();
const tokenRegex = /^sha256~[a-z0-9]{48}$/i;
expect(token).toMatch(tokenRegex);
});
});
6 changes: 6 additions & 0 deletions frontend/src/utilities/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ export const replaceNonNumericPartWithString = (
}
return updatedString;
};

/**
* Mocks a token for testing purpose
*/
export const createMockToken = (): string =>
`sha256~${Array.from({ length: 48 }, () => Math.random().toString(36)[2]).join('')}`;

0 comments on commit e45fdcb

Please sign in to comment.