Skip to content
Snippets Groups Projects
Commit 968bb5b3 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Merge branch '5.0.x' of git.drupal.org:project/restrict_ip into 5.0.x

parents 2ea8197f c8436f8c
Branches
Tags
No related merge requests found
File moved
...@@ -5,3 +5,4 @@ type: 'module' ...@@ -5,3 +5,4 @@ type: 'module'
configure: restrict_ip.admin_page configure: restrict_ip.admin_page
dependencies: dependencies:
- drupal:block - drupal:block
- drupal:user
...@@ -52,7 +52,7 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio ...@@ -52,7 +52,7 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
* *
* @var \Drupal\ip2country\Ip2CountryLookup|null * @var \Drupal\ip2country\Ip2CountryLookup|null
*/ */
protected $ip2CountryLookupService = NULL; protected ?Ip2CountryLookup $ip2CountryLookupService = NULL;
/** /**
* Constructs a RestrictIpService object. * Constructs a RestrictIpService object.
...@@ -78,7 +78,7 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio ...@@ -78,7 +78,7 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
*/ */
public function __construct( public function __construct(
protected AccountProxyInterface $currentUser, protected AccountProxyInterface $currentUser,
CurrentPathStack $currentPathStack, protected CurrentPathStack $currentPathStack,
protected ConfigFactoryInterface $configFactory, protected ConfigFactoryInterface $configFactory,
protected RequestStack $requestStack, protected RequestStack $requestStack,
protected RestrictIpMapperInterface $mapper, protected RestrictIpMapperInterface $mapper,
...@@ -97,16 +97,20 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio ...@@ -97,16 +97,20 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
* {@inheritDoc} * {@inheritDoc}
*/ */
public static function create(ContainerInterface $container): static { public static function create(ContainerInterface $container): static {
$ip2CountryLookupService = NULL;
if ($container->has('ip2country.lookup')) {
$ip2CountryLookupService = $container->get('ip2country.lookup');
}
return new static( return new static(
$container->get('current_user'), $container->get('current_user'),
$container->get('path.current'),
$container->get('config.factory'),
$container->get('request_stack'),
$container->get('restrict_ip.mapper'), $container->get('restrict_ip.mapper'),
$container->get('path.matcher'), $container->get('path.matcher'),
$container->get('module_handler'), $container->get('module_handler'),
$container->get('user.data'), $container->get('user.data'),
$container->get('path.current'), $ip2CountryLookupService
$container->get('config.factory'),
$container->get('request_stack'),
$container->get('ip2country.lookup'),
); );
} }
......
...@@ -27,6 +27,9 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase { ...@@ -27,6 +27,9 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/** /**
* Test that a user is blocked when the module is enabled. * Test that a user is blocked when the module is enabled.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Behat\Mink\Exception\ResponseTextException
*/ */
public function testModuleEnabled() { public function testModuleEnabled() {
$adminUser = $this->drupalCreateUser([ $adminUser = $this->drupalCreateUser([
...@@ -45,6 +48,9 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase { ...@@ -45,6 +48,9 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/** /**
* Test that a user is not blocked if their IP address is whitelisted. * Test that a user is not blocked if their IP address is whitelisted.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Behat\Mink\Exception\ResponseTextException
*/ */
public function testIpWhitelist() { public function testIpWhitelist() {
$adminUser = $this->drupalCreateUser([ $adminUser = $this->drupalCreateUser([
...@@ -61,8 +67,6 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase { ...@@ -61,8 +67,6 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
$this->fillTextValue('edit-address-list', $_SERVER['REMOTE_ADDR'] . PHP_EOL . '::1'); $this->fillTextValue('edit-address-list', $_SERVER['REMOTE_ADDR'] . PHP_EOL . '::1');
$this->click('#edit-submit'); $this->click('#edit-submit');
$this->assertSession()->pageTextNotContains('The page you are trying to access cannot be accessed from your IP address.'); $this->assertSession()->pageTextNotContains('The page you are trying to access cannot be accessed from your IP address.');
return $adminUser;
} }
/** /**
...@@ -113,7 +117,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase { ...@@ -113,7 +117,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
$this->click('#edit-submit'); $this->click('#edit-submit');
$admin_role = $this->createRole(['bypass ip restriction']); $admin_role = $this->createRole(['bypass ip restriction']);
$adminUser->addRole($admin_role); $adminUser->addRole($admin_role)->save();
$this->checkCheckbox('#edit-enable'); $this->checkCheckbox('#edit-enable');
$this->click('#edit-submit'); $this->click('#edit-submit');
...@@ -158,7 +162,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase { ...@@ -158,7 +162,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
$this->click('#edit-submit'); $this->click('#edit-submit');
$admin_role = $this->createRole(['bypass ip restriction']); $admin_role = $this->createRole(['bypass ip restriction']);
$adminUser->addRole($admin_role); $adminUser->addRole($admin_role)->save();
$this->checkCheckbox('#edit-enable'); $this->checkCheckbox('#edit-enable');
$this->click('#edit-submit'); $this->click('#edit-submit');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment