-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Endpoint configuration not passed to terminal server #131
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
Conversation
Add support for endpoint and controlAPIHost parameters in the signed config system to restore custom endpoint configuration that was lost in PR #129. Changes: - Update SignRequest interface to accept optional endpoint and controlAPIHost - Modify signCredentials() to include endpoint fields in config when provided - Update /api/sign endpoint and vite middleware to accept and pass through endpoint params - Maintain backward compatibility - endpoints are optional This allows implementations to specify custom Ably endpoints (e.g., staging) which will be signed and validated via HMAC. Related to: PR #129 (d454d36) Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
…bles Extract endpoint and controlAPIHost from signed config and add them to environment variables (ABLY_ENDPOINT and ABLY_CONTROL_API_HOST) so they are available to the terminal server. This completes the endpoint configuration flow: 1. Client signs config with endpoint/controlAPIHost 2. createAuthPayload() extracts these from signed config 3. Adds them to payload.environmentVariables 4. Terminal server receives them via auth payload The fix is backward compatible - if endpoint fields are not in the signed config, they simply won't be added to environment variables. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Update the web-cli example to show how implementations can pass endpoint configuration to the /api/sign endpoint. This example demonstrates: - Reading endpoint config from environment variables (VITE_ABLY_ENDPOINT, VITE_ABLY_CONTROL_HOST) - Conditionally including endpoint params in the sign request - Note that implementations should determine these values based on their specific requirements The example uses environment variables, but implementations could also use: - User input fields - Configuration files - Hardcoded values for specific environments - Props passed to components Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Add unit and integration tests to verify endpoint configuration flows through the entire system from signing to auth payload creation. Test coverage: - Unit tests for createAuthPayload() endpoint extraction (6 tests) - Unit tests for signCredentials() endpoint inclusion (7 tests) - Integration tests for end-to-end flow (6 tests) Test files: - packages/react-web-cli/src/terminal-shared.test.ts - packages/react-web-cli/src/__tests__/integration/endpoint-config.test.ts - examples/web-cli/server/__tests__/sign-handler.test.ts Also adds: - vitest configuration for examples/web-cli - vitest dependency to examples/web-cli package.json - test script to examples/web-cli package.json All tests verify: - Endpoint fields are correctly included in signed config - Endpoint fields are correctly extracted to environment variables - Backward compatibility when endpoint fields are not provided - Signature integrity with endpoint configuration Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Update pre-push validation script to run tests for packages and examples to ensure new endpoint configuration tests are executed in CI. Added steps: - Step 3b: React Web CLI package tests (pnpm test:react-web-cli) - Step 3c: Example tests (pnpm --filter ably-web-cli-example test) This ensures all 19 new endpoint configuration tests run in CI: - 6 tests in terminal-shared.test.ts - 6 tests in integration/endpoint-config.test.ts - 7 tests in server/__tests__/sign-handler.test.ts Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe changes extend the signing and authentication flow across web CLI and React web CLI packages to support optional Changes
Sequence DiagramsequenceDiagram
participant Client as App.tsx
participant SignAPI as Sign API Handler
participant SignFn as signCredentials()
participant AuthPayload as createAuthPayload()
participant EnvVars as Environment Variables
Client->>SignAPI: POST /sign with endpoint, controlAPIHost
SignAPI->>SignAPI: Parse endpoint, controlAPIHost from body
SignAPI->>SignFn: Call with extracted fields
SignFn->>SignFn: Build signedConfig with endpoint, controlAPIHost
SignFn->>SignAPI: Return signed config + signature
SignAPI->>Client: Return { signature, signedConfig }
Client->>AuthPayload: Call with signedConfig, signature, sessionId
AuthPayload->>AuthPayload: Extract endpoint, controlAPIHost from config
AuthPayload->>EnvVars: Set ABLY_ENDPOINT, ABLY_CONTROL_API_HOST
AuthPayload->>Client: Return auth payload with environmentVariables
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
|
||
| // Extract endpoint configuration and add to environment variables | ||
| if (parsedConfig.endpoint) { | ||
| payload.environmentVariables.ABLY_ENDPOINT = parsedConfig.endpoint; | ||
| } | ||
| if (parsedConfig.controlAPIHost) { | ||
| payload.environmentVariables.ABLY_CONTROL_API_HOST = | ||
| parsedConfig.controlAPIHost; | ||
| } | ||
|
|
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.
This is the crux of the fix, everything else is in support of this.
|
Turns out this was only required because we were running and older version of the terminal server 😅 |
Summary
Fixes the breaking change introduced in PR #129 (commit d454d36) where endpoint configuration was removed from
createAuthPayload()with the claim that it would be included in the signed config, but those fields were never actually added.This PR restores endpoint configuration functionality while maintaining the cleaner API surface (no
additionalEnvVarsparameter).Problem
PR #129 removed the
additionalEnvVarsparameter fromcreateAuthPayload()but:endpointandcontrolAPIHostto the signed configcreateAuthPayload()Solution
Phase 1: Add endpoint fields to signed config
SignRequestinterface to accept optionalendpointandcontrolAPIHostsignCredentials()to include these in the config when providedPhase 2: Extract endpoint config in createAuthPayload()
createAuthPayload()to extract endpoint fields from signed configABLY_ENDPOINTandABLY_CONTROL_API_HOSTto environment variablesPhase 3: Update example implementation
Phase 4: Comprehensive test coverage (19 tests)
createAuthPayload()endpoint extraction (6 tests)signCredentials()endpoint inclusion (7 tests)Phase 5: CI integration
Key Features
✅ Backward Compatible: Works with or without endpoint configuration
✅ Secure: Endpoint values are signed and validated via HMAC
✅ Clean API: No
additionalEnvVarsparameter needed✅ Flexible: Implementations can source endpoint values from env vars, config files, user input, etc.
Testing
All tests passing:
Files Changed
Core Implementation:
examples/web-cli/server/sign-handler.ts- Add endpoint fields to signed configexamples/web-cli/api/sign.ts- Accept endpoint params in APIexamples/web-cli/vite.config.ts- Accept endpoint params in middlewarepackages/react-web-cli/src/terminal-shared.ts- Extract endpoint to env varsExample:
examples/web-cli/src/App.tsx- Demonstrate endpoint configurationTests:
packages/react-web-cli/src/terminal-shared.test.ts- Unit testspackages/react-web-cli/src/__tests__/integration/endpoint-config.test.ts- Integration testsexamples/web-cli/server/__tests__/sign-handler.test.ts- Sign handler testsCI:
scripts/pre-push-validation.sh- Run package tests in CIRelated
Note
Restores endpoint configuration by carrying it through the signing flow and exposing it to the terminal server via auth payload.
signCredentials()now acceptsendpointandcontrolAPIHostand includes them insignedConfig;createAuthPayload()reads these fields and setsABLY_ENDPOINT/ABLY_CONTROL_API_HOSTenv vars/api/signhandler and Vite middleware accept/pass endpoint params;App.tsxforwards optional values from env to signing requestsignCredentials()andcreateAuthPayload(), plus integration tests validating end-to-end propagation and signature integrity; added Vitest config and script in exampleWritten by Cursor Bugbot for commit 908bcd5. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
New Features
endpointandcontrolAPIHostconfiguration fields, conditionally included when provided.Tests
✏️ Tip: You can customize this high-level summary in your review settings.