Skip to content

Commit 84d23f5

Browse files
committed
test(credentials): guard a named reconnect region against the stored one
Fold the named-region reconnect case into the blank-reconnect table as a contrast row on a credential stored in eu, so it fails if a reconnect always keeps the stored region.
1 parent 0e9aa24 commit 84d23f5

1 file changed

Lines changed: 9 additions & 27 deletions

File tree

‎apps/sim/lib/credentials/orchestration/index.test.ts‎

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,13 @@ describe('performUpdateCredential — service-account secret rotation', () => {
399399
)
400400
})
401401

402-
it.each([undefined, ' '])(
403-
'keeps the stored region of a token credential when a reconnect leaves it blank (%j)',
404-
async (domain) => {
402+
it.each([
403+
{ domain: undefined, expected: 'eu' },
404+
{ domain: ' ', expected: 'eu' },
405+
{ domain: 'federal', expected: 'federal' },
406+
])(
407+
'sends region $expected when a token credential stored on eu is reconnected with $domain',
408+
async ({ domain, expected }) => {
405409
mockCredential({ providerId: 'launchdarkly-service-account', displayName: 'Flags (eu)' })
406410
mockStoredBlob({
407411
type: 'token_service_account',
@@ -412,7 +416,7 @@ describe('performUpdateCredential — service-account secret rotation', () => {
412416
mockVerifyAndBuildServiceAccountSecret.mockResolvedValue({
413417
providerId: 'launchdarkly-service-account',
414418
encryptedServiceAccountKey: 'new-cipher',
415-
displayName: 'LaunchDarkly (eu)',
419+
displayName: `LaunchDarkly (${expected})`,
416420
auditMetadata: {},
417421
})
418422

@@ -425,33 +429,11 @@ describe('performUpdateCredential — service-account secret rotation', () => {
425429

426430
expect(mockVerifyAndBuildServiceAccountSecret).toHaveBeenCalledWith(
427431
'launchdarkly-service-account',
428-
expect.objectContaining({ apiToken: 'new-token', domain: 'eu' })
432+
expect.objectContaining({ apiToken: 'new-token', domain: expected })
429433
)
430434
}
431435
)
432436

433-
it('moves a token credential to the region a reconnect names', async () => {
434-
mockCredential({ providerId: 'launchdarkly-service-account', displayName: 'Flags' })
435-
mockVerifyAndBuildServiceAccountSecret.mockResolvedValue({
436-
providerId: 'launchdarkly-service-account',
437-
encryptedServiceAccountKey: 'new-cipher',
438-
displayName: 'LaunchDarkly (federal)',
439-
auditMetadata: {},
440-
})
441-
442-
await performUpdateCredential({
443-
credentialId: 'cred-1',
444-
userId: 'user-1',
445-
apiToken: 'new-token',
446-
domain: 'federal',
447-
})
448-
449-
expect(mockVerifyAndBuildServiceAccountSecret).toHaveBeenCalledWith(
450-
'launchdarkly-service-account',
451-
expect.objectContaining({ domain: 'federal' })
452-
)
453-
})
454-
455437
it('fails the reconnect when the stored secret cannot be decrypted', async () => {
456438
mockCredential()
457439
queueTableRows(schemaMock.credential, [{ key: 'stored-cipher' }])

0 commit comments

Comments
 (0)