New Library
This commit is contained in:
parent
5c6f6c97b7
commit
c479658f0b
83 changed files with 5788 additions and 0 deletions
59
server/vendor/php-opencloud/common/tests/unit/Common/Auth/AuthHandlerTest.php
vendored
Normal file
59
server/vendor/php-opencloud/common/tests/unit/Common/Auth/AuthHandlerTest.php
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace OpenCloud\Test\Common\Auth;
|
||||
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use OpenCloud\Common\Auth\AuthHandler;
|
||||
use OpenCloud\Common\Auth\Token;
|
||||
use OpenCloud\Test\TestCase;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
class AuthHandlerTest extends TestCase
|
||||
{
|
||||
const TOKEN_ID = 'tokenId';
|
||||
|
||||
private $generator;
|
||||
private $handler;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->generator = function () {
|
||||
$token = $this->prophesize(FakeToken::class);
|
||||
$token->getId()->shouldBeCalled()->willReturn(self::TOKEN_ID);
|
||||
return $token->reveal();
|
||||
};
|
||||
|
||||
$this->handler = function (RequestInterface $r) {
|
||||
return $r;
|
||||
};
|
||||
|
||||
$this->handler = new AuthHandler($this->handler, $this->generator);
|
||||
}
|
||||
|
||||
public function test_it_should_bypass_auth_http_requests()
|
||||
{
|
||||
// Fake a Keystone request
|
||||
$request = new Request('POST', 'https://my-openstack.org:5000/v2.0/tokens');
|
||||
|
||||
$this->assertEquals($request, call_user_func_array($this->handler, [$request, []]));
|
||||
}
|
||||
|
||||
public function test_it_should_generate_a_new_token_if_the_current_token_is_either_expired_or_not_set()
|
||||
{
|
||||
$token = $this->prophesize(Token::class);
|
||||
|
||||
// force the mock token to indicate that its expired
|
||||
$token->getId()->willReturn('');
|
||||
$token->hasExpired()->willReturn(true);
|
||||
|
||||
$request = new Request('GET', '');
|
||||
|
||||
$handler = new AuthHandler($this->handler, $this->generator, $token->reveal());
|
||||
$handler($request, []);
|
||||
}
|
||||
}
|
||||
|
||||
class FakeToken implements Token {
|
||||
public function getId() {}
|
||||
public function hasExpired() {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue