7
7
use CrowdSecBouncer \ApiCache ;
8
8
use CrowdSecBouncer \ApiClient ;
9
9
use CrowdSecBouncer \Bouncer ;
10
- use PHPUnit \Framework \MockObject \MockObject ;
11
10
use PHPUnit \Framework \TestCase ;
12
11
use Psr \Log \LoggerInterface ;
13
12
use Symfony \Component \Cache \Adapter \PhpFilesAdapter ;
@@ -46,7 +45,6 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
46
45
// Check if MaxMind database exist
47
46
if (!file_exists ($ maxmindConfig ['database_path ' ])) {
48
47
$ this ->fail ('There must be a MaxMind Database here: ' .$ maxmindConfig ['database_path ' ]);
49
- $ this ->stopFlag = true ; // Stop further processing if this occurs
50
48
}
51
49
// Init context
52
50
$ cacheAdapter = new PhpFilesAdapter ('php_array_adapter_backup_cache ' , 0 ,
@@ -81,9 +79,14 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
81
79
$ this ->assertEquals (
82
80
'captcha ' ,
83
81
$ bouncer ->getRemediationForIp (TestHelpers::IP_JAPAN ),
84
- 'Get decisions for a clean IP but bad country '
82
+ 'Get decisions for a clean IP but bad country (captcha) '
85
83
);
86
84
85
+ $ this ->assertEquals (
86
+ 'bypass ' ,
87
+ $ bouncer ->getRemediationForIp (TestHelpers::IP_FRANCE ),
88
+ 'Get decisions for a clean IP and clean country '
89
+ );
87
90
88
91
// Disable Geolocation feature
89
92
$ geolocationConfig ['enabled ' ] = false ;
@@ -98,5 +101,42 @@ public function testCanVerifyIpAndCountryWithMaxmindInLiveMode(array $maxmindCon
98
101
'Get decisions for a clean IP and bad country but with geolocation disabled '
99
102
);
100
103
104
+
105
+ // Enable again geolocation and change testing conditions
106
+ $ this ->watcherClient ->setSecondState ();
107
+ $ geolocationConfig ['enabled ' ] = true ;
108
+ $ bouncerConfig ['geolocation ' ] = $ geolocationConfig ;
109
+ $ bouncer = new Bouncer (null , $ this ->logger , $ apiCache );
110
+ $ bouncer ->configure ($ bouncerConfig );
111
+ $ cacheAdapter ->clear ();
112
+
113
+ $ this ->assertEquals (
114
+ 'ban ' ,
115
+ $ bouncer ->getRemediationForIp (TestHelpers::IP_JAPAN ),
116
+ 'Get decisions for a bad IP (ban) and bad country (captcha) '
117
+ );
118
+
119
+
120
+ $ this ->assertEquals (
121
+ 'ban ' ,
122
+ $ bouncer ->getRemediationForIp (TestHelpers::IP_FRANCE ),
123
+ 'Get decisions for a bad IP (ban) and clean country '
124
+ );
125
+
126
+ }
127
+
128
+
129
+ /**
130
+ * @group integration
131
+ * @covers \Bouncer
132
+ * @dataProvider maxmindConfigProvider
133
+ * @group ignore_
134
+ * @throws \Symfony\Component\Cache\Exception\CacheException
135
+ */
136
+ public function testCanVerifyIpAndCountryWithMaxmindInStreamMode (array $ maxmindConfig ):
137
+ void
138
+ {
139
+ $ this ->markTestIncomplete ('This test has not been implemented yet. ' );
140
+
101
141
}
102
142
}
0 commit comments