-
Notifications
You must be signed in to change notification settings - Fork 43
Br/add referral get route #697
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,82 @@ | ||
| # Integration test trigger | ||
| # Integration Tests | ||
|
|
||
| This package contains integration tests for the Echo platform. | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Set up the test environment: | ||
| ```bash | ||
| pnpm env:setup | ||
| ``` | ||
|
|
||
| 2. Seed the test database: | ||
| ```bash | ||
| pnpm db:seed | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| Run all integration tests: | ||
| ```bash | ||
| pnpm test:watch | ||
| ``` | ||
|
|
||
| Run specific test suites: | ||
| ```bash | ||
| # Echo Data Server tests | ||
| pnpm test:echo-data-server | ||
|
|
||
| # OAuth Protocol tests | ||
| pnpm test:oauth-protocol | ||
| ``` | ||
|
|
||
| ## Test Suites | ||
|
|
||
| ### Echo Data Server Tests | ||
| Located in `tests/echo-data-server/`: | ||
| - `api-key.client.test.ts` - API key authentication and usage | ||
| - `402-auth.client.test.ts` - Payment required (402) authentication flow | ||
| - `echo-access-jwt.client.test.ts` - JWT token validation | ||
| - `free-tier.client.test.ts` - Free tier functionality | ||
| - `referral-code.client.test.ts` - Referral code creation and application | ||
| - `in-flight-requests.test.ts` - Concurrent request handling | ||
|
|
||
| ### OAuth Protocol Tests | ||
| Located in `tests/oauth-protocol/`: | ||
| - OAuth authorization flow | ||
| - Token refresh and lifecycle | ||
| - PKCE security | ||
| - CSRF vulnerability testing | ||
|
|
||
| ## Referral Code Tests | ||
|
|
||
| The referral code integration tests (`referral-code.client.test.ts`) cover: | ||
|
|
||
| 1. **GET endpoint** - Retrieval of referral codes: | ||
| - Retrieving an existing referral code for a user | ||
| - Auto-creating a referral code for users who don't have one | ||
| - Ensuring consistency across multiple requests | ||
|
|
||
| 2. **POST endpoint** - Application of referral codes: | ||
| - Successfully applying another user's referral code | ||
| - Rejecting invalid referral codes | ||
| - Preventing users from applying codes when they already have a referrer | ||
|
|
||
| ### Test Data | ||
|
|
||
| Referral code test data is defined in `config/test-data.ts`: | ||
| - Primary user has referral code: `TEST-REFERRAL-CODE-PRIMARY` | ||
| - Secondary user has referral code: `TEST-REFERRAL-CODE-SECONDARY` | ||
| - Tertiary user has no referral code (created during tests) | ||
|
|
||
| ## Database Management | ||
|
|
||
| Reset and reseed the database: | ||
| ```bash | ||
| pnpm db:reset-and-seed | ||
| ``` | ||
|
|
||
| Reset only: | ||
| ```bash | ||
| pnpm db:reset | ||
| ``` |
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.
The
setAppMembershipReferrerfunction doesn't validate whether a referral code has expired, allowing expired codes to be applied to memberships.View Details
📝 Patch Details
Analysis
Missing expiration validation in setAppMembershipReferrer allows expired referral codes to be applied
What fails: The
setAppMembershipReferrer()function inpackages/app/control/src/services/db/apps/membership.tsdoes not validate whether a referral code has expired before applying it to a membership.How to reproduce:
expiresAtdate in the past (code schema supports this via optionalexpiresAtparameter, defaulting to 1 year in future)setAppMembershipReferrer(userId, echoAppId, expiredCode)trueand applies the expired code to the membershipResult: Expired referral codes are accepted and applied. The function succeeds even when
referralCode.expiresAt < new Date().Expected: Function should return
falsefor expired codes, matching the pattern used in other similar functions and the error message which states codes "may be invalid, expired, or you may already have a referrer for this app"Verification: The same expiration validation pattern is correctly implemented in:
getCreditGrantCode()inpackages/app/control/src/services/db/credits/grant.ts- usesexpiresAt: { gt: new Date() }in WHERE clausefindRefreshToken()inpackages/app/control/src/services/db/auth/refresh.ts- usesexpiresAt: { gt: new Date() }in WHERE clauseThe fix adds the missing expiration check:
if (!referralCode || referralCode.expiresAt < new Date())