1010require 'test_etld_plus_one_resolver'
1111require_relative '../lib/model/fbc_param_configs'
1212
13- APPENDIX_IS_NEW = "AQUBAQAB"
14- APPENDIX_IS_NORMAL = "AQUAAQAB"
13+ APPENDIX_NET_NEW = "AQUCAQAB"
14+ APPENDIX_MODIFIED_NEW = "AQUDAQAB"
15+ APPENDIX_NO_CHANGE = "AQUAAQAB"
1516
1617# Save the original value before any tests run
1718ORIGINAL_VERSION = ReleaseConfig ::VERSION
@@ -31,10 +32,12 @@ def test_override_different_versions
3132 ReleaseConfig . const_set ( :VERSION , "1.15.24" )
3233 assert_equal "1.15.24" , ReleaseConfig ::VERSION
3334 builder = ParamBuilder . new ( )
34- appendix_new = builder . send ( :get_appendix , true )
35- assert_equal ( appendix_new , "AQUBAQ8Y" )
36- appendix_normal = builder . send ( :get_appendix , false )
37- assert_equal ( appendix_normal , "AQUAAQ8Y" )
35+ appendix_net_new = builder . send ( :get_appendix , ParamBuilder ::APPENDIX_NET_NEW )
36+ assert_equal ( appendix_net_new , "AQUCAQ8Y" )
37+ appendix_modified_new = builder . send ( :get_appendix , ParamBuilder ::APPENDIX_MODIFIED_NEW )
38+ assert_equal ( appendix_modified_new , "AQUDAQ8Y" )
39+ appendix_no_change = builder . send ( :get_appendix , ParamBuilder ::APPENDIX_NO_CHANGE )
40+ assert_equal ( appendix_no_change , "AQUAAQ8Y" )
3841 ensure
3942 ReleaseConfig . send ( :remove_const , :VERSION )
4043 ReleaseConfig . const_set ( :VERSION , tmp_original_version )
@@ -45,10 +48,10 @@ def test_override_different_versions_exception
4548 ReleaseConfig . send ( :remove_const , :VERSION )
4649 ReleaseConfig . const_set ( :VERSION , nil )
4750 builder = ParamBuilder . new ( )
48- appendix_new = builder . send ( :get_appendix , true )
49- assert_equal ( appendix_new , "BQ" )
50- appendix_normal = builder . send ( :get_appendix , false )
51- assert_equal ( appendix_normal , "BQ" )
51+ appendix_net_new = builder . send ( :get_appendix , ParamBuilder :: APPENDIX_NET_NEW )
52+ assert_equal ( appendix_net_new , "BQ" )
53+ appendix_no_change = builder . send ( :get_appendix , ParamBuilder :: APPENDIX_NO_CHANGE )
54+ assert_equal ( appendix_no_change , "BQ" )
5255 ensure
5356 ReleaseConfig . send ( :remove_const , :VERSION )
5457 ReleaseConfig . const_set ( :VERSION , tmp_original_version )
@@ -62,16 +65,16 @@ def test_process_request_with_fbc_fbp_updated
6265 { "test" => "value" , "_fbc" => "fb.1.2.test_fbc" } ,
6366 "example.com?fbclid=test345" )
6467 assert_equal ( 2 , cookie_to_update . size ( ) )
65- assert_contains ( ".test123.#{ APPENDIX_IS_NEW } " , builder . get_fbc ( ) )
68+ assert_contains ( ".test123.#{ APPENDIX_MODIFIED_NEW } " , builder . get_fbc ( ) )
6669 assert_contains ( "fb.0." , builder . get_fbp ( ) )
6770 for cookie in cookie_to_update do
6871 if cookie . name == '_fbc'
69- assert cookie . value . end_with? ( ".test123.#{ APPENDIX_IS_NEW } " )
72+ assert cookie . value . end_with? ( ".test123.#{ APPENDIX_MODIFIED_NEW } " )
7073 assert_contains ( 'fb.0.' , cookie . value )
7174 assert_contains ( "localhost" , cookie . domain )
7275 else
7376 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
74- assert cookie . value . end_with? ( APPENDIX_IS_NEW )
77+ assert cookie . value . end_with? ( APPENDIX_NET_NEW )
7578 assert_equal ( "localhost" , cookie . domain )
7679 end
7780 end
@@ -86,18 +89,18 @@ def test_process_request_with_fbc_fbp_update_no_cookie
8689 { } ,
8790 "example.com" )
8891 assert_equal ( 2 , cookie_to_update . size ( ) )
89- assert builder . get_fbc ( ) . end_with? ( ".test123.#{ APPENDIX_IS_NEW } " )
92+ assert builder . get_fbc ( ) . end_with? ( ".test123.#{ APPENDIX_NET_NEW } " )
9093 assert_contains ( "fb.1." , builder . get_fbp ( ) )
91- assert builder . get_fbp ( ) . end_with? ( ".#{ APPENDIX_IS_NEW } " )
94+ assert builder . get_fbp ( ) . end_with? ( ".#{ APPENDIX_NET_NEW } " )
9295 for cookie in cookie_to_update do
9396 if cookie . name == '_fbc'
94- assert cookie . value . end_with? ( ".test123.#{ APPENDIX_IS_NEW } " )
97+ assert cookie . value . end_with? ( ".test123.#{ APPENDIX_NET_NEW } " )
9598 assert_contains ( 'fb.1.' , cookie . value )
9699 assert_equal ( "example.com" , cookie . domain )
97100 else
98101 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
99102 assert_contains ( "fb.1." , cookie . value )
100- assert cookie . value . end_with? ( ".#{ APPENDIX_IS_NEW } " )
103+ assert cookie . value . end_with? ( ".#{ APPENDIX_NET_NEW } " )
101104 assert_equal ( "example.com" , cookie . domain )
102105 end
103106 end
@@ -114,12 +117,12 @@ def test_process_request_with_with_resolver
114117 assert_equal ( 2 , cookie_to_update . size ( ) )
115118 for cookie in cookie_to_update do
116119 if cookie . name == ParamBuilder ::FBC_NAME
117- assert_contains ( ".test.#{ APPENDIX_IS_NEW } " , cookie . value )
120+ assert_contains ( ".test.#{ APPENDIX_MODIFIED_NEW } " , cookie . value )
118121 assert_contains ( "fb.4." , cookie . value )
119122 assert_equal ( "this.is.a.test.com" , cookie . domain )
120123 else
121124 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
122- assert_equal ( "fb.1.123.value.#{ APPENDIX_IS_NORMAL } " , cookie . value )
125+ assert_equal ( "fb.1.123.value.#{ APPENDIX_NO_CHANGE } " , cookie . value )
123126 assert_equal ( "this.is.a.test.com" , cookie . domain )
124127 end
125128 end
@@ -135,7 +138,7 @@ def test_process_request_with_with_empty_constructor
135138 "https://example.com?fbclid=wer" )
136139 assert_equal ( 1 , cookie_to_update . size ( ) )
137140 for cookie in cookie_to_update do
138- assert_contains ( ".test.#{ APPENDIX_IS_NEW } " , cookie . value )
141+ assert_contains ( ".test.#{ APPENDIX_NET_NEW } " , cookie . value )
139142 assert_contains ( "fb.4." , cookie . value )
140143 assert_equal ( "is.a.test.co.uk" , cookie . domain )
141144 end
@@ -153,7 +156,7 @@ def test_process_request_with_with_invali_string_domain_list
153156 "https://example.com?fbclid=wer" )
154157 assert_equal ( 1 , cookie_to_update . size ( ) )
155158 for cookie in cookie_to_update do
156- assert_contains ( ".test.#{ APPENDIX_IS_NEW } " , cookie . value )
159+ assert_contains ( ".test.#{ APPENDIX_NET_NEW } " , cookie . value )
157160 assert_contains ( "fb.4." , cookie . value )
158161 assert_equal ( "is.a.test.example.com" , cookie . domain )
159162 end
@@ -170,13 +173,13 @@ def test_process_request_with_with_referer
170173 assert_equal ( 2 , cookie_to_update . size ( ) )
171174 for cookie in cookie_to_update do
172175 if cookie . name == ParamBuilder ::FBC_NAME
173- assert_contains ( ".wer.#{ APPENDIX_IS_NEW } " , cookie . value )
176+ assert_contains ( ".wer.#{ APPENDIX_NET_NEW } " , cookie . value )
174177 assert_contains ( "fb.4." , cookie . value )
175178 assert_equal ( "is.a.test.co.uk" , cookie . domain )
176179 else
177180 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
178181 assert_contains ( "fb.4." , cookie . value )
179- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
182+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
180183 assert_equal ( "is.a.test.co.uk" , cookie . domain )
181184 end
182185 end
@@ -193,13 +196,13 @@ def test_process_request_with_with_duplicate_referer_params
193196 assert_equal ( 2 , cookie_to_update . size ( ) )
194197 for cookie in cookie_to_update do
195198 if cookie . name == ParamBuilder ::FBC_NAME
196- assert_contains ( ".wer.#{ APPENDIX_IS_NEW } " , cookie . value )
199+ assert_contains ( ".wer.#{ APPENDIX_NET_NEW } " , cookie . value )
197200 assert_contains ( "fb.4." , cookie . value )
198201 assert_equal ( "is.a.test.co.uk" , cookie . domain )
199202 else
200203 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
201204 assert_contains ( "fb.4." , cookie . value )
202- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
205+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
203206 end
204207 end
205208 assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
@@ -220,13 +223,13 @@ def test_process_request_with_param_config_update
220223 assert_equal ( 2 , cookie_to_update . size ( ) )
221224 for cookie in cookie_to_update do
222225 if cookie . name == ParamBuilder ::FBC_NAME
223- assert_contains ( ".test123_test1_test2.#{ APPENDIX_IS_NEW } " , cookie . value )
226+ assert_contains ( ".test123_test1_test2.#{ APPENDIX_NET_NEW } " , cookie . value )
224227 assert_contains ( "fb.1." , cookie . value )
225228 assert_equal ( "example.com" , cookie . domain )
226229 else
227230 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
228231 assert_contains ( "fb.1." , cookie . value )
229- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
232+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
230233 end
231234 end
232235 assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
@@ -246,13 +249,13 @@ def test_process_request_with_param_config_with_customized_config_only
246249 assert_equal ( 2 , cookie_to_update . size ( ) )
247250 for cookie in cookie_to_update do
248251 if cookie . name == ParamBuilder ::FBC_NAME
249- assert_contains ( ".test1_test2.#{ APPENDIX_IS_NEW } " , cookie . value )
252+ assert_contains ( ".test1_test2.#{ APPENDIX_NET_NEW } " , cookie . value )
250253 assert_contains ( "fb.1." , cookie . value )
251254 assert_equal ( "example.com" , cookie . domain )
252255 else
253256 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
254257 assert_contains ( "fb.1." , cookie . value )
255- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
258+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
256259 end
257260 end
258261 assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
@@ -274,15 +277,15 @@ def test_process_request_with_param_config_with_duplication
274277 for cookie in cookie_to_update do
275278 if cookie . name == ParamBuilder ::FBC_NAME
276279 assert_contains (
277- ".test123_test1_test456.#{ APPENDIX_IS_NEW } " ,
280+ ".test123_test1_test456.#{ APPENDIX_NET_NEW } " ,
278281 cookie . value
279282 )
280283 assert_contains ( "fb.1." , cookie . value )
281284 assert_equal ( "example.com" , cookie . domain )
282285 else
283286 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
284287 assert_contains ( "fb.1." , cookie . value )
285- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
288+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
286289 end
287290 end
288291 assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
@@ -305,13 +308,13 @@ def test_process_request_with_param_config_update_referer
305308 assert_equal ( 2 , cookie_to_update . size ( ) )
306309 for cookie in cookie_to_update do
307310 if cookie . name == ParamBuilder ::FBC_NAME
308- assert_contains ( ".wer_test1_placeholder.#{ APPENDIX_IS_NEW } " , cookie . value )
311+ assert_contains ( ".wer_test1_placeholder.#{ APPENDIX_NET_NEW } " , cookie . value )
309312 assert_contains ( "fb.1." , cookie . value )
310313 assert_equal ( "example.com" , cookie . domain )
311314 else
312315 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
313316 assert_contains ( "fb.1." , cookie . value )
314- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
317+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
315318 end
316319 end
317320 assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
@@ -327,7 +330,7 @@ def test_process_request_with_with_mutiple_domain_list
327330 for cookie in cookie_to_update do
328331 if cookie . name == ParamBuilder ::FBC_NAME
329332 assert_equal (
330- "fb.1.2.test_fbc.#{ APPENDIX_IS_NORMAL } " ,
333+ "fb.1.2.test_fbc.#{ APPENDIX_NO_CHANGE } " ,
331334 cookie . value
332335 )
333336 assert_equal (
@@ -336,7 +339,7 @@ def test_process_request_with_with_mutiple_domain_list
336339 )
337340 else
338341 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
339- assert_contains ( ".#{ APPENDIX_IS_NEW } " , cookie . value )
342+ assert_contains ( ".#{ APPENDIX_NET_NEW } " , cookie . value )
340343 assert_equal ( "example.co.uk" , cookie . domain )
341344 end
342345 end
@@ -380,21 +383,41 @@ def test_process_request_with_valie_cookies_with_language_update
380383 { "_fbp" => "fb.1.123.345" , "_fbc" => "fb.1.2.test_fbc" } ,
381384 nil )
382385 assert_equal ( 2 , cookie_to_update . size ( ) )
383- assert_equal ( "fb.1.2.test_fbc.#{ APPENDIX_IS_NORMAL } " , builder . get_fbc ( ) )
384- assert_equal ( "fb.1.123.345.#{ APPENDIX_IS_NORMAL } " , builder . get_fbp ( ) )
386+ assert_equal ( "fb.1.2.test_fbc.#{ APPENDIX_NO_CHANGE } " , builder . get_fbc ( ) )
387+ assert_equal ( "fb.1.123.345.#{ APPENDIX_NO_CHANGE } " , builder . get_fbp ( ) )
385388 for cookie in cookie_to_update do
386389 if cookie . name == ParamBuilder ::FBC_NAME
387- assert_equal ( "fb.1.2.test_fbc.#{ APPENDIX_IS_NORMAL } " , cookie . value )
390+ assert_equal ( "fb.1.2.test_fbc.#{ APPENDIX_NO_CHANGE } " , cookie . value )
388391 assert_equal ( "localhost" , cookie . domain )
389392 else
390393 assert_equal ( ParamBuilder ::FBP_NAME , cookie . name )
391- assert_equal ( "fb.1.123.345.#{ APPENDIX_IS_NORMAL } " , cookie . value )
394+ assert_equal ( "fb.1.123.345.#{ APPENDIX_NO_CHANGE } " , cookie . value )
392395 assert_equal ( "localhost" , cookie . domain )
393396 end
394397 end
395398 assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
396399 end
397400
401+ def test_process_request_fbc_modified
402+ # Test that modifying an existing fbc with a different payload uses MODIFIED_NEW appendix
403+ builder = ParamBuilder . new ( )
404+ cookie_to_update = builder . process_request (
405+ "localhost" ,
406+ { "fbclid" => "new_click_id" } ,
407+ { "_fbc" => "fb.0.123.old_click_id.BQ" , "_fbp" => "fb.0.456.123456789.BQ" } )
408+ assert_equal ( 1 , cookie_to_update . size ( ) )
409+ fbc = builder . get_fbc ( )
410+ assert fbc . end_with? ( ".new_click_id.#{ APPENDIX_MODIFIED_NEW } " )
411+ assert_contains ( "fb.0." , fbc )
412+ for cookie in cookie_to_update do
413+ assert_equal ( ParamBuilder ::FBC_NAME , cookie . name )
414+ assert cookie . value . end_with? ( ".new_click_id.#{ APPENDIX_MODIFIED_NEW } " )
415+ assert_equal ( "localhost" , cookie . domain )
416+ end
417+ assert_equal ( "fb.0.456.123456789.BQ" , builder . get_fbp ( ) )
418+ assert_equal ( cookie_to_update , builder . get_cookies_to_set ( ) )
419+ end
420+
398421 def test_extract_host_from_http_host_with_protocol_and_port
399422 builder = ParamBuilder . new ( )
400423 host_name = builder . send ( :extract_host_from_http_host , "https://example.com:3030" )
0 commit comments