Skip to content

Commit ced97a4

Browse files
authored
cli status command shows locked status when unlocked (bitwarden#17708)
1 parent ba1c74b commit ced97a4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

apps/cli/src/commands/status.command.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// FIXME: Update this file to be type safe and remove this and next line
2-
// @ts-strict-ignore
31
import { firstValueFrom, map } from "rxjs";
42

53
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
64
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
75
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
86
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
7+
import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service";
98
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
9+
import { UserId } from "@bitwarden/user-core";
1010

1111
import { Response } from "../models/response";
1212
import { TemplateResponse } from "../models/response/template.response";
@@ -17,16 +17,17 @@ export class StatusCommand {
1717
private syncService: SyncService,
1818
private accountService: AccountService,
1919
private authService: AuthService,
20+
private userAutoUnlockKeyService: UserAutoUnlockKeyService,
2021
) {}
2122

2223
async run(): Promise<Response> {
2324
try {
2425
const baseUrl = await this.baseUrl();
25-
const status = await this.status();
2626
const lastSync = await this.syncService.getLastSync();
2727
const [userId, email] = await firstValueFrom(
2828
this.accountService.activeAccount$.pipe(map((a) => [a?.id, a?.email])),
2929
);
30+
const status = await this.status(userId);
3031

3132
return Response.success(
3233
new TemplateResponse({
@@ -42,12 +43,18 @@ export class StatusCommand {
4243
}
4344
}
4445

45-
private async baseUrl(): Promise<string> {
46+
private async baseUrl(): Promise<string | undefined> {
4647
const env = await firstValueFrom(this.envService.environment$);
4748
return env.getUrls().base;
4849
}
4950

50-
private async status(): Promise<"unauthenticated" | "locked" | "unlocked"> {
51+
private async status(
52+
userId: UserId | undefined,
53+
): Promise<"unauthenticated" | "locked" | "unlocked"> {
54+
if (userId != null) {
55+
await this.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(userId);
56+
}
57+
5158
const authStatus = await this.authService.getAuthStatus();
5259
if (authStatus === AuthenticationStatus.Unlocked) {
5360
return "unlocked";

apps/cli/src/oss-serve-configurator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export class OssServeConfigurator {
122122
this.serviceContainer.syncService,
123123
this.serviceContainer.accountService,
124124
this.serviceContainer.authService,
125+
this.serviceContainer.userAutoUnlockKeyService,
125126
);
126127
this.deleteCommand = new DeleteCommand(
127128
this.serviceContainer.cipherService,

apps/cli/src/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ export class Program extends BaseProgram {
524524
this.serviceContainer.syncService,
525525
this.serviceContainer.accountService,
526526
this.serviceContainer.authService,
527+
this.serviceContainer.userAutoUnlockKeyService,
527528
);
528529
const response = await command.run();
529530
this.processResponse(response);

0 commit comments

Comments
 (0)