1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-11 05:53:42 +00:00

fix(billing): Ensure encrypted org key is present during upgrade

This commit is contained in:
Stephon Brown
2026-02-03 17:27:19 -05:00
parent cb6f192b1d
commit 770fedcec2
2 changed files with 16 additions and 0 deletions

View File

@@ -150,6 +150,18 @@ describe("PremiumOrgUpgradeService", () => {
).rejects.toThrow("Key generation failed");
});
it("should throw an error if encrypted string is undefined", async () => {
keyService.makeOrgKey.mockResolvedValue([{ encryptedString: undefined }, "decrypted-key"]);
await expect(
service.upgradeToOrganization(
mockAccount,
"Test Organization",
mockPlanDetails,
mockBillingAddress,
),
).rejects.toThrow("Failed to generate encrypted organization key");
});
it("should propagate error if upgrade API call fails", async () => {
accountBillingClient.upgradePremiumToOrganization.mockRejectedValue(
new Error("API call failed"),

View File

@@ -83,6 +83,10 @@ export class PremiumOrgUpgradeService {
const tier: ProductTierType = this.ProductTierTypeFromSubscriptionTierId(planDetails.tier);
const [encryptedKey] = await this.keyService.makeOrgKey<OrgKey>(account.id);
if (!encryptedKey.encryptedString) {
throw new Error("Failed to generate encrypted organization key");
}
await this.accountBillingClient.upgradePremiumToOrganization(
organizationName,
encryptedKey.encryptedString,