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

More fixes

parent 89c26c43
Branches
Tags
1 merge request!27Resolve #3495439 "Round2"
......@@ -27,7 +27,7 @@ class PageController extends ControllerBase implements PageControllerInterface {
/**
* {@inheritdoc}
*/
public function accessDeniedPage(): RedirectResponse {
public function accessDeniedPage(): RedirectResponse|array {
if (!isset($_SESSION['restrict_ip']) || !$_SESSION['restrict_ip']) {
return new RedirectResponse(Url::fromRoute('<front>')->toString());
}
......
......@@ -17,6 +17,6 @@ interface PageControllerInterface {
/**
* Provides the Access Denied page for the Restrict IP module.
*/
public function accessDeniedPage(): RedirectResponse;
public function accessDeniedPage(): RedirectResponse|array;
}
......@@ -71,7 +71,7 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
* The Path Matcher service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The Module Handler service.
* @param \Drupal\user\UserDataInterface $userData
* @param \Drupal\user\UserDataInterface|null $userData
* The User Data service.
* @param \Drupal\ip2country\Ip2CountryLookup|null $ip2CountryLookupService
* An ip2CountryLookupService object.
......@@ -84,7 +84,7 @@ class RestrictIpService implements RestrictIpServiceInterface, ContainerInjectio
protected RestrictIpMapperInterface $mapper,
protected PathMatcherInterface $pathMatcher,
protected ModuleHandlerInterface $moduleHandler,
protected UserDataInterface $userData,
protected ?UserDataInterface $userData = NULL,
?Ip2CountryLookup $ip2CountryLookupService = NULL,
) {
$this->currentPath = strtolower($currentPathStack->getPath());
......
......@@ -67,8 +67,11 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Tests if the email address can be entered.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Behat\Mink\Exception\ResponseTextException
*/
public function testEmailAddressDisplays() {
public function testEmailAddressDisplays(): void {
$adminUser = $this->drupalCreateUser([
'administer restricted ip addresses',
'access administration pages',
......@@ -87,8 +90,12 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Tests if access can be bypassed with the right permission.
*
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Behat\Mink\Exception\ExpectationException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testAccessBypassByRole() {
public function testAccessBypassByRole(): void {
$adminUser = $this->drupalCreateUser([
'administer restricted ip addresses',
'access administration pages',
......@@ -129,8 +136,10 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Tests if redirect with the right permission.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testRedirectToLoginWhenBypassByRoleEnabled() {
public function testRedirectToLoginWhenBypassByRoleEnabled(): void {
$adminUser = $this->drupalCreateUser([
'administer restricted ip addresses',
'access administration pages',
......@@ -160,8 +169,11 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Tests whitelisting paths.
*
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testWhitelistedPaths() {
public function testWhitelistedPaths(): void {
$adminUser = $this->drupalCreateUser([
'administer restricted ip addresses',
'access administration pages',
......@@ -190,8 +202,11 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Tests blacklisting paths.
*
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testBlacklistedPaths() {
public function testBlacklistedPaths(): void {
$adminUser = $this->drupalCreateUser([
'administer restricted ip addresses',
'access administration pages',
......@@ -221,7 +236,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Helper function to create an article content type.
*/
private function createArticleContentType() {
private function createArticleContentType(): void {
$type = $this->container->get('entity_type.manager')->getStorage('node_type')
->create([
'type' => 'article',
......@@ -234,7 +249,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
/**
* Helper function to create an article.
*/
private function createArticle() {
private function createArticle(): void {
static $counter;
if (!$counter) {
......@@ -248,9 +263,7 @@ class RestrictIpAccessTest extends RestrictIpBrowserTestBase {
]);
$node->save();
$this->container->get('router.builder')->rebuild();
$counter += 1;
}
......
......@@ -171,7 +171,7 @@ class RestrictIpServiceTest extends UnitTestCase {
['/user/password', FALSE],
['/user/logout', FALSE],
['/user/reset/something', FALSE],
['/invalid/path', NULL],
['/invalid/path', FALSE],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment