-
Notifications
You must be signed in to change notification settings - Fork 14
CP-14673: switch Glacier calls to the core-proxy-api Glacier proxy #4012
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b71c51
CP-14673: add core-proxy-api auth header resolver and wire GlacierSer…
B0Y3R-AVA d536590
CP-14673: bump vm-modules to 4.0.0, wire getAuthHeaders into ModuleMa…
B0Y3R-AVA 855250f
CP-14673: include avalanche_declareAgentIdentity in the expected aval…
B0Y3R-AVA 9fc125a
CP-14673: fall back silently for hypercore spot tokens in getLocalTok…
B0Y3R-AVA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/core-mobile/app/utils/api/common/getCoreAuthHeaders.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import AppCheckService from 'services/fcm/AppCheckService' | ||
| import { getCoreAuthHeaders } from './getCoreAuthHeaders' | ||
|
|
||
| jest.mock('services/fcm/AppCheckService', () => ({ | ||
| getToken: jest.fn() | ||
| })) | ||
|
|
||
| jest.mock('react-native-config', () => ({ | ||
| CORE_API_KEY: undefined | ||
| })) | ||
|
|
||
| const Config = require('react-native-config') | ||
|
|
||
| const mockGetToken = AppCheckService.getToken as jest.MockedFunction< | ||
| typeof AppCheckService.getToken | ||
| > | ||
|
|
||
| describe('getCoreAuthHeaders', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| Config.CORE_API_KEY = undefined | ||
| }) | ||
|
|
||
| it('returns the AppCheck token header', async () => { | ||
| mockGetToken.mockResolvedValue({ token: 'appcheck-token' } as Awaited< | ||
| ReturnType<typeof AppCheckService.getToken> | ||
| >) | ||
|
|
||
| await expect(getCoreAuthHeaders()).resolves.toEqual({ | ||
| 'X-Firebase-AppCheck': 'appcheck-token' | ||
| }) | ||
| }) | ||
|
|
||
| it('includes the Core API key header when configured', async () => { | ||
| Config.CORE_API_KEY = 'core-api-key' | ||
| mockGetToken.mockResolvedValue({ token: 'appcheck-token' } as Awaited< | ||
| ReturnType<typeof AppCheckService.getToken> | ||
| >) | ||
|
|
||
| await expect(getCoreAuthHeaders()).resolves.toEqual({ | ||
| 'X-Firebase-AppCheck': 'appcheck-token', | ||
| 'x-core-api-key': 'core-api-key' | ||
| }) | ||
| }) | ||
|
|
||
| it('re-reads the token on every call', async () => { | ||
| mockGetToken | ||
| .mockResolvedValueOnce({ token: 'token-1' } as Awaited< | ||
| ReturnType<typeof AppCheckService.getToken> | ||
| >) | ||
| .mockResolvedValueOnce({ token: 'token-2' } as Awaited< | ||
| ReturnType<typeof AppCheckService.getToken> | ||
| >) | ||
|
|
||
| await expect(getCoreAuthHeaders()).resolves.toEqual({ | ||
| 'X-Firebase-AppCheck': 'token-1' | ||
| }) | ||
| await expect(getCoreAuthHeaders()).resolves.toEqual({ | ||
| 'X-Firebase-AppCheck': 'token-2' | ||
| }) | ||
| }) | ||
| }) |
25 changes: 25 additions & 0 deletions
25
packages/core-mobile/app/utils/api/common/getCoreAuthHeaders.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import Config from 'react-native-config' | ||
| import AppCheckService from 'services/fcm/AppCheckService' | ||
| import { APPCHECK_HEADER } from 'utils/api/common/appCheckFetch' | ||
|
|
||
| const CORE_API_KEY_HEADER = 'x-core-api-key' | ||
|
|
||
| /** | ||
| * Resolves the auth headers required by core-proxy-api (e.g. the Glacier | ||
| * proxy): a Firebase AppCheck token, plus the Core API key when one is | ||
| * configured (dev/E2E builds — it both authorizes and bypasses rate limits). | ||
| * | ||
| * Meant to be invoked per request (e.g. as a glacier-sdk HEADERS resolver or | ||
| * the vm-modules `runtime.getAuthHeaders`) so the short-lived AppCheck token | ||
| * is re-read on every call. Unlike appCheckFetch, callers of this resolver | ||
| * get no 401-retry-with-fresh-token — the token cache makes that rare. | ||
| */ | ||
| export const getCoreAuthHeaders = async (): Promise<Record<string, string>> => { | ||
| const { token } = await AppCheckService.getToken() | ||
| return { | ||
| [APPCHECK_HEADER]: token, | ||
| ...(Config.CORE_API_KEY | ||
| ? { [CORE_API_KEY_HEADER]: Config.CORE_API_KEY } | ||
| : {}) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it
CORE_PROXY_API_KEY? There are multiple Core Apis we use