Skip to content

Commit 4de75bc

Browse files
fix: disable existing profile check when adding profile
Problem: When adding an auth profile, there is a possible race condition where the global store (memento) is not synchronized on a following read. The scenario we were hitting was signing out of a builder id, then signing in with a new one. It would fail since the old builder id would still be in the memento. Soltion: Do not check if the profile already exists, just overwrite it. Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 743cf11 commit 4de75bc

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/credentials/auth.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ export class ProfileStore {
199199
public async addProfile(id: string, profile: SsoProfile): Promise<StoredProfile<SsoProfile>>
200200
public async addProfile(id: string, profile: IamProfile): Promise<StoredProfile<IamProfile>>
201201
public async addProfile(id: string, profile: Profile): Promise<StoredProfile> {
202-
if (this.getProfile(id) !== undefined) {
203-
throw new Error(`Profile already exists: ${id}`)
204-
}
205-
206202
return this.putProfile(id, this.initMetadata(profile))
207203
}
208204

src/test/credentials/auth.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ describe('Auth', function () {
134134
assert.strictEqual(auth.activeConnection, undefined)
135135
})
136136

137-
it('throws when creating a duplicate connection', async function () {
138-
await auth.createConnection(ssoProfile)
139-
await assert.rejects(() => auth.createConnection(ssoProfile))
137+
it('does not throw when creating a duplicate connection', async function () {
138+
const initialConn = await auth.createConnection({ ...ssoProfile, scopes: ['a'] })
139+
const duplicateConn = await auth.createConnection({ ...ssoProfile, scopes: ['b'] })
140+
assert.deepStrictEqual(initialConn.scopes, ['a'])
141+
assert.deepStrictEqual(duplicateConn.scopes, ['a', 'b'])
140142
})
141143

142144
it('throws when using an invalid connection that was deleted', async function () {

0 commit comments

Comments
 (0)