mirror of
https://github.com/vector-im/element-call.git
synced 2026-07-18 18:59:23 +00:00
update tests to check for delete (not anymore =null)
rename: `applyPrivacyFilters`->`santizeSensitiveData`
This commit is contained in:
@@ -18,7 +18,7 @@ import posthog, { type CaptureResult } from "posthog-js";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Anonymity,
|
Anonymity,
|
||||||
applyPrivacyFilters,
|
santizeSensitiveData,
|
||||||
PosthogAnalytics,
|
PosthogAnalytics,
|
||||||
} from "./PosthogAnalytics";
|
} from "./PosthogAnalytics";
|
||||||
import { mockConfig } from "../utils/test";
|
import { mockConfig } from "../utils/test";
|
||||||
@@ -99,7 +99,7 @@ describe("PosthogAnalytics", () => {
|
|||||||
({ event: "anyEvent", properties }) as unknown as CaptureResult;
|
({ event: "anyEvent", properties }) as unknown as CaptureResult;
|
||||||
|
|
||||||
it("drops $initial_person_info regardless of anonymity", () => {
|
it("drops $initial_person_info regardless of anonymity", () => {
|
||||||
const out = applyPrivacyFilters(
|
const out = santizeSensitiveData(
|
||||||
makeEvent({
|
makeEvent({
|
||||||
$current_url: "https://call.example.com/some/private/path",
|
$current_url: "https://call.example.com/some/private/path",
|
||||||
$initial_person_info: {
|
$initial_person_info: {
|
||||||
@@ -112,16 +112,16 @@ describe("PosthogAnalytics", () => {
|
|||||||
expect(out?.properties).not.toHaveProperty("$initial_person_info");
|
expect(out?.properties).not.toHaveProperty("$initial_person_info");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("strips path from $current_url", () => {
|
it("strips hash from $current_url", () => {
|
||||||
const out = applyPrivacyFilters(
|
const out = santizeSensitiveData(
|
||||||
makeEvent({ $current_url: "https://call.example.com/x/y/z" }),
|
makeEvent({ $current_url: "https://call.example.com/#/x/y/z" }),
|
||||||
Anonymity.Pseudonymous,
|
Anonymity.Pseudonymous,
|
||||||
);
|
);
|
||||||
expect(out?.properties["$current_url"]).not.toContain("/x/y/z");
|
expect(out?.properties["$current_url"]).not.toContain("/x/y/z");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("nulls referrer and device fields when anonymous", () => {
|
it("nulls referrer and device fields when anonymous", () => {
|
||||||
const out = applyPrivacyFilters(
|
const out = santizeSensitiveData(
|
||||||
makeEvent({
|
makeEvent({
|
||||||
$current_url: "https://x/y",
|
$current_url: "https://x/y",
|
||||||
$referrer: "https://leaky",
|
$referrer: "https://leaky",
|
||||||
@@ -130,19 +130,19 @@ describe("PosthogAnalytics", () => {
|
|||||||
}),
|
}),
|
||||||
Anonymity.Anonymous,
|
Anonymity.Anonymous,
|
||||||
);
|
);
|
||||||
expect(out?.properties["$referrer"]).toBeNull();
|
expect(out?.properties["$referrer"]).toBeUndefined();
|
||||||
expect(out?.properties["$initial_referrer"]).toBeNull();
|
expect(out?.properties["$initial_referrer"]).toBeUndefined();
|
||||||
expect(out?.properties["$device_id"]).toBeNull();
|
expect(out?.properties["$device_id"]).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes null events through unchanged", () => {
|
it("passes null events through unchanged", () => {
|
||||||
expect(applyPrivacyFilters(null, Anonymity.Pseudonymous)).toBeNull();
|
expect(santizeSensitiveData(null, Anonymity.Pseudonymous)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("strips URL fields nested inside $set_once", () => {
|
it("strips URL fields nested inside $set_once", () => {
|
||||||
const secretUrl =
|
const secretUrl =
|
||||||
"https://call.example.com/room/#/?password=hunter2&roomId=abc";
|
"https://call.example.com/room/#/?password=hunter2&roomId=abc";
|
||||||
const out = applyPrivacyFilters(
|
const out = santizeSensitiveData(
|
||||||
makeEvent({
|
makeEvent({
|
||||||
$current_url: "https://call.example.com/x",
|
$current_url: "https://call.example.com/x",
|
||||||
$set_once: {
|
$set_once: {
|
||||||
@@ -165,7 +165,7 @@ describe("PosthogAnalytics", () => {
|
|||||||
it("strips URL fields nested inside $set", () => {
|
it("strips URL fields nested inside $set", () => {
|
||||||
const secretUrl =
|
const secretUrl =
|
||||||
"https://call.example.com/room/#/?password=hunter2&roomId=abc";
|
"https://call.example.com/room/#/?password=hunter2&roomId=abc";
|
||||||
const out = applyPrivacyFilters(
|
const out = santizeSensitiveData(
|
||||||
makeEvent({
|
makeEvent({
|
||||||
$current_url: "https://call.example.com/x",
|
$current_url: "https://call.example.com/x",
|
||||||
$set: {
|
$set: {
|
||||||
@@ -182,7 +182,7 @@ describe("PosthogAnalytics", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("nulls referrer fields inside $set_once when anonymous", () => {
|
it("nulls referrer fields inside $set_once when anonymous", () => {
|
||||||
const out = applyPrivacyFilters(
|
const out = santizeSensitiveData(
|
||||||
makeEvent({
|
makeEvent({
|
||||||
$current_url: "https://x/y",
|
$current_url: "https://x/y",
|
||||||
$set_once: {
|
$set_once: {
|
||||||
@@ -194,8 +194,8 @@ describe("PosthogAnalytics", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const setOnce = out?.properties["$set_once"] as Record<string, unknown>;
|
const setOnce = out?.properties["$set_once"] as Record<string, unknown>;
|
||||||
expect(setOnce["$initial_referrer"]).toBeNull();
|
expect(setOnce["$initial_referrer"]).toBeUndefined();
|
||||||
expect(setOnce["$initial_referring_domain"]).toBeNull();
|
expect(setOnce["$initial_referring_domain"]).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ function stripSensitiveFields(
|
|||||||
* See src/utils/event-utils.ts in posthog-js (getEventProperties, getPersonInfo)
|
* See src/utils/event-utils.ts in posthog-js (getEventProperties, getPersonInfo)
|
||||||
* for the list of properties posthog sets automatically.
|
* for the list of properties posthog sets automatically.
|
||||||
*/
|
*/
|
||||||
export function applyPrivacyFilters(
|
export function santizeSensitiveData(
|
||||||
event: CaptureResult | null,
|
event: CaptureResult | null,
|
||||||
anonymity: Anonymity,
|
anonymity: Anonymity,
|
||||||
): CaptureResult | null {
|
): CaptureResult | null {
|
||||||
@@ -198,7 +198,7 @@ export class PosthogAnalytics {
|
|||||||
|
|
||||||
if (apiKey && apiHost) {
|
if (apiKey && apiHost) {
|
||||||
const beforeSend = (event: CaptureResult | null): CaptureResult | null =>
|
const beforeSend = (event: CaptureResult | null): CaptureResult | null =>
|
||||||
applyPrivacyFilters(event, this.anonymity);
|
santizeSensitiveData(event, this.anonymity);
|
||||||
this.posthog.init(apiKey, {
|
this.posthog.init(apiKey, {
|
||||||
api_host: apiHost,
|
api_host: apiHost,
|
||||||
autocapture: false,
|
autocapture: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user