@@ -929,7 +929,7 @@ test("processRequest-raise", async () => {
929
929
expect ( fetch ) . toHaveBeenCalledTimes ( 3 ) ;
930
930
} ) ;
931
931
932
- test ( "insertFeaturesIntoEvent -actionToken" , ( ) => {
932
+ test ( "createPartialEventWithSiteInfo -actionToken" , ( ) => {
933
933
const context = new TestContext ( testConfig ) ;
934
934
const req = new Request ( "https://www.example.com/teste2e" , {
935
935
headers : { "X-Recaptcha-Token" : "action-token" } ,
@@ -949,7 +949,7 @@ test("insertFeaturesIntoEvent-actionToken", () => {
949
949
} ) ;
950
950
} ) ;
951
951
952
- test ( "insertFeaturesIntoEvent -sessionToken" , ( ) => {
952
+ test ( "createPartialEventWithSiteInfo -sessionToken" , ( ) => {
953
953
const context = new TestContext ( testConfig ) ;
954
954
const req = new Request ( "https://www.example.com/test" , {
955
955
headers : { cookie : "recaptcha-test-t=session-token" } ,
@@ -969,7 +969,48 @@ test("insertFeaturesIntoEvent-sessionToken", () => {
969
969
} ) ;
970
970
} ) ;
971
971
972
- test ( "insertFeaturesIntoEvent-challengeToken" , ( ) => {
972
+ test ( "createPartialEventWithSiteInfo-strictSessionToken" , ( ) => {
973
+ const context = new TestContext ( testConfig ) ;
974
+ context . config . strict_cookie = true ;
975
+ const req = new Request ( "https://www.example.com/test" , {
976
+ headers : { cookie : "recaptcha-example-t=session-token" } ,
977
+ } ) ;
978
+ const site_info = createPartialEventWithSiteInfo ( context , req ) ;
979
+ const site_features = EventSchema . parse ( context . buildEvent ( req ) ) ;
980
+ const event = {
981
+ ...site_info ,
982
+ ...site_features ,
983
+ } ;
984
+ expect ( event ) . toEqual ( {
985
+ siteKey : "express-site-key" ,
986
+ express : true ,
987
+ userAgent : "test-user-agent" ,
988
+ userIpAddress : "1.2.3.4" ,
989
+ } ) ;
990
+ } ) ;
991
+
992
+ test ( "createPartialEventWithSiteInfo-nonStrictSessionToken" , ( ) => {
993
+ const context = new TestContext ( testConfig ) ;
994
+ context . config . strict_cookie = false ;
995
+ const req = new Request ( "https://www.example.com/test" , {
996
+ headers : { cookie : "recaptcha-example-t=session-token" } ,
997
+ } ) ;
998
+ const site_info = createPartialEventWithSiteInfo ( context , req ) ;
999
+ const site_features = EventSchema . parse ( context . buildEvent ( req ) ) ;
1000
+ const event = {
1001
+ ...site_info ,
1002
+ ...site_features ,
1003
+ } ;
1004
+ expect ( event ) . toEqual ( {
1005
+ token : "session-token" ,
1006
+ siteKey : "session-site-key" ,
1007
+ userAgent : "test-user-agent" ,
1008
+ wafTokenAssessment : true ,
1009
+ userIpAddress : "1.2.3.4" ,
1010
+ } ) ;
1011
+ } ) ;
1012
+
1013
+ test ( "createPartialEventWithSiteInfo-challengeToken" , ( ) => {
973
1014
const context = new TestContext ( testConfig ) ;
974
1015
const req = new Request ( "https://www.example.com/test" , {
975
1016
headers : { cookie : "recaptcha-test-e=challenge-token" } ,
@@ -989,7 +1030,28 @@ test("insertFeaturesIntoEvent-challengeToken", () => {
989
1030
} ) ;
990
1031
} ) ;
991
1032
992
- test ( "insertFeaturesIntoEvent-express" , ( ) => {
1033
+ test ( "createPartialEventWithSiteInfo-nonStrictChallengeToken" , ( ) => {
1034
+ const context = new TestContext ( testConfig ) ;
1035
+ context . config . strict_cookie = false ;
1036
+ const req = new Request ( "https://www.example.com/test" , {
1037
+ headers : { cookie : "recaptcha-example-e=challenge-token" } ,
1038
+ } ) ;
1039
+ const site_info = createPartialEventWithSiteInfo ( context , req ) ;
1040
+ const site_features = EventSchema . parse ( context . buildEvent ( req ) ) ;
1041
+ const event = {
1042
+ ...site_info ,
1043
+ ...site_features ,
1044
+ } ;
1045
+ expect ( event ) . toEqual ( {
1046
+ token : "challenge-token" ,
1047
+ siteKey : "challenge-page-site-key" ,
1048
+ userAgent : "test-user-agent" ,
1049
+ wafTokenAssessment : true ,
1050
+ userIpAddress : "1.2.3.4" ,
1051
+ } ) ;
1052
+ } ) ;
1053
+
1054
+ test ( "createPartialEventWithSiteInfo-express" , ( ) => {
993
1055
const context = new TestContext ( testConfig ) ;
994
1056
const req = new Request ( "https://www.example.com/test" , { } ) ;
995
1057
const site_info = createPartialEventWithSiteInfo ( context , req ) ;
0 commit comments