Esempio n. 1
0
 public function testExecuteNonRandomAndWithCryptKey()
 {
     $expectedMessage = 'The encryption key has been changed.';
     $key = 1;
     $newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
     $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(0);
     $this->requestMock->expects($this->at(1))->method('getPost')->with($this->equalTo('crypt_key'))->willReturn($key);
     $this->encryptMock->expects($this->once())->method('validateKey');
     $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
     $this->managerMock->expects($this->once())->method('addSuccessMessage')->with($expectedMessage);
     $this->cacheMock->expects($this->once())->method('clean');
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->model->execute();
 }
Esempio n. 2
0
 public function testDecrypt()
 {
     $data = 'data';
     $encryptedData = 'd1a2t3a4';
     $this->encryptorInterfaceMock->expects($this->once())->method('decrypt')->with($encryptedData)->will($this->returnValue($data));
     $this->assertEquals($data, $this->info->decrypt($encryptedData));
 }
Esempio n. 3
0
 public function testAdminAuthenticate()
 {
     $password = "******";
     $uid = 123;
     $authResult = true;
     $lockExpires = false;
     $userPassword = ['expires' => 1];
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getPassword', 'getUser', 'getResult'])->getMock();
     /** @var ModelUser|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getLockExpires', 'getPassword', 'save'])->getMock();
     $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getPassword')->willReturn($password);
     $eventMock->expects($this->once())->method('getUser')->willReturn($userMock);
     $eventMock->expects($this->once())->method('getResult')->willReturn($authResult);
     $userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid);
     $userMock->expects($this->once())->method('getLockExpires')->willReturn($lockExpires);
     $this->userMock->expects($this->once())->method('unlock');
     $this->userMock->expects($this->once())->method('getLatestPassword')->willReturn($userPassword);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getLastAddedMessage')->willReturn($this->messageInterfaceMock);
     $this->messageInterfaceMock->expects($this->once())->method('setIdentifier')->willReturnSelf();
     $this->authSessionMock->expects($this->once())->method('setPciAdminUserIsPasswordExpired');
     $this->encryptorMock->expects($this->once())->method('validateHashVersion')->willReturn(false);
     $this->model->execute($eventObserverMock);
 }
 /**
  * Run test for saveTokenWithPaymentLink method
  */
 public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible()
 {
     /** @var OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject $paymentMock */
     $paymentMock = $this->getMock(OrderPaymentInterface::class);
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
     $tokenMock = $this->getMock(PaymentTokenInterface::class);
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $duplicateToken */
     $duplicateToken = $this->getMock(PaymentTokenInterface::class);
     $entityId = 1;
     $newEntityId = 1;
     $paymentId = 1;
     $customerId = 1;
     $gatewayToken = 'xs4vf3';
     $publicHash = 'existing-token';
     $duplicateTokenData = ['entity_id' => $entityId];
     $newHash = 'new-token2';
     $tokenMock->expects(static::atLeastOnce())->method('getPublicHash')->willReturn($publicHash);
     $tokenMock->expects(static::atLeastOnce())->method('getCustomerId')->willReturn($customerId);
     $this->paymentTokenResourceModelMock->expects(self::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($duplicateTokenData);
     $this->paymentTokenFactoryMock->expects(self::once())->method('create')->with(['data' => $duplicateTokenData])->willReturn($duplicateToken);
     $tokenMock->expects(static::atLeastOnce())->method('getIsVisible')->willReturn(false);
     $tokenMock->expects(static::atLeastOnce())->method('getCustomerId')->willReturn($customerId);
     $tokenMock->expects(static::atLeastOnce())->method('getGatewayToken')->willReturn($gatewayToken);
     $this->encryptorMock->expects(static::once())->method('getHash')->with($publicHash . $gatewayToken)->willReturn($newHash);
     $tokenMock->expects(static::once())->method('setPublicHash')->with($newHash);
     $this->paymentTokenRepositoryMock->expects(self::once())->method('save')->with($tokenMock);
     $tokenMock->expects(static::atLeastOnce())->method('getEntityId')->willReturn($newEntityId);
     $paymentMock->expects(self::atLeastOnce())->method('getEntityId')->willReturn($paymentId);
     $this->paymentTokenResourceModelMock->expects(static::once())->method('addLinkToOrderPayment')->with($newEntityId, $paymentId);
     $this->paymentTokenManagement->saveTokenWithPaymentLink($tokenMock, $paymentMock);
 }
Esempio n. 5
0
 public function testVerifyIdentityNoAssignedRoles()
 {
     $password = '******';
     $this->_encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->_model->getPassword())->will($this->returnValue(true));
     $this->_model->setIsActive(true);
     $this->_resourceMock->expects($this->once())->method('hasAssigned2Role')->will($this->returnValue(false));
     $this->setExpectedException('Magento\\Framework\\Exception\\AuthenticationException', 'Access denied.');
     $this->_model->verifyIdentity($password);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreateAccountWithPassword()
 {
     $websiteId = 1;
     $storeId = null;
     $defaultStoreId = 1;
     $customerId = 1;
     $customerEmail = '*****@*****.**';
     $password = '******';
     $hash = '4nj54lkj5jfi03j49f8bgujfgsd';
     $newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $this->string->expects($this->any())->method('strlen')->willReturnCallback(function ($string) {
         return strlen($string);
     });
     $this->encryptor->expects($this->once())->method('getHash')->with($password, true)->willReturn($hash);
     $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $address->expects($this->once())->method('setCustomerId')->with($customerId);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getId')->willReturn($defaultStoreId);
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->atLeastOnce())->method('getStoreIds')->willReturn([1, 2, 3]);
     $website->expects($this->once())->method('getDefaultStore')->willReturn($store);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $customer->expects($this->atLeastOnce())->method('getEmail')->willReturn($customerEmail);
     $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
     $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $customer->expects($this->once())->method('setStoreId')->with($defaultStoreId);
     $customer->expects($this->once())->method('getAddresses')->willReturn([$address]);
     $customer->expects($this->once())->method('setAddresses')->with(null);
     $this->customerRepository->expects($this->once())->method('get')->with($customerEmail)->willReturn($customer);
     $this->share->expects($this->once())->method('isWebsiteScope')->willReturn(true);
     $this->storeManager->expects($this->atLeastOnce())->method('getWebsite')->with($websiteId)->willReturn($website);
     $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
     $this->addressRepository->expects($this->atLeastOnce())->method('save')->with($address);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->random->expects($this->once())->method('getUniqueHash')->willReturn($newLinkToken);
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->any())->method('setRpToken')->with($newLinkToken);
     $customerSecure->expects($this->any())->method('setRpTokenCreatedAt');
     $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($customerSecure);
     $this->dataObjectProcessor->expects($this->once())->method('buildOutputDataArray')->willReturn([]);
     $this->scopeConfig->expects($this->at(1))->method('getValue')->with(AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId)->willReturn($templateIdentifier);
     $this->scopeConfig->expects($this->at(2))->method('getValue')->willReturn($sender);
     $transport = $this->getMockBuilder('Magento\\Framework\\Mail\\TransportInterface')->getMock();
     $this->transportBuilder->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setTemplateOptions')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setTemplateVars')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('addTo')->willReturnSelf();
     $this->transportBuilder->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->accountManagement->createAccount($customer, $password);
 }
Esempio n. 7
0
 /**
  * @dataProvider authenticateDataProvider
  * @param string $usernameIn
  * @param string $usernameOut
  * @param bool $expectedResult
  * @return void
  */
 public function testAuthenticate($usernameIn, $usernameOut, $expectedResult)
 {
     $password = '******';
     $config = 'config';
     $data = ['id' => 1, 'is_active' => 1, 'username' => $usernameOut];
     $this->configMock->expects($this->once())->method('isSetFlag')->with('admin/security/use_case_sensitive_login')->willReturn($config);
     $this->eventManagerMock->expects($this->any())->method('dispatch');
     $this->resourceMock->expects($this->any())->method('loadByUsername')->willReturn($data);
     $this->model->setIdFieldName('id');
     $this->encryptorMock->expects($this->any())->method('validateHash')->willReturn(true);
     $this->resourceMock->expects($this->any())->method('hasAssigned2Role')->willReturn(true);
     $this->assertEquals($expectedResult, $this->model->authenticate($usernameIn, $password));
 }
 public function testTrackAdminPassword()
 {
     $newPW = "mYn3wpassw0rd";
     $oldPW = "notsecure";
     $uid = 123;
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getObject'])->getMock();
     /** @var \Magento\User\Model\User|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getCurrentPassword', 'getForceNewPassword'])->getMock();
     $eventObserverMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getObject')->willReturn($userMock);
     $userMock->expects($this->once())->method('getId')->willReturn($uid);
     $userMock->expects($this->once())->method('getCurrentPassword')->willReturn($newPW);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     $userMock->expects($this->once())->method('getForceNewPassword')->willReturn(false);
     $this->encryptorMock->expects($this->once())->method('getHash')->willReturn(md5($oldPW));
     /** @var \Magento\Framework\Message\Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock);
     $this->authSessionMock->expects($this->once())->method('unsPciAdminUserIsPasswordExpired')->willReturn(null);
     $this->model->execute($eventObserverMock);
 }
 public function testCheckAdminPasswordChangeThrowsLocalizedExp()
 {
     $newPW = "mYn3wpassw0rd";
     $uid = 123;
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getObject'])->getMock();
     /** @var \Magento\User\Model\User|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getNewPassword', 'getForceNewPassword'])->getMock();
     $eventObserverMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getObject')->willReturn($userMock);
     $userMock->expects($this->atLeastOnce())->method('getNewPassword')->willReturn($newPW);
     $userMock->expects($this->once())->method('getForceNewPassword')->willReturn(false);
     $userMock->expects($this->once())->method('getId')->willReturn($uid);
     $this->encryptorMock->expects($this->once())->method('isValidHash')->willReturn(true);
     $this->userMock->method('getOldPasswords')->willReturn([md5('pw1'), md5('pw2')]);
     try {
         $this->model->execute($eventObserverMock);
     } catch (\Magento\Framework\Exception\LocalizedException $expected) {
         return;
     }
     $this->fail('An expected exception has not been raised.');
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreateAccountWithPassword()
 {
     $websiteId = 1;
     $storeId = null;
     $defaultStoreId = 1;
     $customerId = 1;
     $customerEmail = '*****@*****.**';
     $hash = '4nj54lkj5jfi03j49f8bgujfgsd';
     $newLinkToken = '2jh43j5h2345jh23lh452h345hfuzasd96ofu';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $password = '******';
     $minPasswordLength = 5;
     $minCharacterSetsNum = 2;
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturnMap([[AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH, 'default', null, $minPasswordLength], [AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER, 'default', null, $minCharacterSetsNum], [AccountManagement::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $defaultStoreId, $templateIdentifier], [AccountManagement::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, 1, $sender]]);
     $this->string->expects($this->any())->method('strlen')->with($password)->willReturn(iconv_strlen($password, 'UTF-8'));
     $this->encryptor->expects($this->once())->method('getHash')->with($password, true)->willReturn($hash);
     $address = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
     $address->expects($this->once())->method('setCustomerId')->with($customerId);
     $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getId')->willReturn($defaultStoreId);
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->atLeastOnce())->method('getStoreIds')->willReturn([1, 2, 3]);
     $website->expects($this->once())->method('getDefaultStore')->willReturn($store);
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $customer->expects($this->atLeastOnce())->method('getEmail')->willReturn($customerEmail);
     $customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
     $customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
     $customer->expects($this->once())->method('setStoreId')->with($defaultStoreId);
     $customer->expects($this->once())->method('getAddresses')->willReturn([$address]);
     $customer->expects($this->once())->method('setAddresses')->with(null);
     $this->customerRepository->expects($this->once())->method('get')->with($customerEmail)->willReturn($customer);
     $this->share->expects($this->once())->method('isWebsiteScope')->willReturn(true);
     $this->storeManager->expects($this->atLeastOnce())->method('getWebsite')->with($websiteId)->willReturn($website);
     $this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
     $this->addressRepository->expects($this->atLeastOnce())->method('save')->with($address);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->random->expects($this->once())->method('getUniqueHash')->willReturn($newLinkToken);
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->any())->method('setRpToken')->with($newLinkToken);
     $customerSecure->expects($this->any())->method('setRpTokenCreatedAt');
     $customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieveSecureData')->willReturn($customerSecure);
     $this->emailNotificationMock->expects($this->once())->method('newAccount')->willReturnSelf();
     $this->accountManagement->createAccount($customer, $password);
 }
Esempio n. 11
0
 public function testCheckPasswordChangeValid()
 {
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(true);
     $newPassword = "******";
     $newPasswordHash = "new password hash";
     $oldPassword = "******";
     $this->model->setPassword($newPassword)->setId(1)->setOrigData('password', $oldPassword);
     $this->encryptorMock->expects($this->once())->method('isValidHash')->with($newPassword, $oldPassword)->willReturn(false);
     $this->encryptorMock->expects($this->once())->method('getHash')->with($newPassword, false)->willReturn($newPasswordHash);
     $this->resourceMock->expects($this->once())->method('getOldPasswords')->willReturn(['hash1', 'hash2']);
     $result = $this->model->validate();
     $this->assertTrue($result);
 }
 /**
  * Test for performIdentityCheck method
  *
  * @param bool $verifyIdentityResult
  * @param bool $lockExpires
  * @dataProvider dataProviderPerformIdentityCheck
  */
 public function testPerformIdentityCheck($verifyIdentityResult, $lockExpires)
 {
     $password = '******';
     $userName = '******';
     $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $this->model->getPassword())->willReturn($verifyIdentityResult);
     $this->model->setIsActive(true);
     $this->resourceMock->expects($this->any())->method('hasAssigned2Role')->willReturn(true);
     $this->model->setUserName($userName);
     $this->model->setLockExpires($lockExpires);
     $this->eventManagerMock->expects($this->any())->method('dispatch')->with('admin_user_authenticate_after', ['username' => $userName, 'password' => $password, 'user' => $this->model, 'result' => $verifyIdentityResult])->willReturnSelf();
     if ($lockExpires) {
         $this->setExpectedException('\\Magento\\Framework\\Exception\\State\\UserLockedException', __('Your account is temporarily disabled.'));
     }
     if (!$verifyIdentityResult) {
         $this->setExpectedException('\\Magento\\Framework\\Exception\\AuthenticationException', __('You have entered an invalid password for current user.'));
     }
     $this->model->performIdentityCheck($password);
 }
Esempio n. 13
0
 /**
  * @param bool $result
  * @dataProvider validateCustomerPassword
  */
 public function testValidateCustomerPassword($result)
 {
     $customerId = 7;
     $password = '******';
     $hash = '1b2af329dd0';
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->willReturn($customerMock);
     $this->customerSecure->expects($this->any())->method('getId')->willReturn($customerId);
     $this->customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistryMock->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
     $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $hash)->willReturn($result);
     if ($result) {
         $this->assertTrue($this->authentication->authenticate($customerId, $password));
     } else {
         $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Model\Authentication::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Model\Authentication::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(1, 1);
         $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(false);
         $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure);
         $this->customerRepositoryMock->expects($this->once())->method('save')->willReturn($customerMock);
         $this->setExpectedException('\\Magento\\Framework\\Exception\\InvalidEmailOrPasswordException');
         $this->authentication->authenticate($customerId, $password);
     }
 }
 /**
  * @return void
  */
 public function testChangePassword()
 {
     $customerId = 7;
     $email = '*****@*****.**';
     $currentPassword = '******';
     $newPassword = '******';
     $passwordHash = '1a2b3f4c';
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $customer->expects($this->any())->method('getId')->willReturn($customerId);
     $this->customerRepository->expects($this->once())->method('get')->with($email)->willReturn($customer);
     $this->accountManagementHelper->expects($this->once())->method('validatePasswordAndLockStatus')->with($customer, $currentPassword);
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'setPasswordHash'])->disableOriginalConstructor()->getMock();
     $customerSecure->expects($this->once())->method('setRpToken')->with(null);
     $customerSecure->expects($this->once())->method('setRpTokenCreatedAt')->with(null);
     $customerSecure->expects($this->once())->method('setPasswordHash')->with($passwordHash);
     $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
     $this->encryptor->expects($this->once())->method('getHash')->with($newPassword, true)->willReturn($passwordHash);
     $this->scopeConfig->expects($this->any())->method('getValue')->willReturnMap([[AccountManagement::XML_PATH_MINIMUM_PASSWORD_LENGTH, 'default', null, 7], [AccountManagement::XML_PATH_REQUIRED_CHARACTER_CLASSES_NUMBER, 'default', null, 1]]);
     $this->string->expects($this->any())->method('strlen')->with($newPassword)->willReturn(7);
     $this->customerRepository->expects($this->once())->method('save')->with($customer);
     $this->assertTrue($this->accountManagement->changePassword($email, $currentPassword, $newPassword));
 }
 /**
  * @param bool $result
  * @dataProvider validatePasswordAndLockStatusDataProvider
  */
 public function testValidatePasswordAndLockStatus($result)
 {
     $customerId = 7;
     $password = '******';
     $hash = '1b2af329dd0';
     $email = '*****@*****.**';
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $customerMock->expects($this->any())->method('getId')->willReturn($customerId);
     $this->customerSecure->expects($this->any())->method('getId')->willReturn($customerId);
     $this->customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
     $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $hash)->willReturn($result);
     if ($result) {
         $this->assertEquals($this->helper, $this->helper->validatePasswordAndLockStatus($customerMock, $password));
     } else {
         $customerMock->expects($this->once())->method('getEmail')->willReturn($email);
         $this->eventManagerMock->expects($this->once())->method('dispatch')->with('customer_password_invalid', ['username' => $email, 'password' => $password]);
         $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(false);
         $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure);
         $this->setExpectedException('\\Magento\\Framework\\Exception\\InvalidEmailOrPasswordException', __('The password doesn\'t match this account.'));
         $this->helper->validatePasswordAndLockStatus($customerMock, $password);
     }
 }
Esempio n. 16
0
 public function testHashPassword()
 {
     $this->_encryptor->expects($this->once())->method('getHash')->with('password', 'salt')->will($this->returnValue('hash'));
     $this->assertEquals('hash', $this->_model->hashPassword('password', 'salt'));
 }