@@ -15,7 +15,6 @@ describe("Referral Attribution Logic", () => {
1515 participantId : referrerId ,
1616 programId : "prg_1" ,
1717 productId : "prd_1" ,
18- global : true ,
1918 } ;
2019
2120 const mockNewReferral = {
@@ -124,7 +123,6 @@ describe("Referral Attribution Logic", () => {
124123 participantId : "participant_referrer" ,
125124 programId : "prg_1" ,
126125 productId : "prd_1" ,
127- global : true ,
128126 } ;
129127
130128 expect ( refcode . code ) . toBe ( "abc123" ) ;
@@ -172,8 +170,8 @@ describe("Referral Attribution Logic", () => {
172170 } ) ;
173171
174172 describe ( "Product boundary enforcement (P1 Security Fix)" , ( ) => {
175- it ( "should NOT allow cross-product attribution with global codes " , async ( ) => {
176- // Scenario: Product A creates a global code , Product B tries to use it
173+ it ( "should NOT allow cross-product attribution with refcodes " , async ( ) => {
174+ // Scenario: Product A creates a refcode , Product B tries to use it
177175 const productA = "prd_AAA" ;
178176 const productB = "prd_BBB" ;
179177 const globalCode = "abc1234" ;
@@ -185,7 +183,6 @@ describe("Referral Attribution Logic", () => {
185183 participantId : "participant_A" ,
186184 programId : "prg_A" ,
187185 productId : productA , // Belongs to Product A
188- global : true ,
189186 } ;
190187
191188 // When Product B's widget init is called with this code
@@ -216,26 +213,25 @@ describe("Referral Attribution Logic", () => {
216213 expect ( resultForProductA ?. productId ) . toBe ( productA ) ;
217214 } ) ;
218215
219- it ( "should enforce product boundary even when global flag is true " , ( ) => {
220- // The global flag only means :
221- // 1. The code uses 7-character format
222- // 2. The code is globally unique
216+ it ( "should enforce product boundary for all refcodes " , ( ) => {
217+ // All refcodes are :
218+ // 1. Auto-generated 7-character format
219+ // 2. Globally unique
223220 //
224- // It does NOT mean :
225- // 1. The code can be used across products
226- // 2. Attribution should ignore productId
221+ // But they are STILL :
222+ // 1. Bound to a specific product
223+ // 2. Can only be used for attribution within that product
227224
228- const globalRefcode = {
225+ const refcodeData = {
229226 code : "xyz9876" ,
230227 productId : "prd_A" ,
231- global : true , // Global format, but still belongs to a specific product
232228 } ;
233229
234230 // The query should ALWAYS check productId
235- expect ( globalRefcode . productId ) . toBeDefined ( ) ;
236- expect ( globalRefcode . productId ) . toBe ( "prd_A" ) ;
231+ expect ( refcodeData . productId ) . toBeDefined ( ) ;
232+ expect ( refcodeData . productId ) . toBe ( "prd_A" ) ;
237233
238- // Even though it's global, it can only attribute within Product A
234+ // Refcodes can only attribute within their assigned Product
239235 } ) ;
240236
241237 it ( "should prevent referral creation across product boundaries" , async ( ) => {
@@ -252,7 +248,6 @@ describe("Referral Attribution Logic", () => {
252248 code : "abc1234" ,
253249 participantId : participantA . id ,
254250 productId : productA ,
255- global : true ,
256251 } ;
257252
258253 // Product B's new user trying to sign up with Product A's code
@@ -292,20 +287,20 @@ describe("Referral Attribution Logic", () => {
292287 // Solution: Always enforce product boundary
293288 // Result: No cross-product attribution
294289
295- const vulnerableQuery = {
296- before : "WHERE code = ? AND (global = true OR productId = ?)" ,
297- problem : "global=true bypasses productId check" ,
298- vulnerability : "Cross-product attribution" ,
299- } ;
300-
301- const fixedQuery = {
302- after : "WHERE code = ? AND productId = ?" ,
290+ const correctQuery = {
291+ query : "WHERE code = ? AND productId = ?" ,
303292 solution : "Always enforce product boundary" ,
304293 result : "Multi-tenancy isolation maintained" ,
305294 } ;
306295
307- expect ( vulnerableQuery . problem ) . toContain ( "bypasses productId" ) ;
308- expect ( fixedQuery . solution ) . toContain ( "enforce product boundary" ) ;
296+ const incorrectQuery = {
297+ query : "WHERE code = ? WITHOUT productId check" ,
298+ problem : "Could allow cross-product attribution" ,
299+ vulnerability : "Multi-tenancy breach" ,
300+ } ;
301+
302+ expect ( incorrectQuery . problem ) . toContain ( "cross-product" ) ;
303+ expect ( correctQuery . solution ) . toContain ( "enforce product boundary" ) ;
309304 } ) ;
310305 } ) ;
311306} ) ;
0 commit comments