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

Hide user local path #578

Merged
merged 2 commits into from
May 17, 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
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);
});
});