|
@@ 107-122 (lines=16) @@
|
| 104 |
|
/** |
| 105 |
|
* Tests that access is denied to a service not listed in the whitelist. |
| 106 |
|
*/ |
| 107 |
|
public function testAccessDeniedToServiceMissingFromWhitelist() |
| 108 |
|
{ |
| 109 |
|
// make it appear that we are generating a cross origin request |
| 110 |
|
$_SERVER['HTTP_ORIGIN'] = 'www.example.com'; |
| 111 |
|
// some dummy variables that are needed by the plugin |
| 112 |
|
$handler = new ControllerHandler(array()); |
| 113 |
|
$this->assertTrue($handler->isAppropriate('/testDummy', array(), array(), 'GET')); |
| 114 |
|
$plugin = new CrossOriginRequestPlugin(array( |
| 115 |
|
'whitelist' => array() |
| 116 |
|
)); |
| 117 |
|
try { |
| 118 |
|
$plugin->afterHandlerSelected($handler); |
| 119 |
|
} catch (AccessDeniedException $e) { |
| 120 |
|
$this->assertEquals(403, $e->getAssociatedStatusCode()); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
/** |
| 125 |
|
* Tests that access is denied to an action not listed in the whitelist of |
|
@@ 128-145 (lines=18) @@
|
| 125 |
|
* Tests that access is denied to an action not listed in the whitelist of |
| 126 |
|
* the controller. |
| 127 |
|
*/ |
| 128 |
|
public function testAccessDeniedToActionMissingFromWhitelist() |
| 129 |
|
{ |
| 130 |
|
// make it appear that we are generating a cross origin request |
| 131 |
|
$_SERVER['HTTP_ORIGIN'] = 'www.example.com'; |
| 132 |
|
// some dummy variables that are needed by the plugin |
| 133 |
|
$handler = new ControllerHandler(array()); |
| 134 |
|
$this->assertTrue($handler->isAppropriate('/testDummy', array(), array(), 'GET')); |
| 135 |
|
$plugin = new CrossOriginRequestPlugin(array( |
| 136 |
|
'whitelist' => array( |
| 137 |
|
'TestdummyController' => array() |
| 138 |
|
) |
| 139 |
|
)); |
| 140 |
|
try { |
| 141 |
|
$plugin->afterHandlerSelected($handler); |
| 142 |
|
} catch (AccessDeniedException $e) { |
| 143 |
|
$this->assertEquals(403, $e->getAssociatedStatusCode()); |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
/** |
| 148 |
|
* Tests that the whitelist can be the string 'all' instead of an array |
|
@@ 151-167 (lines=17) @@
|
| 148 |
|
* Tests that the whitelist can be the string 'all' instead of an array |
| 149 |
|
* allowing access to any service. |
| 150 |
|
*/ |
| 151 |
|
public function testWhitelistingAllActions() |
| 152 |
|
{ |
| 153 |
|
// make it appear that we are generating a cross origin request |
| 154 |
|
$_SERVER['HTTP_ORIGIN'] = 'www.example.com'; |
| 155 |
|
// some dummy variables that are needed by the plugin |
| 156 |
|
$handler = new ControllerHandler(array()); |
| 157 |
|
$this->assertTrue($handler->isAppropriate('/testDummy', array(), array(), 'GET')); |
| 158 |
|
$plugin = new CrossOriginRequestPlugin(array( |
| 159 |
|
'whitelist' => 'all' |
| 160 |
|
)); |
| 161 |
|
try { |
| 162 |
|
$plugin->afterHandlerSelected($handler); |
| 163 |
|
$this->assertTrue(true); |
| 164 |
|
} catch (AccessDeniedException $e) { |
| 165 |
|
$this->fail('Cross origin plugin should not have denied access.'); |
| 166 |
|
} |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
/** |
| 170 |
|
* Test that the plugin doesn't break with the PatternMatchHandler. |