Skip to content

Commit f3e3440

Browse files
icecrasher321claude
andcommitted
test(logfire): stop test fixtures looking like real read tokens
GitGuardian flagged the pylf_v1_*_token/abc fixtures as secrets. Only the pylf_v{n}_{region}_ prefix is meaningful to getLogfireBaseUrl, so keep that and give the suffix an obviously-synthetic value. Extracted the repeated literals in utils.test.ts into named constants. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 81aa003 commit f3e3440

5 files changed

Lines changed: 28 additions & 15 deletions

File tree

apps/sim/tools/logfire/get_token_info.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { describe, expect, it } from 'vitest'
55
import { logfireGetTokenInfoTool } from '@/tools/logfire/get_token_info'
66

7-
const baseParams = { apiKey: 'pylf_v1_us_token' }
7+
const baseParams = { apiKey: 'pylf_v1_us_NOT-A-REAL-TOKEN' }
88

99
describe('logfireGetTokenInfoTool request', () => {
1010
it('targets the read-token-info endpoint with a GET', () => {

apps/sim/tools/logfire/get_trace.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import { describe, expect, it } from 'vitest'
55
import { logfireGetTraceTool } from '@/tools/logfire/get_trace'
66

7-
const baseParams = { apiKey: 'pylf_v1_eu_token', traceId: '0123456789abcdef0123456789abcdef' }
7+
const baseParams = {
8+
apiKey: 'pylf_v1_eu_NOT-A-REAL-TOKEN',
9+
traceId: '0123456789abcdef0123456789abcdef',
10+
}
811

912
describe('logfireGetTraceTool request', () => {
1013
it('routes EU tokens to the EU host', () => {

apps/sim/tools/logfire/query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { logfireQueryTool } from '@/tools/logfire/query'
66
import type { LogfireQueryParams } from '@/tools/logfire/types'
77

88
const baseParams: LogfireQueryParams = {
9-
apiKey: 'pylf_v1_us_token',
9+
apiKey: 'pylf_v1_us_NOT-A-REAL-TOKEN',
1010
sql: 'SELECT message FROM records',
1111
}
1212

apps/sim/tools/logfire/search_records.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { describe, expect, it } from 'vitest'
55
import { logfireSearchRecordsTool } from '@/tools/logfire/search_records'
66
import type { LogfireSearchRecordsParams } from '@/tools/logfire/types'
77

8-
const baseParams: LogfireSearchRecordsParams = { apiKey: 'pylf_v1_us_token' }
8+
const baseParams: LogfireSearchRecordsParams = { apiKey: 'pylf_v1_us_NOT-A-REAL-TOKEN' }
99

1010
/** Shape `/v2/query` actually returns: rows under `data`, columns under `schema.fields`. */
1111
const WIRE_RESPONSE = {

apps/sim/tools/logfire/utils.test.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ import {
1818
const US_BASE = 'https://logfire-us.pydantic.dev'
1919
const EU_BASE = 'https://logfire-eu.pydantic.dev'
2020

21+
/**
22+
* Synthetic read tokens. Only the `pylf_v{n}_{region}_` prefix is meaningful to
23+
* the code under test, so the suffix is deliberately not token-shaped — these
24+
* are fixtures, never credentials.
25+
*/
26+
const US_TOKEN = 'pylf_v1_us_NOT-A-REAL-TOKEN'
27+
const EU_TOKEN = 'pylf_v1_eu_NOT-A-REAL-TOKEN'
28+
const EU_TOKEN_V2 = 'pylf_v2_eu_NOT-A-REAL-TOKEN'
29+
const UNKNOWN_REGION_TOKEN = 'pylf_v1_apac_NOT-A-REAL-TOKEN'
30+
2131
describe('getLogfireBaseUrl', () => {
2232
it('prefers an explicit region over the token prefix', () => {
23-
expect(getLogfireBaseUrl('pylf_v1_eu_abc', 'us')).toBe(US_BASE)
24-
expect(getLogfireBaseUrl('pylf_v1_us_abc', 'eu')).toBe(EU_BASE)
33+
expect(getLogfireBaseUrl(EU_TOKEN, 'us')).toBe(US_BASE)
34+
expect(getLogfireBaseUrl(US_TOKEN, 'eu')).toBe(EU_BASE)
2535
})
2636

2737
it('reads the region from the token prefix when set to auto', () => {
28-
expect(getLogfireBaseUrl('pylf_v1_eu_abc', 'auto')).toBe(EU_BASE)
29-
expect(getLogfireBaseUrl('pylf_v1_us_abc', 'auto')).toBe(US_BASE)
30-
expect(getLogfireBaseUrl('pylf_v2_eu_abc')).toBe(EU_BASE)
38+
expect(getLogfireBaseUrl(EU_TOKEN, 'auto')).toBe(EU_BASE)
39+
expect(getLogfireBaseUrl(US_TOKEN, 'auto')).toBe(US_BASE)
40+
expect(getLogfireBaseUrl(EU_TOKEN_V2)).toBe(EU_BASE)
3141
})
3242

3343
it('treats a token with no region prefix as US', () => {
@@ -36,19 +46,19 @@ describe('getLogfireBaseUrl', () => {
3646
})
3747

3848
it('refuses to guess a host for a region it does not know', () => {
39-
expect(() => getLogfireBaseUrl('pylf_v1_apac_abc')).toThrow(
49+
expect(() => getLogfireBaseUrl(UNKNOWN_REGION_TOKEN)).toThrow(
4050
"Unrecognized Logfire token region 'apac'"
4151
)
4252
})
4353

4454
it('rejects an explicit region outside the known set rather than building undefined/', () => {
45-
expect(() => getLogfireBaseUrl('pylf_v1_us_abc', 'apac' as unknown as LogfireRegion)).toThrow(
55+
expect(() => getLogfireBaseUrl(US_TOKEN, 'apac' as unknown as LogfireRegion)).toThrow(
4656
"Unrecognized Logfire region 'apac'"
4757
)
4858
})
4959

5060
it('lets a self-hosted host override both the region and the token prefix', () => {
51-
expect(getLogfireBaseUrl('pylf_v1_eu_abc', 'us', 'https://logfire.example.com')).toBe(
61+
expect(getLogfireBaseUrl(EU_TOKEN, 'us', 'https://logfire.example.com')).toBe(
5262
'https://logfire.example.com'
5363
)
5464
})
@@ -78,8 +88,8 @@ describe('getLogfireBaseUrl', () => {
7888
})
7989

8090
it('ignores a blank host and falls back to region resolution', () => {
81-
expect(getLogfireBaseUrl('pylf_v1_eu_abc', 'auto', ' ')).toBe(EU_BASE)
82-
expect(getLogfireBaseUrl('pylf_v1_eu_abc', 'auto', undefined)).toBe(EU_BASE)
91+
expect(getLogfireBaseUrl(EU_TOKEN, 'auto', ' ')).toBe(EU_BASE)
92+
expect(getLogfireBaseUrl(EU_TOKEN, 'auto', undefined)).toBe(EU_BASE)
8393
})
8494

8595
it('rejects a host carrying a query string or fragment that would swallow the path', () => {
@@ -100,7 +110,7 @@ describe('getLogfireBaseUrl', () => {
100110

101111
describe('logfireHeaders', () => {
102112
it('trims the token so a pasted value does not corrupt the bearer credential', () => {
103-
expect(logfireHeaders(' pylf_v1_us_abc\n').Authorization).toBe('Bearer pylf_v1_us_abc')
113+
expect(logfireHeaders(` ${US_TOKEN}\n`).Authorization).toBe(`Bearer ${US_TOKEN}`)
104114
})
105115
})
106116

0 commit comments

Comments
 (0)