Skip to content

Commit

Permalink
Hide user local path (#578)
Browse files Browse the repository at this point in the history
* Hide user local path
  • Loading branch information
sudhirverma authored May 17, 2021
1 parent 5080b04 commit 0e8da8c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/util/hideclusterinformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@ export function hideClusterUrl(message: string): string {
if (urlCheck.test(message)) {
return message.replace(urlCheck, 'cluster info ');
}
return hidePath(message);
}

// eslint-disable-next-line no-useless-escape
const pathMatch = /(?:"([a-zA-Z]\:(\\|\/|\\\\)|\/([^\/]+\/)|.\/|([^\/"]+\/)))([^\\\/\:\*\?\<\>\"\|]+(\\|\/){0,2})+/gm;
export function hidePath(message: string): string {
if (pathMatch.test(message)) {
const paths = message.match(pathMatch);
if (paths.length !== 0) {
paths.forEach((path) => {
message = message.replace(path, '"local path');
});
}
return message;
}
return message;
}
31 changes: 31 additions & 0 deletions test/util/hideclusterinformation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

'use strict';

import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
import { hidePath } from '../../src/util/hideclusterinformation';

const expect = chai.expect;
chai.use(sinonChai);

suite('Hide user information', () => {

const userPath = `undefinedUnable to connect to the server: error executing access token command "C:\\!Users\\test\\AppData\\Local\\test-code\\installer\\test-cloud-sdk\\bin\\test.cmd config config-helper --format=json": err=exec: "C:\\Users\test\\AppData\\Local\\test-code\\installer\\test-cloud-sdk\\₭ǝ℞ᖭ\\₭ǝ℞ᖭ.cmd": file does not exist output= stderr=
"/₭℞ᖭ/apple/₭℞ᖭ/" "./test/test" "test/test2" "test" `;

test('Hide local user path', async () => {
const result = hidePath(userPath);
expect(result).deep.equals(`undefinedUnable to connect to the server: error executing access token command "local path": err=exec: "local path": file does not exist output= stderr=
"local path" "local path" "local path" "test" `);
});

test('return string if local user path not found', async () => {
const message = 'undefinedUnable to connect to the server: error executing access token command';
const result = hidePath(message);
expect(result).deep.equals(message);
});
});

0 comments on commit 0e8da8c

Please sign in to comment.