Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
SecurityManagerTest Class Reference
Inheritance diagram for SecurityManagerTest:

Public Member Functions

 setUp ()
 
 testPerformSecurityCheck ()
 
 testPerformSecurityCheckLimitNumber ()
 
 testPerformSecurityCheckLimitTime ()
 

Protected Member Functions

 tearDown ()
 
 getPasswordResetRequestEventCollection ()
 

Protected Attributes

 $securityManager
 
 $accountManagement
 
 $objectManager
 
 $passwordResetRequestEvent
 

Detailed Description

Definition at line 12 of file SecurityManagerTest.php.

Member Function Documentation

◆ getPasswordResetRequestEventCollection()

getPasswordResetRequestEventCollection ( )
protected

Get PasswordResetRequestEvent collection

Returns
\Magento\Security\Model\ResourceModel\PasswordResetRequestEvent\Collection

Definition at line 92 of file SecurityManagerTest.php.

93  {
94  $collection = $this->passwordResetRequestEvent->getResourceCollection();
95  $collection->load();
96 
97  return $collection;
98  }

◆ setUp()

setUp ( )

Set up

Definition at line 37 of file SecurityManagerTest.php.

38  {
39  $this->objectManager = Bootstrap::getObjectManager();
40  $this->accountManagement = $this->objectManager->create(
41  \Magento\Customer\Api\AccountManagementInterface::class
42  );
43  $this->securityManager = $this->objectManager->create(\Magento\Security\Model\SecurityManager::class);
44  $this->passwordResetRequestEvent = $this->objectManager
45  ->get(\Magento\Security\Model\PasswordResetRequestEvent::class);
46  }

◆ tearDown()

tearDown ( )
protected

Tear down

Definition at line 51 of file SecurityManagerTest.php.

52  {
53  $this->objectManager = null;
54  $this->accountManagement = null;
55  $this->securityManager = null;
56  parent::tearDown();
57  }

◆ testPerformSecurityCheck()

testPerformSecurityCheck ( )

Test for performSecurityCheck() method

@magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0 @magentoDbIsolation enabled

Definition at line 65 of file SecurityManagerTest.php.

66  {
68  $sizeBefore = $collection->getSize();
69 
71  $longIp = 127001;
72  $accountReference = '[email protected]';
73  $this->assertInstanceOf(
74  \Magento\Security\Model\SecurityManager::class,
75  $this->securityManager->performSecurityCheck(
76  $requestType,
77  $accountReference,
78  $longIp
79  )
80  );
81 
83  $sizeAfter = $collection->getSize();
84  $this->assertEquals(1, $sizeAfter - $sizeBefore);
85  }

◆ testPerformSecurityCheckLimitNumber()

testPerformSecurityCheckLimitNumber ( )

Test for performSecurityCheck() method when number of password reset events is exceeded

@magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 1 @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 1 @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 0 @magentoConfigFixture current_store contact/email/recipient_email hi@ex.nosp@m.ampl.nosp@m.e.com @expectedException \Magento\Framework\Exception\SecurityViolationException @magentoDbIsolation enabled

Definition at line 110 of file SecurityManagerTest.php.

111  {
112  $attempts = 2;
114  $longIp = 127001;
115  $accountReference = '[email protected]';
116 
117  try {
118  for ($i = 0; $i < $attempts; $i++) {
119  $this->securityManager->performSecurityCheck($requestType, $accountReference, $longIp);
120  }
121  } catch (\Magento\Framework\Exception\SecurityViolationException $e) {
122  $this->assertEquals(1, $i);
123  throw new \Magento\Framework\Exception\SecurityViolationException(
124  __($e->getMessage())
125  );
126  }
127 
128  $this->expectExceptionMessage(
129  'We received too many requests for password resets. '
130  . 'Please wait and try again later or contact [email protected].'
131  );
132  }
__()
Definition: __.php:13
$i
Definition: gallery.phtml:31

◆ testPerformSecurityCheckLimitTime()

testPerformSecurityCheckLimitTime ( )

Test for performSecurityCheck() method when time between password reset events is exceeded

@magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 1 @magentoConfigFixture current_store customer/password/max_number_password_reset_requests 0 @magentoConfigFixture current_store customer/password/min_time_between_password_reset_requests 1 @magentoConfigFixture current_store contact/email/recipient_email hi@ex.nosp@m.ampl.nosp@m.e.com @expectedException \Magento\Framework\Exception\SecurityViolationException @magentoDbIsolation enabled

Definition at line 144 of file SecurityManagerTest.php.

145  {
146  $attempts = 2;
148  $longIp = 127001;
149  $accountReference = '[email protected]';
150 
151  try {
152  for ($i = 0; $i < $attempts; $i++) {
153  $this->securityManager->performSecurityCheck($requestType, $accountReference, $longIp);
154  }
155  } catch (\Magento\Framework\Exception\SecurityViolationException $e) {
156  $this->assertEquals(1, $i);
157  throw new \Magento\Framework\Exception\SecurityViolationException(
158  __($e->getMessage())
159  );
160  }
161 
162  $this->fail('Something went wrong. Please check method execution logic.');
163 
164  $this->expectExceptionMessage(
165  'We received too many requests for password resets. '
166  . 'Please wait and try again later or contact [email protected].'
167  );
168  }
__()
Definition: __.php:13
$i
Definition: gallery.phtml:31

Field Documentation

◆ $accountManagement

$accountManagement
protected

Definition at line 22 of file SecurityManagerTest.php.

◆ $objectManager

$objectManager
protected

Definition at line 27 of file SecurityManagerTest.php.

◆ $passwordResetRequestEvent

$passwordResetRequestEvent
protected

Definition at line 32 of file SecurityManagerTest.php.

◆ $securityManager

$securityManager
protected

Definition at line 17 of file SecurityManagerTest.php.


The documentation for this class was generated from the following file: