-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[PM-28045] - Validate Organization Key Population #19954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrmccannon
wants to merge
6
commits into
main
Choose a base branch
from
jmccannon/ac/pm-28405-validate-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
65658b7
Adding validation to ensure organizations are not being created withoβ¦
jrmccannon 93a9ee2
Merge branch 'main' into jmccannon/ac/pm-28405-validate-keys
jrmccannon 4bdadea
Added request test class.
jrmccannon bf5b9d3
Removing request test.
jrmccannon 5a59c7f
removing duplicate check
jrmccannon 6d00757
Keys is different than key
jrmccannon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...rc/common/organization-user/models/requests/organization-user-accept-init.request.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { OrganizationKeysRequest } from "@bitwarden/common/admin-console/models/request/organization-keys.request"; | ||
|
|
||
| import { OrganizationUserAcceptInitRequest } from "./organization-user-accept-init.request"; | ||
|
|
||
| describe("OrganizationUserAcceptInitRequest", () => { | ||
| const validToken = "invite-token"; | ||
| const validKey = "encrypted-org-key"; | ||
| const validKeys = new OrganizationKeysRequest("public-key", "encrypted-private-key"); | ||
| const validCollectionName = "encrypted-collection-name"; | ||
|
|
||
| it("should create a request with all required parameters", () => { | ||
| const request = new OrganizationUserAcceptInitRequest( | ||
| validToken, | ||
| validKey, | ||
| validKeys, | ||
| validCollectionName, | ||
| ); | ||
|
|
||
| expect(request.token).toBe(validToken); | ||
| expect(request.key).toBe(validKey); | ||
| expect(request.keys).toBe(validKeys); | ||
| expect(request.collectionName).toBe(validCollectionName); | ||
| }); | ||
|
|
||
| it("should throw when token is empty", () => { | ||
| expect( | ||
| () => new OrganizationUserAcceptInitRequest("", validKey, validKeys, validCollectionName), | ||
| ).toThrow("Token is required"); | ||
| }); | ||
|
|
||
| it("should throw when key is empty", () => { | ||
| expect( | ||
| () => new OrganizationUserAcceptInitRequest(validToken, "", validKeys, validCollectionName), | ||
| ).toThrow("Organization key is required"); | ||
| }); | ||
|
|
||
| it("should throw when keys is null", () => { | ||
| expect( | ||
| () => new OrganizationUserAcceptInitRequest(validToken, validKey, null!, validCollectionName), | ||
| ).toThrow("Organization keys are required"); | ||
| }); | ||
|
|
||
| it("should throw when keys is undefined", () => { | ||
| expect( | ||
| () => | ||
| new OrganizationUserAcceptInitRequest( | ||
| validToken, | ||
| validKey, | ||
| undefined!, | ||
| validCollectionName, | ||
| ), | ||
| ).toThrow("Organization keys are required"); | ||
| }); | ||
|
|
||
| it("should throw when collectionName is empty", () => { | ||
| expect( | ||
| () => new OrganizationUserAcceptInitRequest(validToken, validKey, validKeys, ""), | ||
| ).toThrow("Collection name is required"); | ||
| }); | ||
| }); |
21 changes: 19 additions & 2 deletions
21
...ole/src/common/organization-user/models/requests/organization-user-accept-init.request.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,27 @@ | ||
| // FIXME: Update this file to be type safe and remove this and next line | ||
| // @ts-strict-ignore | ||
| import { OrganizationKeysRequest } from "@bitwarden/common/admin-console/models/request/organization-keys.request"; | ||
|
|
||
| export class OrganizationUserAcceptInitRequest { | ||
| token: string; | ||
| key: string; | ||
| keys: OrganizationKeysRequest; | ||
| collectionName: string; | ||
|
|
||
| constructor(token: string, key: string, keys: OrganizationKeysRequest, collectionName: string) { | ||
| if (!token) { | ||
| throw new Error("Token is required"); | ||
| } | ||
| if (!key) { | ||
| throw new Error("Organization key is required"); | ||
| } | ||
| if (!keys) { | ||
| throw new Error("Organization keys are required"); | ||
| } | ||
| if (!collectionName) { | ||
| throw new Error("Collection name is required"); | ||
| } | ||
| this.token = token; | ||
| this.key = key; | ||
| this.keys = keys; | ||
| this.collectionName = collectionName; | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
libs/common/src/admin-console/models/request/create-provider-organization.request.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { PlanType } from "../../../billing/enums"; | ||
|
|
||
| import { CreateProviderOrganizationRequest } from "./create-provider-organization.request"; | ||
| import { OrganizationKeysRequest } from "./organization-keys.request"; | ||
|
|
||
| describe("CreateProviderOrganizationRequest", () => { | ||
| const validName = "Test Org"; | ||
| const validOwnerEmail = "owner@example.com"; | ||
| const validPlanType = PlanType.TeamsAnnually; | ||
| const validSeats = 10; | ||
| const validKey = "encrypted-org-key"; | ||
| const validKeyPair = new OrganizationKeysRequest("public-key", "encrypted-private-key"); | ||
| const validCollectionName = "encrypted-collection-name"; | ||
|
|
||
| const createRequest = ( | ||
| overrides: Partial<{ | ||
| name: string; | ||
| ownerEmail: string; | ||
| planType: PlanType; | ||
| seats: number; | ||
| key: string; | ||
| keyPair: OrganizationKeysRequest; | ||
| collectionName: string; | ||
| }> = {}, | ||
| ) => { | ||
| return new CreateProviderOrganizationRequest( | ||
| "name" in overrides ? overrides.name! : validName, | ||
| "ownerEmail" in overrides ? overrides.ownerEmail! : validOwnerEmail, | ||
| "planType" in overrides ? overrides.planType! : validPlanType, | ||
| "seats" in overrides ? overrides.seats! : validSeats, | ||
| "key" in overrides ? overrides.key! : validKey, | ||
| "keyPair" in overrides ? overrides.keyPair! : validKeyPair, | ||
| "collectionName" in overrides ? overrides.collectionName! : validCollectionName, | ||
| ); | ||
| }; | ||
|
|
||
| it("should create a request with all required parameters", () => { | ||
| const request = createRequest(); | ||
|
|
||
| expect(request.name).toBe(validName); | ||
| expect(request.ownerEmail).toBe(validOwnerEmail); | ||
| expect(request.planType).toBe(validPlanType); | ||
| expect(request.seats).toBe(validSeats); | ||
| expect(request.key).toBe(validKey); | ||
| expect(request.keyPair).toBe(validKeyPair); | ||
| expect(request.collectionName).toBe(validCollectionName); | ||
| }); | ||
|
|
||
| it("should throw when name is empty", () => { | ||
| expect(() => createRequest({ name: "" })).toThrow("Name is required"); | ||
| }); | ||
|
|
||
| it("should throw when ownerEmail is empty", () => { | ||
| expect(() => createRequest({ ownerEmail: "" })).toThrow("Owner email is required"); | ||
| }); | ||
|
|
||
| it("should throw when planType is null", () => { | ||
| expect(() => createRequest({ planType: null! })).toThrow("Plan type is required"); | ||
| }); | ||
|
|
||
| it("should throw when seats is null", () => { | ||
| expect(() => createRequest({ seats: null! })).toThrow("Seats is required"); | ||
| }); | ||
|
|
||
| it("should throw when key is empty", () => { | ||
| expect(() => createRequest({ key: "" })).toThrow("Organization key is required"); | ||
| }); | ||
|
|
||
| it("should throw when keyPair is null", () => { | ||
| expect(() => createRequest({ keyPair: null! })).toThrow("Organization key pair is required"); | ||
| }); | ||
|
|
||
| it("should throw when keyPair is undefined", () => { | ||
| expect(() => createRequest({ keyPair: undefined })).toThrow( | ||
| "Organization key pair is required", | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw when collectionName is empty", () => { | ||
| expect(() => createRequest({ collectionName: "" })).toThrow("Collection name is required"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libs/common/src/admin-console/models/request/organization-create.request.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { OrganizationCreateRequest } from "./organization-create.request"; | ||
| import { OrganizationKeysRequest } from "./organization-keys.request"; | ||
|
|
||
| describe("OrganizationCreateRequest", () => { | ||
| const validKey = "encrypted-org-key"; | ||
| const validKeys = new OrganizationKeysRequest("public-key", "encrypted-private-key"); | ||
| const validCollectionName = "encrypted-collection-name"; | ||
|
|
||
| it("should create a request with valid key parameters", () => { | ||
| const request = new OrganizationCreateRequest(validKey, validKeys, validCollectionName); | ||
|
|
||
| expect(request.key).toBe(validKey); | ||
| expect(request.keys).toBe(validKeys); | ||
| expect(request.collectionName).toBe(validCollectionName); | ||
| }); | ||
|
|
||
| it("should inherit validation from parent class", () => { | ||
| expect(() => new OrganizationCreateRequest("", validKeys, validCollectionName)).toThrow( | ||
| "Organization key is required", | ||
| ); | ||
|
|
||
| expect(() => new OrganizationCreateRequest(validKey, null!, validCollectionName)).toThrow( | ||
| "Organization keys are required", | ||
| ); | ||
|
|
||
| expect(() => new OrganizationCreateRequest(validKey, validKeys, "")).toThrow( | ||
| "Collection name is required", | ||
| ); | ||
| }); | ||
|
|
||
| it("should allow setting payment fields after construction", () => { | ||
| const request = new OrganizationCreateRequest(validKey, validKeys, validCollectionName); | ||
| request.paymentToken = "token"; | ||
|
|
||
| expect(request.paymentToken).toBe("token"); | ||
| }); | ||
| }); |
6 changes: 2 additions & 4 deletions
6
libs/common/src/admin-console/models/request/organization-create.request.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,9 @@ | ||
| // FIXME: Update this file to be type safe and remove this and next line | ||
| // @ts-strict-ignore | ||
| import { PaymentMethodType } from "../../../billing/enums"; | ||
| import { OrganizationNoPaymentMethodCreateRequest } from "../../../billing/models/request/organization-no-payment-method-create-request"; | ||
|
|
||
| export class OrganizationCreateRequest extends OrganizationNoPaymentMethodCreateRequest { | ||
| paymentMethodType: PaymentMethodType; | ||
| paymentToken: string; | ||
| paymentMethodType!: PaymentMethodType; | ||
| paymentToken: string = ""; | ||
| skipTrial?: boolean; | ||
| coupons?: string[]; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.