Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integration): sign Admin API requests during integration tests #3177

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(backend): sign GraphQL requests in test environment
mkurapov committed Dec 13, 2024
commit 0a128d1b0ebad8281a7e6401da3b25c628c5a033
17 changes: 14 additions & 3 deletions packages/backend/src/tests/app.ts
Original file line number Diff line number Diff line change
@@ -12,8 +12,9 @@ import {
import { setContext } from '@apollo/client/link/context'
import { start, gracefulShutdown } from '..'
import { onError } from '@apollo/client/link/error'

import { print } from 'graphql/language/printer'
import { App, AppServices } from '../app'
import { generateApiSignature } from './apiSignature'

export const testAccessToken = 'test-app-access'

@@ -76,10 +77,20 @@ export const createTestApp = async (
})
}
})
const authLink = setContext((_, { headers }) => {
const authLink = setContext((request, { headers }) => {
const requestBody = {
variables: request.variables,
operationName: request.operationName,
query: print(request.query)
}
return {
headers: {
...headers
...headers,
signature: generateApiSignature(
config.adminApiSecret,
config.adminApiSignatureVersion,
requestBody
)
Copy link
Contributor Author

@mkurapov mkurapov Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the API_SECRET is mandatory, sign graphql requests during tests as well. I was thinking of potentially bypassing signing in tests via flag like if (config.env === "test") don't add the auth middleware, but this was straightforward

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: because of our replay attack checks, going to use if (config.env === "test") don't add the auth middleware method

}
}
})