Skip to content

Commit 6221694

Browse files
authored
Set client telemetry by default (#2796)
1 parent 4f9b99f commit 6221694

File tree

4 files changed

+342
-48
lines changed

4 files changed

+342
-48
lines changed

src/startup.runtime.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,40 @@ window.onbeforeunload = () => {
4545
function initFeatures() {
4646
const logger = injector.resolve<Logger>("logger");
4747
const settingsProvider = injector.resolve<ISettingsProvider>("settingsProvider");
48-
Utils.checkIsFeatureEnabled(FEATURE_CLIENT_TELEMETRY, settingsProvider, logger)
48+
Utils.getFeatureValueOrNull(FEATURE_CLIENT_TELEMETRY, settingsProvider, logger)
4949
.then((isEnabled) => {
50+
const featureFlagValue = isEnabled === null || isEnabled;
5051
logger.trackEvent("FeatureFlag", {
5152
feature: FEATURE_CLIENT_TELEMETRY,
52-
enabled: isEnabled.toString(),
53+
enabled: featureFlagValue.toString(),
5354
message: `Feature flag '${FEATURE_CLIENT_TELEMETRY}' - ${isEnabled ? 'enabled' : 'disabled'}`
5455
});
5556
let telemetryConfigurator = new TelemetryConfigurator(injector);
56-
if (isEnabled) {
57+
if (featureFlagValue) {
5758
telemetryConfigurator.configure();
5859
} else {
5960
telemetryConfigurator.cleanUp();
6061
}
6162
});
62-
Utils.checkIsFeatureEnabled(isRedesignEnabledSetting, settingsProvider, logger)
63+
checkIsRedesignEnabled(settingsProvider, logger)
6364
.then((isEnabled) => {
6465
logger.trackEvent("FeatureFlag", {
6566
feature: isRedesignEnabledSetting,
6667
enabled: isEnabled.toString(),
6768
message: `Feature flag '${isRedesignEnabledSetting}' - ${isEnabled ? 'enabled' : 'disabled'}`
6869
});
6970
});
71+
}
72+
73+
async function checkIsRedesignEnabled(settingsProvider: ISettingsProvider, logger: Logger): Promise<boolean> {
74+
try {
75+
const setting = await settingsProvider.getSetting(isRedesignEnabledSetting);
76+
77+
if (!setting) return false;
78+
79+
return Boolean(setting);
80+
} catch (error) {
81+
logger?.trackEvent("FeatureFlag", { message: "Feature flag check failed", data: error.message });
82+
return false;
83+
}
7084
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import { assert } from "chai";
2+
import { describe, it } from "mocha";
3+
import { sanitizeUrl, cleanUpUrlParams, cleanUrlSensitiveDataFromQuery, cleanUrlSensitiveDataFromValue } from "./serviceWorker";
4+
5+
describe("serviceWorker", () => {
6+
7+
describe("sanitizeUrl", () => {
8+
it("should remove sensitive data from query parameters", () => {
9+
const url = "https://example.com/path?client_secret=abc&token=xyz&other=123";
10+
const sanitizedUrl = sanitizeUrl(url);
11+
assert.equal(sanitizedUrl, "https://example.com/path?client_secret=***&token=***&other=123");
12+
});
13+
14+
it("should remove sensitive data from hash parameters", () => {
15+
const url = "https://example.com/path#client_secret=abc&token=xyz&other=123";
16+
const sanitizedUrl = sanitizeUrl(url);
17+
assert.equal(sanitizedUrl, "https://example.com/path#client_secret=***&token=***&other=***");
18+
});
19+
20+
it("should handle URLs without sensitive data", () => {
21+
const url = "https://example.com/path?other=123";
22+
const sanitizedUrl = sanitizeUrl(url);
23+
assert.equal(sanitizedUrl, "https://example.com/path?other=123");
24+
});
25+
26+
it("should handle URLs with only allowed parameters in hash", () => {
27+
const url = "https://example.com/path#state=abc&session_state=xyz&client_secret=abc";
28+
const sanitizedUrl = sanitizeUrl(url);
29+
assert.equal(sanitizedUrl, "https://example.com/path#state=abc&session_state=xyz&client_secret=***");
30+
});
31+
32+
it("should handle null or undefined URLs", () => {
33+
assert.equal(sanitizeUrl(null), null);
34+
assert.equal(sanitizeUrl(undefined), undefined);
35+
});
36+
37+
it("should handle empty URLs", () => {
38+
assert.equal(sanitizeUrl(""), "");
39+
});
40+
});
41+
42+
43+
describe("cleanUpUrlParams", () => {
44+
it("should replace sensitive parameters with ***", () => {
45+
const url = "https://example.com/path#client_secret=abc&token=xyz&other=123";
46+
const cleanedUrl = cleanUpUrlParams(url);
47+
assert.equal(cleanedUrl, "https://example.com/path#client_secret=***&token=***&other=***");
48+
});
49+
50+
it("should leave allowed parameters unchanged", () => {
51+
const url = "https://example.com/path#state=abc&session_state=xyz&client_secret=abc";
52+
const cleanedUrl = cleanUpUrlParams(url);
53+
assert.equal(cleanedUrl, "https://example.com/path#state=abc&session_state=xyz&client_secret=***");
54+
});
55+
56+
it("should handle URLs without hash", () => {
57+
const url = "https://example.com/path";
58+
const cleanedUrl = cleanUpUrlParams(url);
59+
assert.equal(cleanedUrl, "https://example.com/path");
60+
});
61+
62+
it("should handle null or undefined URLs", () => {
63+
assert.equal(cleanUpUrlParams(null), null);
64+
assert.equal(cleanUpUrlParams(undefined), undefined);
65+
});
66+
67+
it("should handle empty URLs", () => {
68+
assert.equal(cleanUpUrlParams(""), "");
69+
});
70+
});
71+
72+
describe("cleanUrlSensitiveDataFromQuery", () => {
73+
it("should replace sensitive query parameters with ***", () => {
74+
const url = "https://example.com/path?client_secret=abc&token=xyz&other=123";
75+
const cleanedUrl = cleanUrlSensitiveDataFromQuery(url);
76+
assert.equal(cleanedUrl, "https://example.com/path?client_secret=***&token=***&other=123");
77+
});
78+
79+
it("should handle URLs without query parameters", () => {
80+
const url = "https://example.com/path";
81+
const cleanedUrl = cleanUrlSensitiveDataFromQuery(url);
82+
assert.equal(cleanedUrl, "https://example.com/path");
83+
});
84+
85+
it("should handle null or undefined URLs", () => {
86+
assert.equal(cleanUrlSensitiveDataFromQuery(null), null);
87+
assert.equal(cleanUrlSensitiveDataFromQuery(undefined), undefined);
88+
});
89+
90+
it("should handle empty URLs", () => {
91+
assert.equal(cleanUrlSensitiveDataFromQuery(""), "");
92+
});
93+
94+
it("should handle complex URLs with multiple parameters", () => {
95+
const url = "https://example.com/api/v1?client_secret=abc123&api_key=xyz789&user=john&password=pass123&normal=value";
96+
const cleanedUrl = cleanUrlSensitiveDataFromQuery(url);
97+
assert.equal(cleanedUrl, "https://example.com/api/v1?client_secret=***&api_key=xyz789&user=***&password=***&normal=value");
98+
});
99+
100+
it("should handle URLs with encoded characters", () => {
101+
const url = "https://example.com/path?token=abc%26xyz&user_name=john%20doe";
102+
const cleanedUrl = cleanUrlSensitiveDataFromQuery(url);
103+
assert.equal(cleanedUrl, "https://example.com/path?token=***&user_name=***");
104+
});
105+
106+
it("should handle special cases like access_token and user_name", () => {
107+
const url = "https://example.com/oauth?access_token=abc123&user_name=john";
108+
const cleanedUrl = cleanUrlSensitiveDataFromQuery(url);
109+
assert.equal(cleanedUrl, "https://example.com/oauth?access_token=***&user_name=***");
110+
});
111+
112+
it("should handle malformed URLs by using fallback mechanism", () => {
113+
const url = "invalid://url with spaces?token=abc";
114+
const cleanedUrl = cleanUrlSensitiveDataFromQuery(url);
115+
// Should still sanitize using regex fallback
116+
assert.equal(cleanedUrl, "invalid://url with spaces?token=***");
117+
});
118+
});
119+
120+
describe("cleanUrlSensitiveDataFromValue", () => {
121+
it("should replace sensitive data in header values with ***", () => {
122+
const dataValue = "client_secret=abc&token=xyz&other=123";
123+
const cleanedValue = cleanUrlSensitiveDataFromValue(dataValue);
124+
assert.equal(cleanedValue, "client_secret=***&token=***&other=123");
125+
});
126+
127+
it("should handle values without sensitive data", () => {
128+
const dataValue = "other=123";
129+
const cleanedValue = cleanUrlSensitiveDataFromValue(dataValue);
130+
assert.equal(cleanedValue, "other=123");
131+
});
132+
133+
it("should handle null or undefined values", () => {
134+
assert.equal(cleanUrlSensitiveDataFromValue(null), null);
135+
assert.equal(cleanUrlSensitiveDataFromValue(undefined), undefined);
136+
});
137+
138+
it("should handle empty values", () => {
139+
assert.equal(cleanUrlSensitiveDataFromValue(""), "");
140+
});
141+
});
142+
});

0 commit comments

Comments
 (0)