Skip to content

Commit e04dfa3

Browse files
committed
chore(credentials): satisfy test-pattern, unused-export, and test-type audits
1 parent 471e851 commit e04dfa3

5 files changed

Lines changed: 21 additions & 25 deletions

File tree

‎apps/sim/lib/credentials/aws-service-account.server.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import { AWS_SERVICE_ACCOUNT_PROVIDER_ID } from '@/lib/oauth/types'
3737
* this credential's subject and exchanges it with STS for the customer's role.
3838
*/
3939

40-
export const AWS_WORKLOAD_IDENTITY_AUDIENCE = WORKLOAD_IDENTITY_AUDIENCES.aws
41-
export const AWS_CREDENTIAL_SECRET_TYPE = 'aws_credential_v1' as const
40+
const AWS_WORKLOAD_IDENTITY_AUDIENCE = WORKLOAD_IDENTITY_AUDIENCES.aws
41+
const AWS_CREDENTIAL_SECRET_TYPE = 'aws_credential_v1' as const
4242

4343
const ROLE_ARN_PATTERN =
4444
/^arn:aws(?:-cn|-us-gov|-iso[a-z-]*)?:iam::\d{12}:role\/[\w+=,.@/-]{1,512}$/

‎apps/sim/lib/credentials/databricks-service-account.server.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import { DATABRICKS_SERVICE_ACCOUNT_PROVIDER_ID } from '@/lib/oauth/types'
3131
* which reach the tools as `accessToken` and `domain`.
3232
*/
3333

34-
export const DATABRICKS_CREDENTIAL_SECRET_TYPE = 'databricks_credential_v1' as const
35-
export const DATABRICKS_WORKLOAD_IDENTITY_AUDIENCE = WORKLOAD_IDENTITY_AUDIENCES.databricks
34+
const DATABRICKS_CREDENTIAL_SECRET_TYPE = 'databricks_credential_v1' as const
35+
const DATABRICKS_WORKLOAD_IDENTITY_AUDIENCE = WORKLOAD_IDENTITY_AUDIENCES.databricks
3636

3737
const REQUEST_TIMEOUT_MS = 15_000
3838
const CLIENT_ID_PATTERN = /^[A-Za-z0-9-]{8,128}$/
@@ -92,7 +92,7 @@ const storedConfigSchema = z.discriminatedUnion('authType', [
9292
z.object(oidcShape).strict(),
9393
])
9494

95-
export type DatabricksCredentialConfig = z.infer<typeof storedConfigSchema>
95+
type DatabricksCredentialConfig = z.infer<typeof storedConfigSchema>
9696

9797
const submittedConfigSchema = z.discriminatedUnion('authType', [
9898
patSchema,
@@ -142,7 +142,7 @@ async function requestWorkspaceToken(
142142
}
143143

144144
/** A bearer token for the configured workspace. */
145-
export async function resolveDatabricksAccessToken(
145+
async function resolveDatabricksAccessToken(
146146
config: DatabricksCredentialConfig,
147147
owner: WorkloadIdentityOwner
148148
): Promise<string> {

‎apps/sim/lib/credentials/workload-identity/issuer.test.ts‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { createLocalJWKSet, decodeProtectedHeader, jwtVerify } from 'jose'
66
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
77
import { env } from '@/lib/core/config/env'
88

9-
const mutableEnv = env as Record<string, string | undefined>
9+
/** The shared env mock is mutable at runtime; its declared type is the real readonly env. */
10+
function setEnv(key: string, value: string | undefined) {
11+
Reflect.set(env, key, value)
12+
}
1013

1114
function rsaPem() {
1215
return generateKeyPairSync('rsa', { modulusLength: 2048 }).privateKey.export({
@@ -22,13 +25,13 @@ async function loadIssuer() {
2225

2326
describe('workload identity issuer', () => {
2427
beforeEach(() => {
25-
mutableEnv.WORKLOAD_IDENTITY_SIGNING_KEY = rsaPem()
28+
setEnv('WORKLOAD_IDENTITY_SIGNING_KEY', rsaPem())
2629
})
2730

2831
afterEach(() => {
29-
mutableEnv.WORKLOAD_IDENTITY_SIGNING_KEY = undefined
30-
mutableEnv.WORKLOAD_IDENTITY_PREVIOUS_KEY = undefined
31-
mutableEnv.WORKLOAD_IDENTITY_ISSUER = undefined
32+
setEnv('WORKLOAD_IDENTITY_SIGNING_KEY', undefined)
33+
setEnv('WORKLOAD_IDENTITY_PREVIOUS_KEY', undefined)
34+
setEnv('WORKLOAD_IDENTITY_ISSUER', undefined)
3235
})
3336

3437
it('mints a token a relying party verifies with the published JWKS and discovery document', async () => {
@@ -67,16 +70,16 @@ describe('workload identity issuer', () => {
6770

6871
it('keeps verifying tokens signed by the previous key during rotation', async () => {
6972
const previousKey = rsaPem()
70-
mutableEnv.WORKLOAD_IDENTITY_SIGNING_KEY = previousKey
73+
setEnv('WORKLOAD_IDENTITY_SIGNING_KEY', previousKey)
7174
const before = await loadIssuer()
7275
const oldToken = await before.mintWorkloadIdentityToken({
7376
subject: 'sim:workspace:ws-1:credential:abc123def456',
7477
audience: 'sts.amazonaws.com',
7578
owner: { workspaceId: 'ws-1' },
7679
})
7780

78-
mutableEnv.WORKLOAD_IDENTITY_SIGNING_KEY = rsaPem()
79-
mutableEnv.WORKLOAD_IDENTITY_PREVIOUS_KEY = previousKey
81+
setEnv('WORKLOAD_IDENTITY_SIGNING_KEY', rsaPem())
82+
setEnv('WORKLOAD_IDENTITY_PREVIOUS_KEY', previousKey)
8083
const after = await loadIssuer()
8184
const jwks = await after.getWorkloadIdentityJwks()
8285

@@ -87,7 +90,7 @@ describe('workload identity issuer', () => {
8790
})
8891

8992
it('publishes nothing and refuses to sign when no signing key is configured', async () => {
90-
mutableEnv.WORKLOAD_IDENTITY_SIGNING_KEY = undefined
93+
setEnv('WORKLOAD_IDENTITY_SIGNING_KEY', undefined)
9194
const issuer = await loadIssuer()
9295
const { workloadIdentityDiscoveryResponse, workloadIdentityJwksResponse } = await import(
9396
'@/lib/credentials/workload-identity/responses'
@@ -106,7 +109,7 @@ describe('workload identity issuer', () => {
106109
})
107110

108111
it('uses the pinned issuer URL when one is configured', async () => {
109-
mutableEnv.WORKLOAD_IDENTITY_ISSUER = 'https://oidc.example.com/workload/'
112+
setEnv('WORKLOAD_IDENTITY_ISSUER', 'https://oidc.example.com/workload/')
110113
const issuer = await loadIssuer()
111114

112115
expect(issuer.getWorkloadIdentityIssuer()).toBe('https://oidc.example.com/workload')

‎apps/sim/lib/credentials/workload-identity/subject.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ function ownerSegment(owner: WorkloadIdentityOwner): string {
4141
}
4242

4343
/** `sim:workspace:<id>:credential:<subjectId>` (or `sim:organization:…`). */
44-
export function buildWorkloadIdentitySubject(
45-
owner: WorkloadIdentityOwner,
46-
subjectId: string
47-
): string {
44+
function buildWorkloadIdentitySubject(owner: WorkloadIdentityOwner, subjectId: string): string {
4845
if (!SUBJECT_ID_PATTERN.test(subjectId)) {
4946
throw new WorkloadIdentitySubjectError('Invalid workload identity subject')
5047
}

‎apps/sim/lib/internal/aws/credentials.test.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @vitest-environment node
33
*/
4-
import { beforeEach, describe, expect, it, vi } from 'vitest'
4+
import { describe, expect, it, vi } from 'vitest'
55
import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types'
66

77
const { mockGetAwsCredentialConfig, mockResolveAwsSessionCredentials } = vi.hoisted(() => ({
@@ -29,10 +29,6 @@ function call(overrides: Partial<InternalToolOperationCall> = {}): InternalToolO
2929
}
3030

3131
describe('withAwsCredential', () => {
32-
beforeEach(() => {
33-
vi.clearAllMocks()
34-
})
35-
3632
it('hands an inline-key call to the family handler untouched', async () => {
3733
const request = call()
3834
const handler = vi.fn(async (received: InternalToolOperationCall) => {

0 commit comments

Comments
 (0)