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 Ip address for telemetry #576

Merged
merged 1 commit into from
May 19, 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
29 changes: 27 additions & 2 deletions src/util/hideclusterinformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function hideClusterInfo(message: string): string {
const urlCheck = /(https?:\/\/[^\s]+)/g;
export function hideClusterUrl(message: string): string {
if (urlCheck.test(message)) {
return message.replace(urlCheck, 'cluster info ');
message = message.replace(urlCheck, 'cluster info ');
}
return hidePath(message);
}
Expand All @@ -29,7 +29,32 @@ export function hidePath(message: string): string {
message = message.replace(path, '"local path');
});
}
return message;
}
return hideIPAddress(message);
}

const IpAddress = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)+/gm;
export function hideIPAddress(message: string): string {
if (IpAddress.test(message)) {
const ipAddress = message.match(IpAddress);
if (ipAddress.length !== 0) {
ipAddress.forEach((data) => {
message = message.replace(data, 'IP Address ');
});
}
}
return hideIPV6Address(message);
}

const IPV6Address = /((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*::((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*|((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4})){7}/gm
export function hideIPV6Address(message: string): string {
if (IPV6Address.test(message)) {
const ipv6Address = message.match(IPV6Address);
if (ipv6Address.length !== 0) {
ipv6Address.forEach((data) => {
message = message.replace(data, 'IPV6 Address ');
});
}
}
return message;
}
22 changes: 21 additions & 1 deletion test/util/hideclusterinformation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@

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

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

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

const ipAddress = 'undefinedUnable to connect to the server: dial tcp 192.168.1.240:6443: connect: no route to host 192.168.1.240:6443 2001:0000:3238:DFE1:63::FEFB 2001:0:3238:DFE1:63::FEFB';

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" `;

const hideClusterData = 'undefinedUnable to connect to the server: dial tcp 192.168.1.240:6443: connect: no route to host 192.168.1.240:6443 2001:0000:3238:DFE1:63::FEFB https://test.com connect to the server: dial tcp: lookup https://test.com:10.10.20.30: no such host';

test('hide cluster information', async () => {
const result = hideClusterInfo(hideClusterData);
expect(result).deep.equals('undefinedUnable to connect to the server: dial tcp IP Address :6443: connect: no route to host IP Address :6443 IPV6 Address cluster info connect to the server: dial tcp: lookup cluster info: no such host');
});

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=
Expand All @@ -28,4 +37,15 @@ suite('Hide user information', () => {
const result = hidePath(message);
expect(result).deep.equals(message);
});

test('Hide user ipAddress', async () => {
const result = hideIPAddress(ipAddress);
expect(result).deep.equals('undefinedUnable to connect to the server: dial tcp IP Address :6443: connect: no route to host IP Address :6443 IPV6 Address IPV6 Address ');
});

test('return string if user ipAddress not found', async () => {
const message = 'undefinedUnable to connect to the server: dial tcp connect: no route to host';
const result = hideIPAddress(message);
expect(result).deep.equals(message);
});
});