Skip to content
This repository was archived by the owner on Apr 5, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/php/scriptlet/AuthenticationFilter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function __construct(RequestAuthenticator $auth) {
public function filter($request, $response, $invocation) {
try {
$r= $this->auth->authenticate($request, $response, null);
return false === $r ? $r : $invocation->proceed($request, $response);
} catch (ScriptletException $e) {
throw $e;
} catch (Throwable $e) {
throw new ScriptletException('Authentication failed: '.$e->getMessage(), HttpConstants::STATUS_FORBIDDEN, $e);
}
return false === $r ? $r : $invocation->proceed($request, $response);
}
}
33 changes: 33 additions & 0 deletions src/test/php/scriptlet/unittest/AuthenticationFilterTest.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace scriptlet\unittest;

use lang\IllegalAccessException;
use lang\IllegalArgumentException;
use scriptlet\AuthenticationFilter;
use scriptlet\Invocation;
use unittest\TestCase;

/**
* TestCase
*
* @see xp://scriptlet.AuthenticationFilter
*/
class AuthenticationFilterTest extends TestCase {

/**
* Regression test for fixed error handling in pull request #22
* https://github.com/xp-framework/scriptlet/pull/22
*/
#[@test, @expect(IllegalArgumentException::class)]
public function fix_global_error_handling_regression() {
$mockAuthenticator= newinstance('scriptlet.RequestAuthenticator', [], [
'authenticate' => function($request, $response, $context) {
return true;
}
]);
$mockInvocation= new Invocation(function() {
throw new IllegalArgumentException('Test');
}, [new AuthenticationFilter($mockAuthenticator)]);
$mockInvocation->proceed(null, null);
}

}