Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[develop] PRG Plugin fixes: Incorrect use of session hops expiration #3016

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/Zend/Mvc/Controller/Plugin/FilePostRedirectGet.php
Expand Up @@ -46,6 +46,7 @@ public function __invoke($form, $redirect = null, $redirectToUrl = false)
if (!$form->isValid()) { if (!$form->isValid()) {
$container->errors = $form->getMessages(); $container->errors = $form->getMessages();
} }
$container->setExpirationHops(1, array('post', 'errors'));


return $this->redirect($redirect, $redirectToUrl); return $this->redirect($redirect, $redirectToUrl);
} else { } else {
Expand All @@ -67,11 +68,10 @@ public function __invoke($form, $redirect = null, $redirectToUrl = false)
} }
} }


protected function getSessionContainer() public function getSessionContainer()
{ {
if (!isset($this->sessionContainer)) { if (!isset($this->sessionContainer)) {
$this->sessionContainer = new Container('file_prg_post1'); $this->sessionContainer = new Container('file_prg_post1');
$this->sessionContainer->setExpirationHops(1, array('post', 'errors'));
} }
return $this->sessionContainer; return $this->sessionContainer;
} }
Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
Expand Up @@ -36,6 +36,7 @@ public function __invoke($redirect = null, $redirectToUrl = false)


if ($request->isPost()) { if ($request->isPost()) {
$container->post = $request->getPost()->toArray(); $container->post = $request->getPost()->toArray();
$container->setExpirationHops(1, 'post');
return $this->redirect($redirect, $redirectToUrl); return $this->redirect($redirect, $redirectToUrl);
} else { } else {
if ($container->post !== null) { if ($container->post !== null) {
Expand All @@ -48,11 +49,10 @@ public function __invoke($redirect = null, $redirectToUrl = false)
} }
} }


protected function getSessionContainer() public function getSessionContainer()
{ {
if (!isset($this->sessionContainer)) { if (!isset($this->sessionContainer)) {
$this->sessionContainer = new Container('prg_post1'); $this->sessionContainer = new Container('prg_post1');
$this->sessionContainer->setExpirationHops(1, 'post');
} }
return $this->sessionContainer; return $this->sessionContainer;
} }
Expand Down
Expand Up @@ -194,6 +194,13 @@ public function testReturnsPostOnRedirectGet()


$this->assertEquals($params, $prgResult); $this->assertEquals($params, $prgResult);
$this->assertEquals($params['postval1'], $this->form->get('postval1')->getValue()); $this->assertEquals($params['postval1'], $this->form->get('postval1')->getValue());

// Do GET again to make sure data is empty
$this->request = new Request();
$this->controller->dispatch($this->request, $this->response);
$prgResult = $this->controller->fileprg($this->form, '/test/getPage', true);

$this->assertFalse($prgResult);
} }


public function testAppliesFormErrorsOnPostRedirectGet() public function testAppliesFormErrorsOnPostRedirectGet()
Expand Down
31 changes: 31 additions & 0 deletions tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
Expand Up @@ -108,6 +108,37 @@ public function testRedirectsToRouteOnPost()
$this->assertEquals(303, $prgResultRoute->getStatusCode()); $this->assertEquals(303, $prgResultRoute->getStatusCode());
} }


public function testReturnsPostOnRedirectGet()
{
$params = array(
'postval1' => 'value1'
);
$this->request->setMethod('POST');
$this->request->setPost(new Parameters($params));

$result = $this->controller->dispatch($this->request, $this->response);
$prgResultRoute = $this->controller->prg('home');

$this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
$this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
$this->assertEquals('/', $prgResultRoute->getHeaders()->get('Location')->getUri());
$this->assertEquals(303, $prgResultRoute->getStatusCode());

// Do GET
$this->request = new Request();
$this->controller->dispatch($this->request, $this->response);
$prgResult = $this->controller->prg('home');

$this->assertEquals($params, $prgResult);

// Do GET again to make sure data is empty
$this->request = new Request();
$this->controller->dispatch($this->request, $this->response);
$prgResult = $this->controller->prg('home');

$this->assertFalse($prgResult);
}

/** /**
* @expectedException Zend\Mvc\Exception\RuntimeException * @expectedException Zend\Mvc\Exception\RuntimeException
*/ */
Expand Down