Commit 291e6dad authored by Tomas Vik (OOO back on 2026-08-31)'s avatar Tomas Vik (OOO back on 2026-08-31) 🌴
Browse files

fix: remove tokens from secret storage when we remove account

parent 1dc4e125
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ describe('AccountService', () => {
    await accountService.removeAccount(account.id);

    expect(accountService.getAllAccounts()).toHaveLength(0);
    expect(await secrets.get('gitlab-tokens')).toBe('{}');
  });

  describe('account from environment variable', () => {
+14 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ export class AccountService {
    this.onDidChangeEmitter.fire();
  }

  async #storeToken(accountId: string, token: string) {
  async #validateSecretsAreUpToDate() {
    assert(this.context);
    const storedSecrets = await getSecrets(this.context);
    assert.deepStrictEqual(
@@ -118,6 +118,18 @@ export class AccountService {
      storedSecrets,
      'The GitLab secrets stored in your keychain have changed. (Maybe another instance of VS Code or maybe OS synchronizing keychains.) Please restart VS Code.',
    );
  }

  async #removeToken(accountId: string) {
    assert(this.context);
    await this.#validateSecretsAreUpToDate();
    delete this.secrets[accountId];
    await this.context.secrets.store(SECRETS_KEY, JSON.stringify(this.secrets));
  }

  async #storeToken(accountId: string, token: string) {
    assert(this.context);
    await this.#validateSecretsAreUpToDate();
    const secrets = { ...this.secrets, [accountId]: { token } };
    await this.context.secrets.store(SECRETS_KEY, JSON.stringify(secrets));
    this.secrets = secrets;
@@ -129,6 +141,7 @@ export class AccountService {
    delete accountMap[accountId];

    await this.context.globalState.update(ACCOUNTS_KEY, accountMap);
    await this.#removeToken(accountId);
    this.onDidChangeEmitter.fire();
  }