-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[PM-24618] Integrate CLI sends with server branch #18106
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
harr1424
wants to merge
25
commits into
main
Choose a base branch
from
PM-24618-CLI-reveal-email-CLI-flag
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.
+882
โ38
Open
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6983929
WIP explore existing Send attributes and logic
harr1424 68323dd
Merge branch 'main' into PM-24618-CLI-reveal-email-CLI-flag
harr1424 913a6ad
WIP progress checkpoint Send refactor
harr1424 e8794cf
send creation integrated with server and returns object containing emโฆ
harr1424 e2659d6
Claude! Review my code!
harr1424 705bc2b
WIP respond to Claude & add tests
harr1424 5ea4414
Merge branch 'main' into PM-24618-CLI-reveal-email-CLI-flag
harr1424 0fd81fa
improve mutual exclusion check for create with emails and password
harr1424 07eb16d
respond to review comments
harr1424 51f920d
Merge branch 'main' into PM-24618-CLI-reveal-email-CLI-flag
harr1424 f31aca2
[PM-21774] Adjust icon and tooltip for protected Sends on the Sends lโฆ
mcamirault 4d486aa
Merge branch 'main' into tools/pm-21774/send-list-page-updates
mcamirault 94b4b11
[PM-21774] Update Sent table UI stories
mcamirault 06bc0d5
[PM-21774] Fix Send table UI story
mcamirault 0f611a7
[PM-21774] Merge changes from main and resolve conflicts
mcamirault 70a222b
merge origin/tools/pm-21774/send-list-page-updates
harr1424 42691b7
Merge remote-tracking branch 'origin/main' into PM-23108-CLI-Add-emaiโฆ
harr1424 ff81b34
fix eslint issue
harr1424 c8c7f8b
resolve eslint errors
harr1424 02a3b6b
Merge branch 'main' into PM-24618-CLI-reveal-email-CLI-flag
harr1424 d27a9b4
fix strict typing errors
harr1424 6014a7d
Merge branch 'main' into PM-24618-CLI-reveal-email-CLI-flag
harr1424 347784d
gate usage of send email field in create and edit behind SendEmailOTPโฆ
harr1424 aa241bf
re-implement feature flag using existing pattern
harr1424 86f1c6f
trim password whitespace in edit command
harr1424 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
365 changes: 365 additions & 0 deletions
365
apps/cli/src/tools/send/commands/create.command.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,365 @@ | ||
| // FIXME: Update this file to be type safe and remove this and next line | ||
| // @ts-strict-ignore | ||
| import { mock } from "jest-mock-extended"; | ||
| import { of } from "rxjs"; | ||
|
|
||
| import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
| import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; | ||
| import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; | ||
| import { mockAccountInfoWith } from "@bitwarden/common/spec"; | ||
| import { SendType } from "@bitwarden/common/tools/send/enums/send-type"; | ||
| import { AuthType } from "@bitwarden/common/tools/send/models/domain/send"; | ||
| import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; | ||
| import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; | ||
| import { UserId } from "@bitwarden/user-core"; | ||
|
|
||
| import { SendCreateCommand } from "./create.command"; | ||
|
|
||
| describe("SendCreateCommand", () => { | ||
| let command: SendCreateCommand; | ||
|
|
||
| const sendService = mock<SendService>(); | ||
| const environmentService = mock<EnvironmentService>(); | ||
| const sendApiService = mock<SendApiService>(); | ||
| const accountProfileService = mock<BillingAccountProfileStateService>(); | ||
| const accountService = mock<AccountService>(); | ||
|
|
||
| const activeAccount = { | ||
| id: "user-id" as UserId, | ||
| ...mockAccountInfoWith({ | ||
| email: "[email protected]", | ||
| name: "User", | ||
| }), | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
|
|
||
| accountService.activeAccount$ = of(activeAccount); | ||
| accountProfileService.hasPremiumFromAnySource$.mockReturnValue(of(false)); | ||
| environmentService.environment$ = of({ | ||
| getWebVaultUrl: () => "https://vault.bitwarden.com", | ||
| } as any); | ||
|
|
||
| command = new SendCreateCommand( | ||
| sendService, | ||
| environmentService, | ||
| sendApiService, | ||
| accountProfileService, | ||
| accountService, | ||
| ); | ||
| }); | ||
|
|
||
| describe("authType inference", () => { | ||
| const futureDate = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000); | ||
|
|
||
| describe("with CLI flags", () => { | ||
| it("should set authType to Email when emails are provided via CLI", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| email: ["[email protected]"], | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", emails: "[email protected]", authType: AuthType.Email } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| expect(sendService.encrypt).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: SendType.Text, | ||
| }), | ||
| null, | ||
| undefined, | ||
| ); | ||
| }); | ||
|
|
||
| it("should set authType to Password when password is provided via CLI", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| password: "testPassword123", | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", authType: AuthType.Password } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| expect(sendService.encrypt).toHaveBeenCalledWith( | ||
| expect.any(Object), | ||
| null as any, | ||
| "testPassword123", | ||
| ); | ||
| }); | ||
|
|
||
| it("should set authType to None when neither emails nor password provided", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| }; | ||
|
|
||
| const cmdOptions = {}; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", authType: AuthType.None } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| expect(sendService.encrypt).toHaveBeenCalledWith(expect.any(Object), null, undefined); | ||
| }); | ||
|
|
||
| it("should return error when both emails and password provided via CLI", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| email: ["[email protected]"], | ||
| password: "testPassword123", | ||
| }; | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(false); | ||
| expect(response.message).toBe("--password and --emails are mutually exclusive."); | ||
| }); | ||
| }); | ||
|
|
||
| describe("with JSON input", () => { | ||
| it("should set authType to Email when emails provided in JSON", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| emails: ["[email protected]", "[email protected]"], | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { | ||
| id: "send-id", | ||
| emails: "[email protected],[email protected]", | ||
| authType: AuthType.Email, | ||
| } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, {}); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| }); | ||
|
|
||
| it("should set authType to Password when password provided in JSON", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| password: "jsonPassword123", | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", authType: AuthType.Password } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, {}); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| }); | ||
|
|
||
| it("should return error when both emails and password provided in JSON", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| emails: ["[email protected]"], | ||
| password: "jsonPassword123", | ||
| }; | ||
|
|
||
| const response = await command.run(requestJson, {}); | ||
|
|
||
| expect(response.success).toBe(false); | ||
| expect(response.message).toBe("--password and --emails are mutually exclusive."); | ||
| }); | ||
| }); | ||
|
|
||
| describe("with mixed CLI and JSON input", () => { | ||
| it("should return error when CLI emails combined with JSON password", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| password: "jsonPassword123", | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| email: ["[email protected]"], | ||
| }; | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(false); | ||
| expect(response.message).toBe("--password and --emails are mutually exclusive."); | ||
| }); | ||
|
|
||
| it("should return error when CLI password combined with JSON emails", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| emails: ["[email protected]"], | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| password: "cliPassword123", | ||
| }; | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(false); | ||
| expect(response.message).toBe("--password and --emails are mutually exclusive."); | ||
| }); | ||
|
|
||
| it("should use CLI value when JSON has different value of same type", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| emails: ["[email protected]"], | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| email: ["[email protected]"], | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", emails: "[email protected]", authType: AuthType.Email } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("edge cases", () => { | ||
| it("should set authType to None when emails array is empty", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| emails: [] as string[], | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", authType: AuthType.None } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, {}); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| }); | ||
|
|
||
| it("should set authType to None when password is empty string", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| password: "", | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", authType: AuthType.None } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| }); | ||
|
|
||
| it("should set authType to None when password is whitespace only", async () => { | ||
| const requestJson = { | ||
| type: SendType.Text, | ||
| text: { text: "test content", hidden: false }, | ||
| deletionDate: futureDate, | ||
| }; | ||
|
|
||
| const cmdOptions = { | ||
| password: " ", | ||
| }; | ||
|
|
||
| sendService.encrypt.mockResolvedValue([ | ||
| { id: "send-id", authType: AuthType.None } as any, | ||
| null as any, | ||
| ]); | ||
| sendApiService.save.mockResolvedValue(undefined as any); | ||
| sendService.getFromState.mockResolvedValue({ | ||
| decrypt: jest.fn().mockResolvedValue({}), | ||
| } as any); | ||
|
|
||
| const response = await command.run(requestJson, cmdOptions); | ||
|
|
||
| expect(response.success).toBe(true); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
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.