jakubigla /
PSR7Auth
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace PSR7AuthTest\Middleware; |
||
| 4 | |||
| 5 | use PHPUnit_Framework_TestCase; |
||
| 6 | use Psr\Http\Message\ResponseInterface; |
||
| 7 | use Psr\Http\Message\ServerRequestInterface; |
||
| 8 | use PSR7Auth\AccessRule\AccessRuleInterface; |
||
| 9 | use PSR7Auth\Domain\Entity\UserInterface; |
||
| 10 | use PSR7Auth\Exception\IdentityNotFoundException; |
||
| 11 | use PSR7Auth\IdentityProvider\IdentityProviderInterface; |
||
| 12 | use PSR7Auth\Middleware\AuthenticationMiddleware; |
||
| 13 | use PSR7Auth\Verifier\VerifierInterface; |
||
| 14 | use stdClass; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Class AuthenticationMiddlewareTest |
||
| 18 | */ |
||
| 19 | class AuthenticationMiddlewareTest extends PHPUnit_Framework_TestCase |
||
| 20 | { |
||
| 21 | /** @var IdentityProviderInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 22 | private $identityProvider; |
||
| 23 | |||
| 24 | /** @var AccessRuleInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 25 | private $accessRule; |
||
| 26 | |||
| 27 | /** @var VerifierInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 28 | private $verifier; |
||
| 29 | |||
| 30 | /** @var ServerRequestInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 31 | private $request; |
||
| 32 | |||
| 33 | /** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 34 | private $response; |
||
| 35 | |||
| 36 | /** @var callable|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 37 | private $nextMiddleware; |
||
| 38 | |||
| 39 | /** @var AuthenticationMiddleware|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 40 | private $middleware; |
||
| 41 | |||
| 42 | public function setUp() |
||
| 43 | { |
||
| 44 | $this->identityProvider = self::getMock(IdentityProviderInterface::class, ['__invoke']); |
||
| 45 | $this->accessRule = self::getMock(AccessRuleInterface::class, ['__invoke']); |
||
| 46 | $this->verifier = self::getMock(VerifierInterface::class, ['__invoke']); |
||
| 47 | $this->request = self::getMock(ServerRequestInterface::class); |
||
| 48 | $this->response = self::getMock(ResponseInterface::class); |
||
| 49 | $this->nextMiddleware = self::getMock(stdClass::class, ['__invoke']); |
||
| 50 | $this->middleware = new AuthenticationMiddleware( |
||
|
0 ignored issues
–
show
|
|||
| 51 | $this->identityProvider, |
||
| 52 | $this->accessRule, |
||
| 53 | $this->verifier |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function testAccessRulePipesToTheNextMiddlewareWhenNotSatisfied() |
||
| 58 | { |
||
| 59 | $nextReturnValue = $this->getMock(ResponseInterface::class); |
||
| 60 | |||
| 61 | $this |
||
|
0 ignored issues
–
show
|
|||
| 62 | ->nextMiddleware |
||
| 63 | ->expects(self::once()) |
||
| 64 | ->method('__invoke') |
||
| 65 | ->with($this->request, $this->response) |
||
| 66 | ->willReturn($nextReturnValue); |
||
| 67 | |||
| 68 | $this |
||
| 69 | ->accessRule |
||
| 70 | ->expects(self::once()) |
||
| 71 | ->method('__invoke') |
||
| 72 | ->willReturn(false); |
||
| 73 | |||
| 74 | $result = $this->middleware->__invoke($this->request, $this->response, $this->nextMiddleware); |
||
| 75 | |||
| 76 | self::assertSame($nextReturnValue, $result); |
||
| 77 | } |
||
| 78 | |||
| 79 | public function testIdentityNotFoundFromIdentityProvider() |
||
| 80 | { |
||
| 81 | $nextReturnValue = $this->getMock(ResponseInterface::class); |
||
| 82 | |||
| 83 | $this |
||
|
0 ignored issues
–
show
|
|||
| 84 | ->nextMiddleware |
||
| 85 | ->expects(self::once()) |
||
| 86 | ->method('__invoke') |
||
| 87 | ->with($this->request, $this->response) |
||
| 88 | ->willReturn($nextReturnValue); |
||
| 89 | |||
| 90 | $this |
||
| 91 | ->accessRule |
||
| 92 | ->expects(self::once()) |
||
| 93 | ->method('__invoke') |
||
| 94 | ->with($this->request) |
||
| 95 | ->willReturn(true); |
||
| 96 | |||
| 97 | $this |
||
| 98 | ->identityProvider |
||
| 99 | ->expects($this->once()) |
||
| 100 | ->method('__invoke') |
||
| 101 | ->willThrowException(new IdentityNotFoundException()); |
||
| 102 | |||
| 103 | $this |
||
|
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Psr\Http\Message\ServerRequestInterface.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 104 | ->request |
||
| 105 | ->expects(self::once()) |
||
| 106 | ->method('withAttribute') |
||
| 107 | ->willReturn($this->request); |
||
| 108 | |||
| 109 | $result = $this->middleware->__invoke($this->request, $this->response, $this->nextMiddleware); |
||
| 110 | self::assertSame($nextReturnValue, $result); |
||
| 111 | } |
||
| 112 | |||
| 113 | public function testIdentityAuthenticated() |
||
| 114 | { |
||
| 115 | $nextReturnValue = $this->getMock(ResponseInterface::class); |
||
| 116 | |||
| 117 | $this |
||
|
0 ignored issues
–
show
|
|||
| 118 | ->nextMiddleware |
||
| 119 | ->expects(self::once()) |
||
| 120 | ->method('__invoke') |
||
| 121 | ->with($this->request, $this->response) |
||
| 122 | ->willReturn($nextReturnValue); |
||
| 123 | |||
| 124 | $this |
||
| 125 | ->accessRule |
||
| 126 | ->expects(self::once()) |
||
| 127 | ->method('__invoke') |
||
| 128 | ->with($this->request) |
||
| 129 | ->willReturn(true); |
||
| 130 | |||
| 131 | $this |
||
| 132 | ->identityProvider |
||
| 133 | ->expects(self::once()) |
||
| 134 | ->method('__invoke') |
||
| 135 | ->with($this->request) |
||
| 136 | ->willReturn($this->getMock(UserInterface::class)); |
||
| 137 | |||
| 138 | $this |
||
|
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Psr\Http\Message\ServerRequestInterface.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 139 | ->request |
||
| 140 | ->expects(self::once()) |
||
| 141 | ->method('withAttribute') |
||
| 142 | ->willReturn($this->request); |
||
| 143 | |||
| 144 | $result = $this->middleware->__invoke($this->request, $this->response, $this->nextMiddleware); |
||
| 145 | self::assertSame($nextReturnValue, $result); |
||
| 146 | } |
||
| 147 | } |
||
| 148 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..