From b48356228c5ca1437f5ede48f34aa0c79e877d79 Mon Sep 17 00:00:00 2001 From: Leslie Tilton <23057410+Banrion@users.noreply.github.com> Date: Thu, 29 May 2025 08:45:40 -0500 Subject: [PATCH] Update risk insights report to default an invalid uri to the original uri (#14800) --- .../reports/risk-insights/services/ciphers.mock.ts | 3 +++ .../services/risk-insights-report.service.spec.ts | 14 +++++++++----- .../services/risk-insights-report.service.ts | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/ciphers.mock.ts b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/ciphers.mock.ts index ca5cdc35b8a..f697d24f208 100644 --- a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/ciphers.mock.ts +++ b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/ciphers.mock.ts @@ -27,6 +27,9 @@ export const mockCiphers: any[] = [ createLoginUriView("accounts.google.com"), createLoginUriView("https://www.google.com"), createLoginUriView("https://www.google.com/login"), + createLoginUriView("www.invalid@uri@.com"), + createLoginUriView("www.invaliduri!.com"), + createLoginUriView("this_is-not|a-valid-uri123@+"), ], }, edit: false, diff --git a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.spec.ts b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.spec.ts index f9177bf1bf7..3aa624f1e59 100644 --- a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.spec.ts +++ b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.spec.ts @@ -50,7 +50,7 @@ describe("RiskInsightsReportService", () => { let testCase = testCaseResults[0]; expect(testCase).toBeTruthy(); expect(testCase.cipherMembers).toHaveLength(2); - expect(testCase.trimmedUris).toHaveLength(2); + expect(testCase.trimmedUris).toHaveLength(5); expect(testCase.weakPasswordDetail).toBeTruthy(); expect(testCase.exposedPasswordDetail).toBeTruthy(); expect(testCase.reusedPasswordCount).toEqual(2); @@ -69,12 +69,16 @@ describe("RiskInsightsReportService", () => { it("should generate the raw data + uri report correctly", async () => { const result = await firstValueFrom(service.generateRawDataUriReport$("orgId")); - expect(result).toHaveLength(8); + expect(result).toHaveLength(11); // Two ciphers that have google.com as their uri. There should be 2 results const googleResults = result.filter((x) => x.trimmedUri === "google.com"); expect(googleResults).toHaveLength(2); + // There is an invalid uri and it should not be trimmed + const invalidUriResults = result.filter((x) => x.trimmedUri === "this_is-not|a-valid-uri123@+"); + expect(invalidUriResults).toHaveLength(1); + // Verify the details for one of the googles matches the password health info // expected const firstGoogle = googleResults.filter( @@ -88,7 +92,7 @@ describe("RiskInsightsReportService", () => { it("should generate applications health report data correctly", async () => { const result = await firstValueFrom(service.generateApplicationsReport$("orgId")); - expect(result).toHaveLength(5); + expect(result).toHaveLength(8); // Two ciphers have google.com associated with them. The first cipher // has 2 members and the second has 4. However, the 2 members in the first @@ -132,7 +136,7 @@ describe("RiskInsightsReportService", () => { expect(reportSummary.totalMemberCount).toEqual(7); expect(reportSummary.totalAtRiskMemberCount).toEqual(6); - expect(reportSummary.totalApplicationCount).toEqual(5); - expect(reportSummary.totalAtRiskApplicationCount).toEqual(4); + expect(reportSummary.totalApplicationCount).toEqual(8); + expect(reportSummary.totalAtRiskApplicationCount).toEqual(7); }); }); diff --git a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.ts b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.ts index e4fece801b6..6fdab58115d 100644 --- a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.ts +++ b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/risk-insights-report.service.ts @@ -433,7 +433,7 @@ export class RiskInsightsReportService { const cipherUris: string[] = []; const uris = cipher.login?.uris ?? []; uris.map((u: { uri: string }) => { - const uri = Utils.getDomain(u.uri); + const uri = Utils.getDomain(u.uri) ?? u.uri; if (!cipherUris.includes(uri)) { cipherUris.push(uri); }