Skip to content

Commit ee5fd2d

Browse files
committed
fix(sso): report the row the trust grant actually matched
The grant returned true once it found the proof, without checking that the provider UPDATE matched anything, so its boolean did not always mean what callers read it to mean. It now reports the matched row.
1 parent eedc242 commit ee5fd2d

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

apps/sim/app/api/auth/sso/register/route.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ describe('POST /api/auth/sso/register', () => {
116116
mockSecureFetchWithPinnedIP.mockRejectedValue(new Error('discovery not mocked for this test'))
117117
mockRegisterSSOProvider.mockResolvedValue({ id: 'row-1', providerId: 'acme-oidc' })
118118
mockUpdateSSOProvider.mockResolvedValue({ providerId: 'acme-oidc' })
119+
// The trust UPDATE reports the row it matched; by default the provider exists.
120+
dbChainMockFns.returning.mockResolvedValue([{ id: 'provider-row' }])
119121
// Default: the org has already verified the domain, so the ownership gate
120122
// passes and each test exercises the logic beyond it. A successful org-scoped
121123
// registration reads it three times: the fail-fast entry gate, the

apps/sim/app/api/auth/sso/register/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,12 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
680680
.for('share')
681681
if (!proof) return false
682682

683-
await tx.update(ssoProvider).set({ domainVerified: true }).where(ownerClause)
684-
return true
683+
const granted = await tx
684+
.update(ssoProvider)
685+
.set({ domainVerified: true })
686+
.where(ownerClause)
687+
.returning({ id: ssoProvider.id })
688+
return granted.length > 0
685689
})
686690
}
687691

0 commit comments

Comments
 (0)