From ced97a4467de3f2eb8d0fb4a902fce9daea1ae33 Mon Sep 17 00:00:00 2001 From: Maciej Zieniuk <167752252+mzieniukbw@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:19:11 +0100 Subject: [PATCH] cli status command shows locked status when unlocked (#17708) --- apps/cli/src/commands/status.command.ts | 17 ++++++++++++----- apps/cli/src/oss-serve-configurator.ts | 1 + apps/cli/src/program.ts | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/cli/src/commands/status.command.ts b/apps/cli/src/commands/status.command.ts index f7fc8541a5f..7ae1e657630 100644 --- a/apps/cli/src/commands/status.command.ts +++ b/apps/cli/src/commands/status.command.ts @@ -1,12 +1,12 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore import { firstValueFrom, map } from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; +import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; +import { UserId } from "@bitwarden/user-core"; import { Response } from "../models/response"; import { TemplateResponse } from "../models/response/template.response"; @@ -17,16 +17,17 @@ export class StatusCommand { private syncService: SyncService, private accountService: AccountService, private authService: AuthService, + private userAutoUnlockKeyService: UserAutoUnlockKeyService, ) {} async run(): Promise { try { const baseUrl = await this.baseUrl(); - const status = await this.status(); const lastSync = await this.syncService.getLastSync(); const [userId, email] = await firstValueFrom( this.accountService.activeAccount$.pipe(map((a) => [a?.id, a?.email])), ); + const status = await this.status(userId); return Response.success( new TemplateResponse({ @@ -42,12 +43,18 @@ export class StatusCommand { } } - private async baseUrl(): Promise { + private async baseUrl(): Promise { const env = await firstValueFrom(this.envService.environment$); return env.getUrls().base; } - private async status(): Promise<"unauthenticated" | "locked" | "unlocked"> { + private async status( + userId: UserId | undefined, + ): Promise<"unauthenticated" | "locked" | "unlocked"> { + if (userId != null) { + await this.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(userId); + } + const authStatus = await this.authService.getAuthStatus(); if (authStatus === AuthenticationStatus.Unlocked) { return "unlocked"; diff --git a/apps/cli/src/oss-serve-configurator.ts b/apps/cli/src/oss-serve-configurator.ts index dbe17224d07..e8f5e6acd9a 100644 --- a/apps/cli/src/oss-serve-configurator.ts +++ b/apps/cli/src/oss-serve-configurator.ts @@ -122,6 +122,7 @@ export class OssServeConfigurator { this.serviceContainer.syncService, this.serviceContainer.accountService, this.serviceContainer.authService, + this.serviceContainer.userAutoUnlockKeyService, ); this.deleteCommand = new DeleteCommand( this.serviceContainer.cipherService, diff --git a/apps/cli/src/program.ts b/apps/cli/src/program.ts index 3e5b5678629..b0c94b19ae9 100644 --- a/apps/cli/src/program.ts +++ b/apps/cli/src/program.ts @@ -524,6 +524,7 @@ export class Program extends BaseProgram { this.serviceContainer.syncService, this.serviceContainer.accountService, this.serviceContainer.authService, + this.serviceContainer.userAutoUnlockKeyService, ); const response = await command.run(); this.processResponse(response);