Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
flood_control
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
flood_control
Merge requests
!40
Issue
#3350592
: Fix the issues reported by PHPCS
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3350592
: Fix the issues reported by PHPCS
issue/flood_control-3350592:3350592-fix-the-issues
into
2.3.x
Overview
0
Commits
1
Pipelines
0
Changes
3
Open
Urvashi Vora
requested to merge
issue/flood_control-3350592:3350592-fix-the-issues
into
2.3.x
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
Closes
#3350592
0
0
Merge request reports
Compare
2.3.x
2.3.x (base)
and
latest version
latest version
afda100d
1 commit,
2 years ago
3 files
+
4
−
111
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
Conflict: This file was removed in the source branch, but modified in the target branch. Ask someone with write access to resolve it.
tests/src/Functional/FloodControlLoginTest.php deleted
100644 → 0
+
0
−
109
Options
<?php
namespace
Drupal\Tests\FloodControl\Functional
;
use
Drupal\Tests\BrowserTestBase
;
/**
* Tests the flood settings when log in attempts fail.
*
* @group flood_control
*/
class
FloodControlIpLoginTest
extends
BrowserTestBase
{
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'flood_control'
];
/**
* {@inheritdoc}
*/
protected
$defaultTheme
=
'stark'
;
/**
* User with the permission to access the flood unblock settings.
*
* @var \Drupal\user\Entity\User
*/
protected
$adminUser
;
/**
* A regular user.
*
* @var \Drupal\user\Entity\User
*/
protected
$webUser
;
/**
* The module installer.
*
* @var \Drupal\Core\Extension\ModuleInstallerInterface
*/
protected
$moduleInstaller
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
moduleInstaller
=
$this
->
container
->
get
(
'module_installer'
);
// Defines a user that can configure the module.
$this
->
adminUser
=
$this
->
createUser
([
'administer site configuration'
]);
// Defines a user that can unblock.
$this
->
unblockUser
=
$this
->
drupalCreateUser
([
'access flood unblock'
]);
}
/**
* Test blockin ip addresses after multiple login attempts.
*/
public
function
testIpLoginLimit
()
{
$database
=
\Drupal
::
database
();
// Removes all flood entries for a fresh start.
if
(
$database
->
schema
()
->
tableExists
(
'flood'
))
{
$database
->
truncate
(
'flood'
)
->
execute
();
}
// Sets the maximum number of ip address login attempts to 3.
$this
->
config
(
'user.flood'
)
->
set
(
'ip_limit'
,
3
)
->
save
();
// Attempts 3 logins with the wrong credentials.
for
(
$i
=
0
;
$i
<
3
;
$i
++
)
{
$this
->
drupalGet
(
'/user/login'
);
$this
->
submitForm
([
'name'
=>
'wrong-name'
,
'pass'
=>
'wrong-pass'
,
],
'Log in'
);
$this
->
assertSession
()
->
pageTextContains
(
'Unrecognized username or password'
);
}
// Attempts 4th login with wrong credentials to check if ip address is
// added to the flood table.
$this
->
drupalGet
(
'/user/login'
);
$this
->
submitForm
([
'name'
=>
'wrong-name'
,
'pass'
=>
'wrong-pass'
,
],
'Log in'
);
$this
->
assertSession
()
->
pageTextNotContains
(
'Unrecognized username or password'
);
$this
->
assertSession
()
->
pageTextContains
(
'Login failed'
);
$this
->
assertSession
()
->
pageTextContains
(
'Too many failed login attempts from your IP address'
);
// Checks if IP address has been added to the flood table.
$blocked_addresses
=
$database
->
select
(
'flood'
,
'f'
)
->
fields
(
'f'
,
[
'fid'
])
->
condition
(
'identifier'
,
'127.0.0.1'
)
->
condition
(
'event'
,
'user.failed_login_ip'
)
->
execute
()
->
fetchAll
();
$this
->
assertGreaterThanOrEqual
(
1
,
count
(
$blocked_addresses
),
'Blocked IP address not found in flood table'
);
}
}
Loading