Skip to content
Snippets Groups Projects
Commit 5f47789a authored by liuba's avatar liuba Committed by Florent Torregrosa
Browse files

Issue #3210239 by liuba, Grimreaper, C-Logemann: The url check on admin form...

Issue #3210239 by liuba, Grimreaper, C-Logemann: The url check on admin form validation is too retrictive
parent aa026cdd
Branches
Tags
1 merge request!23Issue #3210239: The url check on admin form validation is too retrictive
...@@ -115,11 +115,6 @@ class MatomoAdminSettingsForm extends ConfigFormBase { ...@@ -115,11 +115,6 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
'#title' => $this->t('Matomo HTTPS URL'), '#title' => $this->t('Matomo HTTPS URL'),
'#type' => 'textfield', '#type' => 'textfield',
]; ];
// Required for automated form save testing only.
$form['general']['matomo_url_skiperror'] = [
'#type' => 'hidden',
'#default_value' => FALSE,
];
// Visibility settings. // Visibility settings.
$form['tracking_scope'] = [ $form['tracking_scope'] = [
...@@ -614,11 +609,10 @@ class MatomoAdminSettingsForm extends ConfigFormBase { ...@@ -614,11 +609,10 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
$form_state->setValueForElement($form['general']['matomo_url_http'], $url); $form_state->setValueForElement($form['general']['matomo_url_http'], $url);
} }
$url = $url . 'matomo.php'; $url = $url . 'matomo.php';
$skip_error_check = $form_state->getValue('matomo_url_skiperror');
try { try {
$result = $this->httpClient->request('GET', $url); $result = $this->httpClient->request('GET', $url);
if (!$skip_error_check && $result->getStatusCode() != 200) { if ($result->getStatusCode() != 200) {
$form_state->setErrorByName('matomo_url_http', $this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [ $this->messenger()->addWarning($this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url), '@url' => UrlHelper::filterBadProtocol($url),
'@error' => $result->getReasonPhrase(), '@error' => $result->getReasonPhrase(),
'@code' => $result->getStatusCode(), '@code' => $result->getStatusCode(),
...@@ -626,13 +620,11 @@ class MatomoAdminSettingsForm extends ConfigFormBase { ...@@ -626,13 +620,11 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
} }
} }
catch (RequestException $exception) { catch (RequestException $exception) {
if (!$skip_error_check) { $this->messenger()->addWarning($this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [
$form_state->setErrorByName('matomo_url_http', $this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [ '@url' => UrlHelper::filterBadProtocol($url),
'@url' => UrlHelper::filterBadProtocol($url), '@error' => $exception->getMessage(),
'@error' => $exception->getMessage(), '@code' => $exception->getCode(),
'@code' => $exception->getCode(), ]));
]));
}
} }
$matomo_url_https = $form_state->getValue('matomo_url_https'); $matomo_url_https = $form_state->getValue('matomo_url_https');
...@@ -645,8 +637,8 @@ class MatomoAdminSettingsForm extends ConfigFormBase { ...@@ -645,8 +637,8 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
$url = $url . 'matomo.php'; $url = $url . 'matomo.php';
try { try {
$result = $this->httpClient->request('GET', $url); $result = $this->httpClient->request('GET', $url);
if (!$skip_error_check && $result->getStatusCode() != 200) { if ($result->getStatusCode() != 200) {
$form_state->setErrorByName('matomo_url_https', $this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [ $this->messenger()->addWarning($this->t('The validation of "@url" failed with error "@error" (HTTP code @code).', [
'@url' => UrlHelper::filterBadProtocol($url), '@url' => UrlHelper::filterBadProtocol($url),
'@error' => $result->getReasonPhrase(), '@error' => $result->getReasonPhrase(),
'@code' => $result->getStatusCode(), '@code' => $result->getStatusCode(),
...@@ -654,13 +646,11 @@ class MatomoAdminSettingsForm extends ConfigFormBase { ...@@ -654,13 +646,11 @@ class MatomoAdminSettingsForm extends ConfigFormBase {
} }
} }
catch (RequestException $exception) { catch (RequestException $exception) {
if (!$skip_error_check) { $this->messenger()->addWarning($this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [
$form_state->setErrorByName('matomo_url_https', $this->t('The validation of "@url" failed with an exception "@error" (HTTP code @code).', [ '@url' => UrlHelper::filterBadProtocol($url),
'@url' => UrlHelper::filterBadProtocol($url), '@error' => $exception->getMessage(),
'@error' => $exception->getMessage(), '@code' => $exception->getCode(),
'@code' => $exception->getCode(), ]));
]));
}
} }
} }
......
...@@ -75,8 +75,7 @@ class MatomoPhpFilterTest extends BrowserTestBase { ...@@ -75,8 +75,7 @@ class MatomoPhpFilterTest extends BrowserTestBase {
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/system/matomo'); $this->drupalGet('admin/config/system/matomo');
$page->find('css', '[name="matomo_url_skiperror"]')
->setValue(TRUE);
$edit = []; $edit = [];
$edit['matomo_site_id'] = $site_id; $edit['matomo_site_id'] = $site_id;
$edit['matomo_url_http'] = 'http://www.example.com/matomo/'; $edit['matomo_url_http'] = 'http://www.example.com/matomo/';
...@@ -118,8 +117,6 @@ class MatomoPhpFilterTest extends BrowserTestBase { ...@@ -118,8 +117,6 @@ class MatomoPhpFilterTest extends BrowserTestBase {
$this->config('matomo.settings')->set('visibility.request_path_pages', '<?php return 0; ?>')->save(); $this->config('matomo.settings')->set('visibility.request_path_pages', '<?php return 0; ?>')->save();
$this->drupalGet('admin/config/system/matomo'); $this->drupalGet('admin/config/system/matomo');
$page->find('css', '[name="matomo_url_skiperror"]')
->setValue(TRUE);
$edit = []; $edit = [];
$edit['matomo_site_id'] = $site_id; $edit['matomo_site_id'] = $site_id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment