@@ -164,6 +164,30 @@ public function testValidateReportParametersShouldThrowMicrosoftTeamsWebhookUrlE
164164 Piwik::postEvent ('ScheduledReports.validateReportParameters ' , [&$ parameters , 'teams ' ]);
165165 }
166166
167+ public function testValidateReportParametersShouldThrowMicrosoftTeamsWebhookUrlExceptionForIntegerLoopbackAlias ()
168+ {
169+ $ this ->setRequiredFields ();
170+ $ this ->expectException (\Exception::class);
171+ $ this ->expectExceptionMessage ('MicrosoftTeams_IncomingWebhookInvalidErrorMessage ' );
172+ $ parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY , MicrosoftTeams::MS_TEAMS_INCOMING_WEBHOOK_URL_PARAMETER => 'http://2130706433:18081/hook ' ];
173+ Piwik::postEvent ('ScheduledReports.validateReportParameters ' , [&$ parameters , 'teams ' ]);
174+ }
175+
176+ /**
177+ * @dataProvider provideWebhookUrlsWithIpHosts
178+ */
179+ public function testValidateReportParametersShouldThrowMicrosoftTeamsWebhookUrlExceptionForIpHosts ($ webhookUrl )
180+ {
181+ $ this ->setRequiredFields ();
182+ $ this ->expectException (\Exception::class);
183+ $ this ->expectExceptionMessage ('MicrosoftTeams_IncomingWebhookInvalidErrorMessage ' );
184+ $ parameters = [
185+ ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY ,
186+ MicrosoftTeams::MS_TEAMS_INCOMING_WEBHOOK_URL_PARAMETER => $ webhookUrl ,
187+ ];
188+ Piwik::postEvent ('ScheduledReports.validateReportParameters ' , [&$ parameters , 'teams ' ]);
189+ }
190+
167191 public function testValidateCustomAlertReportParametersShouldThrowMicrosoftTeamsWebhookUrInvalidException ()
168192 {
169193 $ this ->setRequiredFields ();
@@ -200,6 +224,27 @@ public function testValidateCustomAlertReportParametersShouldThrowMicrosoftTeams
200224 Piwik::postEvent ('CustomAlerts.validateReportParameters ' , [$ parameters , 'teams ' ]);
201225 }
202226
227+ public function testValidateCustomAlertReportParametersShouldThrowMicrosoftTeamsWebhookUrlExceptionForIntegerLoopbackAlias ()
228+ {
229+ $ this ->setRequiredFields ();
230+ $ this ->expectException (\Exception::class);
231+ $ this ->expectExceptionMessage ('MicrosoftTeams_IncomingWebhookInvalidErrorMessage ' );
232+ $ parameters = [MicrosoftTeams::MS_TEAMS_INCOMING_WEBHOOK_URL_PARAMETER => 'http://2130706433:18081/hook ' ];
233+ Piwik::postEvent ('CustomAlerts.validateReportParameters ' , [$ parameters , 'teams ' ]);
234+ }
235+
236+ /**
237+ * @dataProvider provideWebhookUrlsWithIpHosts
238+ */
239+ public function testValidateCustomAlertReportParametersShouldThrowMicrosoftTeamsWebhookUrlExceptionForIpHosts ($ webhookUrl )
240+ {
241+ $ this ->setRequiredFields ();
242+ $ this ->expectException (\Exception::class);
243+ $ this ->expectExceptionMessage ('MicrosoftTeams_IncomingWebhookInvalidErrorMessage ' );
244+ $ parameters = [MicrosoftTeams::MS_TEAMS_INCOMING_WEBHOOK_URL_PARAMETER => $ webhookUrl ];
245+ Piwik::postEvent ('CustomAlerts.validateReportParameters ' , [$ parameters , 'teams ' ]);
246+ }
247+
203248 public function testValidateReportParametersMicrosoftTeamsShouldNotThrowAnyException ()
204249 {
205250 $ this ->setRequiredFields ();
@@ -224,6 +269,15 @@ public function testValidateReportParametersMicrosoftTeamsShouldNotThrowAnyExcep
224269 $ this ->assertNotEmpty ($ parameters );
225270 }
226271
272+ public function provideWebhookUrlsWithIpHosts ()
273+ {
274+ return [
275+ 'ipv4 ' => ['https://8.8.8.8/hook ' ],
276+ 'ipv4 ' => ['https://10.6.4.2 ' ],
277+ 'ipv6 ' => ['https://[2001:4860:4860::8888]/hook ' ],
278+ ];
279+ }
280+
227281 private function assertHasReport ($ login , $ idSite )
228282 {
229283 $ report = $ this ->getReport ($ login , $ idSite );
0 commit comments