Skip to content

Commit 066bedf

Browse files
committed
fix(auth): address review on test randomness, the SSO callbackUrl default, and an unused type export
1 parent 5b72337 commit 066bedf

7 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎apps/docs/content/docs/cli/organizations.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ sim organizations sso providers save [options]
926926
| `--jwks-endpoint <value>` | No | Optional signing-key endpoint; otherwise resolved through issuer discovery. Available when providerType is oidc. |
927927
| `--entry-point <value>` | Conditional | Identity provider SAML sign-in endpoint. Available when providerType is saml. Required when providerType is saml. |
928928
| `--cert <value>` | Conditional | Identity provider signing certificate. Available when providerType is saml. Required when providerType is saml. |
929-
| `--callback-url <value>` | No | SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL. Available when providerType is saml. |
929+
| `--callback-url <value>` | No | SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL, and a provider already on the legacy `/sso/saml2/callback` URL keeps it. Available when providerType is saml. |
930930
| `--audience <value>` | No | SAML audience; omission preserves the saved value. Available when providerType is saml. |
931931
| `--want-assertions-signed` | No | Require signed assertions; omission preserves the saved value. Available when providerType is saml. |
932932
| `--no-want-assertions-signed` | No | Send --want-assertions-signed as false. |

‎apps/docs/content/docs/cli/reference.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4193,7 +4193,7 @@ sim organizations sso providers save [options]
41934193
| `--jwks-endpoint <value>` | No | Optional signing-key endpoint; otherwise resolved through issuer discovery. Available when providerType is oidc. |
41944194
| `--entry-point <value>` | Conditional | Identity provider SAML sign-in endpoint. Available when providerType is saml. Required when providerType is saml. |
41954195
| `--cert <value>` | Conditional | Identity provider signing certificate. Available when providerType is saml. Required when providerType is saml. |
4196-
| `--callback-url <value>` | No | SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL. Available when providerType is saml. |
4196+
| `--callback-url <value>` | No | SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL, and a provider already on the legacy `/sso/saml2/callback` URL keeps it. Available when providerType is saml. |
41974197
| `--audience <value>` | No | SAML audience; omission preserves the saved value. Available when providerType is saml. |
41984198
| `--want-assertions-signed` | No | Require signed assertions; omission preserves the saved value. Available when providerType is saml. |
41994199
| `--no-want-assertions-signed` | No | Send --want-assertions-signed as false. |

‎apps/docs/openapi-v2-resources.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23741,7 +23741,7 @@
2374123741
"description": "Identity provider signing certificate."
2374223742
},
2374323743
"callbackUrl": {
23744-
"description": "SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL.",
23744+
"description": "SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL, and a provider already on the legacy `/sso/saml2/callback` URL keeps it.",
2374523745
"type": "string",
2374623746
"maxLength": 2048,
2374723747
"format": "uri"

‎apps/sim/app/api/auth/oauth2/token/route.integration.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { randomBytes } from 'node:crypto'
21
import { db } from '@sim/db'
32
import * as schema from '@sim/db/schema'
43
import { envFlagsMock } from '@sim/testing/mocks/env-flags.mock'
54
import { requestUtilsMockFns } from '@sim/testing/mocks/request.mock'
65
import { generateId } from '@sim/utils/id'
6+
import { generateRandomBytes, generateRandomHex, randomInt } from '@sim/utils/random'
77
import { makeSignature, symmetricEncrypt } from 'better-auth/crypto'
88
import { eq, inArray, like, sql } from 'drizzle-orm'
99
import { NextRequest } from 'next/server'
@@ -47,7 +47,7 @@ describe('OAuth token route in PostgreSQL', () => {
4747
async (redirectUri) => {
4848
const POST = (request: NextRequest) => tokenRoute(request, {})
4949
/** A fresh TEST-NET-2 address per case, so reruns never draw on an earlier run's bucket. */
50-
const clientIp = `198.51.100.${(randomBytes(1)[0] % 254) + 1}`
50+
const clientIp = `198.51.100.${randomInt(1, 255)}`
5151
requestUtilsMockFns.mockGetClientIp.mockReturnValue(clientIp)
5252
const userId = generateId()
5353
const clientId = generateId()
@@ -69,7 +69,7 @@ describe('OAuth token route in PostgreSQL', () => {
6969
})
7070

7171
const issueCode = async () => {
72-
const verifier = randomBytes(32).toString('base64url')
72+
const verifier = Buffer.from(generateRandomBytes(32)).toString('base64url')
7373
const challenge = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier))
7474
const url = new URL('/api/auth/oauth2/authorize', baseUrl)
7575
url.search = new URLSearchParams({
@@ -268,7 +268,7 @@ describe('OAuth token route in PostgreSQL', () => {
268268
'exchanges a code and refreshes for a confidential client registered for %s',
269269
async (method) => {
270270
const POST = (request: NextRequest) => tokenRoute(request, {})
271-
const clientIp = `203.0.113.${(randomBytes(1)[0] % 254) + 1}`
271+
const clientIp = `203.0.113.${randomInt(1, 255)}`
272272
requestUtilsMockFns.mockGetClientIp.mockReturnValue(clientIp)
273273
const baseUrl = 'https://test.sim.ai'
274274
const redirectUri = 'https://client.example/callback'
@@ -339,7 +339,7 @@ describe('OAuth token route in PostgreSQL', () => {
339339
updatedAt: now,
340340
})
341341

342-
const verifier = randomBytes(32).toString('base64url')
342+
const verifier = Buffer.from(generateRandomBytes(32)).toString('base64url')
343343
const challenge = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier))
344344
const authorizeUrl = new URL('/api/auth/oauth2/authorize', baseUrl)
345345
authorizeUrl.search = new URLSearchParams({
@@ -391,7 +391,7 @@ describe('OAuth token route in PostgreSQL', () => {
391391
const exchangeToken = (request: NextRequest) => tokenRoute(request, {})
392392
const revokeToken = (request: NextRequest) => revokeRoute(request, {})
393393

394-
const testId = randomBytes(8).toString('hex')
394+
const testId = generateRandomHex(16)
395395
const userId = `oauth-route-test-user-${testId}`
396396
const sessionId = `oauth-route-test-session-${testId}`
397397
const sessionToken = `oauth-route-test-session-token-${testId}`

‎apps/sim/lib/api/contracts/v2/sso.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const v2SaveSsoProviderBodySchema = z.discriminatedUnion('providerType', [
183183
.max(2048)
184184
.optional()
185185
.describe(
186-
'SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL.'
186+
'SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL, and a provider already on the legacy `/sso/saml2/callback` URL keeps it.'
187187
),
188188
audience: z
189189
.string()

‎apps/sim/lib/auth/oauth-protocol-request.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { truncate } from '@sim/utils/string'
22
import { NextRequest, NextResponse } from 'next/server'
33
import type { OAuthClientCredentials, OAuthProtocolErrorCode } from '@/lib/auth/oauth-token-family'
44

5-
export interface ParsedOAuthForm {
5+
interface ParsedOAuthForm {
66
form: URLSearchParams
77
credentials: OAuthClientCredentials | null
88
rawBody: string

‎packages/sim-cli/src/generated/v2-api.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23523,7 +23523,7 @@ export const V2_OPERATIONS = {
2352323523
callbackUrl: {
2352423524
kind: 'string',
2352523525
describe:
23526-
'SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL. Available when providerType is saml.',
23526+
'SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL, and a provider already on the legacy `/sso/saml2/callback` URL keeps it. Available when providerType is saml.',
2352723527
},
2352823528
audience: {
2352923529
kind: 'string',
@@ -23671,7 +23671,7 @@ export const V2_OPERATIONS = {
2367123671
callbackUrl: {
2367223672
kind: 'string',
2367323673
describe:
23674-
'SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL.',
23674+
'SAML ACS URL advertised to the identity provider; defaults to this provider’s Sim ACS URL, and a provider already on the legacy `/sso/saml2/callback` URL keeps it.',
2367523675
},
2367623676
audience: {
2367723677
kind: 'string',

0 commit comments

Comments
 (0)