Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1007 from tractorcow/pulls/3.1-security-errorpage

API Error page support for Security controller errors
  • Loading branch information...
commit 435a5ee8430dd5fbdaf5831841f29876b42d52fd 2 parents 1f4d9e4 + f9cb880
@hafriedlander hafriedlander authored
View
5 _config/config.yml
@@ -1,3 +1,6 @@
LeftAndMain:
extensions:
- - LeftAndMainPageIconsExtension
+ - LeftAndMainPageIconsExtension
+Security:
+ extensions:
+ - ErrorPageControllerExtension
View
17 code/controllers/ErrorPageControllerExtension.php
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * Enhances error handling for a controller with ErrorPage generated output
+ *
+ * @package cms
+ * @subpackage controller
+ */
+class ErrorPageControllerExtension extends Extension {
+
+ public function onBeforeHTTPError($statusCode, $request) {
+ $response = ErrorPage::response_for($statusCode);
+ if($response) {
+ throw new SS_HTTPResponse_Exception($response, $statusCode);
+ }
+ }
+}
View
14 tests/model/ErrorPageTest.php
@@ -70,4 +70,16 @@ public function testBehaviourOf403() {
$this->assertEquals($response->getStatusCode(), '403');
$this->assertNotNull($response->getBody(), 'We have body text from the error page');
}
-}
+
+ public function testSecurityError() {
+ // Generate 404 page
+ $page = $this->objFromFixture('ErrorPage', '404');
+ $page->publish('Stage', 'Live');
+
+ // Test invalid action
+ $response = $this->get('Security/nosuchaction');
+ $this->assertEquals($response->getStatusCode(), '404');
+ $this->assertNotNull($response->getBody());
+ $this->assertContains('text/html', $response->getHeader('Content-Type'));
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.