mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
[PM-814] Breach Report Escape Characters (#16264)
* encode username for uri and add spec * verify response from getHibpBreach method * test/validate for BreachAccountResponse type and length instead of mock response
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
|||||||
VaultTimeoutSettingsService,
|
VaultTimeoutSettingsService,
|
||||||
VaultTimeoutStringType,
|
VaultTimeoutStringType,
|
||||||
} from "../key-management/vault-timeout";
|
} from "../key-management/vault-timeout";
|
||||||
|
import { BreachAccountResponse } from "../models/response/breach-account.response";
|
||||||
import { ErrorResponse } from "../models/response/error.response";
|
import { ErrorResponse } from "../models/response/error.response";
|
||||||
import { AppIdService } from "../platform/abstractions/app-id.service";
|
import { AppIdService } from "../platform/abstractions/app-id.service";
|
||||||
import { Environment, EnvironmentService } from "../platform/abstractions/environment.service";
|
import { Environment, EnvironmentService } from "../platform/abstractions/environment.service";
|
||||||
@@ -411,4 +412,26 @@ describe("ApiService", () => {
|
|||||||
).rejects.toMatchObject(error);
|
).rejects.toMatchObject(error);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
describe("getHibpBreach", () => {
|
||||||
|
it("should properly URL encode username with special characters", async () => {
|
||||||
|
const mockResponse = [{ name: "test" }];
|
||||||
|
const username = "connect#bwpm@simplelogin.co";
|
||||||
|
|
||||||
|
jest.spyOn(sut, "send").mockResolvedValue(mockResponse);
|
||||||
|
|
||||||
|
const result = await sut.getHibpBreach(username);
|
||||||
|
|
||||||
|
expect(sut.send).toHaveBeenCalledWith(
|
||||||
|
"GET",
|
||||||
|
"/hibp/breach?username=" + encodeURIComponent(username),
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(result).toBeInstanceOf(Array);
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0]).toBeInstanceOf(BreachAccountResponse);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1434,7 +1434,8 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
// HIBP APIs
|
// HIBP APIs
|
||||||
|
|
||||||
async getHibpBreach(username: string): Promise<BreachAccountResponse[]> {
|
async getHibpBreach(username: string): Promise<BreachAccountResponse[]> {
|
||||||
const r = await this.send("GET", "/hibp/breach?username=" + username, null, true, true);
|
const encodedUsername = encodeURIComponent(username);
|
||||||
|
const r = await this.send("GET", "/hibp/breach?username=" + encodedUsername, null, true, true);
|
||||||
return r.map((a: any) => new BreachAccountResponse(a));
|
return r.map((a: any) => new BreachAccountResponse(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user