public function testChangeEncryptionKeyThrowsException() { $key = 'key'; $this->writerMock->expects($this->once())->method('checkIfWritable')->willReturn(false); try { $this->model->changeEncryptionKey($key); } catch (\Exception $e) { return; } $this->fail('An excpected exception was not signaled.'); }
public function testExecuteRandom() { $newKey = 'RSASHA9000VERYSECURESUPERMANKEY'; $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1); $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey); $this->managerMock->expects($this->once())->method('addSuccessMessage'); $this->managerMock->expects($this->once())->method('addNoticeMessage'); $this->cacheMock->expects($this->once())->method('clean'); $this->responseMock->expects($this->once())->method('setRedirect'); $this->model->execute(); }
/** * Process saving new encryption key * * @return void */ public function executeInternal() { try { $key = null; if (0 == $this->getRequest()->getPost('generate_random')) { $key = $this->getRequest()->getPost('crypt_key'); if (empty($key)) { throw new \Exception(__('Please enter an encryption key.')); } $this->encryptor->validateKey($key); } $newKey = $this->change->changeEncryptionKey($key); $this->messageManager->addSuccessMessage(__('The encryption key has been changed.')); if (!$key) { $this->messageManager->addNoticeMessage(__('This is your new encryption key: <span style="font-family:monospace;">%1</span>. ' . 'Be sure to write it down and take good care of it!', $newKey)); } $this->cache->clean(); } catch (\Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); $this->_session->setFormData(['crypt_key' => $key]); } $this->_redirect('adminhtml/*/'); }