Skip to content

Commit 4056ba7

Browse files
committed
fix(credentials): keep a Splunk password's surrounding spaces, and report page 1 when Apollo is asked for page 0
1 parent 09ca74e commit 4056ba7

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎apps/sim/lib/credentials/service-account-secret.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,59 @@ describe('a ServiceNow login', () => {
838838
})
839839
})
840840

841+
describe('a Splunk username and password', () => {
842+
const secureFetch = inputValidationMockFns.mockSecureFetchWithPinnedIP
843+
844+
beforeEach(() => {
845+
mockEncryptSecret.mockImplementation(async (value: string) => ({ encrypted: value }))
846+
inputValidationMockFns.mockValidateUrlWithDNS.mockReset().mockResolvedValue({
847+
isValid: true,
848+
resolvedIP: '203.0.113.7',
849+
originalHostname: 'splunk.example.com',
850+
})
851+
secureFetch.mockReset().mockResolvedValue(
852+
new Response(JSON.stringify({ entry: [{ content: { username: 'svc-sim' } }] }), {
853+
status: 200,
854+
headers: { 'Content-Type': 'application/json' },
855+
})
856+
)
857+
})
858+
859+
it('verifies and stores a password with surrounding spaces exactly as typed', async () => {
860+
const result = await verifyAndBuildServiceAccountSecret('splunk-service-account', {
861+
apiToken: ' pass word ',
862+
providerWorkspaceId: 'svc-sim',
863+
domain: 'splunk.example.com:8089',
864+
})
865+
866+
expect(secureFetch).toHaveBeenCalledWith(
867+
expect.any(String),
868+
'203.0.113.7',
869+
expect.objectContaining({
870+
headers: expect.objectContaining({
871+
Authorization: `Basic ${Buffer.from('svc-sim: pass word ').toString('base64')}`,
872+
}),
873+
})
874+
)
875+
expect(JSON.parse(result.encryptedServiceAccountKey).apiToken).toBe(' pass word ')
876+
})
877+
878+
it('still sends a pasted token without its surrounding whitespace', async () => {
879+
await verifyAndBuildServiceAccountSecret('splunk-service-account', {
880+
apiToken: ' splunk-token\n',
881+
domain: 'splunk.example.com:8089',
882+
})
883+
884+
expect(secureFetch).toHaveBeenCalledWith(
885+
expect.any(String),
886+
'203.0.113.7',
887+
expect.objectContaining({
888+
headers: expect.objectContaining({ Authorization: 'Bearer splunk-token' }),
889+
})
890+
)
891+
})
892+
})
893+
841894
describe('a token provider whose region or host defaults to the one it always used', () => {
842895
const fetchMock = vi.fn<typeof fetch>()
843896

‎apps/sim/lib/credentials/token-service-accounts/descriptors.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,7 @@ export const TOKEN_SERVICE_ACCOUNT_DESCRIPTORS: Record<
27422742
label: 'Authentication token or password',
27432743
placeholder: 'Paste a Splunk authentication token, or the password',
27442744
secret: true,
2745+
preserveWhitespace: true,
27452746
},
27462747
{
27472748
id: 'providerWorkspaceId',

‎apps/sim/tools/apollo/people_search.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ describe('apollo_people_search response mapping', () => {
5757
expect(result.output.per_page).toBe(100)
5858
})
5959

60+
it.concurrent('reports page 1, the page the request sent, when page is 0', async () => {
61+
const result = await transform(
62+
{ total_entries: 5, people: [] },
63+
{ apiKey: 'token', credentialType: 'oauth', page: 0 }
64+
)
65+
66+
expect(result.output.page).toBe(1)
67+
})
68+
6069
it.concurrent('reads the nested pagination the legacy endpoint returns', async () => {
6170
const result = await transform(
6271
{ people: [{ id: 'p2' }], pagination: { page: 2, per_page: 10, total_entries: 40 } },

‎apps/sim/tools/apollo/people_search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const apolloPeopleSearchTool: ToolConfig<
196196
success: true,
197197
output: {
198198
people: data.people || [],
199-
page: pagination.page ?? data.page ?? params?.page ?? 1,
199+
page: pagination.page ?? data.page ?? (params?.page || 1),
200200
per_page: pagination.per_page ?? data.per_page ?? requestedPerPage(params),
201201
total_entries: pagination.total_entries ?? data.total_entries ?? 0,
202202
},

0 commit comments

Comments
 (0)