Skip to content

Commit 7a7376f

Browse files
committed
add test for token strategy
make doctrine/inflector constraint less strict
1 parent e406bde commit 7a7376f

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"cache/cache": "^0.4.0",
1919
"guzzlehttp/psr7": "^1.4",
2020
"guzzlehttp/promises": "^1.3",
21-
"doctrine/inflector": "~1.1.0",
21+
"doctrine/inflector": "~1.1",
2222
"weew/helpers-array": "^1.3"
2323
},
2424
"require-dev": {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
-
3+
request:
4+
method: GET
5+
url: 'http://127.0.0.1:8200/v1/auth/token/lookup-self'
6+
headers:
7+
Host: '127.0.0.1:8200'
8+
Accept-Encoding: null
9+
User-Agent: VaultPHP/1.0.0
10+
Content-Type: application/json
11+
X-Vault-Token: db02de05-fa39-4855-059b-67221c5c2f63
12+
Accept: null
13+
response:
14+
status:
15+
http_version: '1.1'
16+
code: '200'
17+
message: OK
18+
headers:
19+
Cache-Control: no-store
20+
Content-Type: application/json
21+
Date: 'Tue, 01 Aug 2017 06:54:33 GMT'
22+
Content-Length: '504'
23+
body: "{\"request_id\":\"ab3f3dc9-3633-0c18-44e2-f3f58cb56d0a\",\"lease_id\":\"\",\"renewable\":false,\"lease_duration\":0,\"data\":{\"accessor\":\"033ccada-d332-9415-0acc-0ec51e81dbd1\",\"creation_time\":1501570473,\"creation_ttl\":2764800,\"display_name\":\"userpass-test\",\"explicit_max_ttl\":0,\"id\":\"db02de05-fa39-4855-059b-67221c5c2f63\",\"meta\":{\"username\":\"test\"},\"num_uses\":0,\"orphan\":true,\"path\":\"auth/userpass/login/test\",\"policies\":[\"default\",\"test\"],\"renewable\":true,\"ttl\":2764800},\"wrap_info\":null,\"warnings\":null,\"auth\":null}\n"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use Psr\Log\NullLogger;
4+
use Vault\AuthenticationStrategies\TokenAuthenticationStrategy;
5+
use Vault\Client;
6+
use VaultTransports\Guzzle6Transport;
7+
8+
class TokenAuthenticationStrategyTest extends \Codeception\Test\Unit
9+
{
10+
/**
11+
* @var \UnitTester
12+
*/
13+
protected $tester;
14+
15+
public function testCanAuthenticate()
16+
{
17+
$client = (new Client(new Guzzle6Transport()))
18+
->setAuthenticationStrategy(new TokenAuthenticationStrategy('db02de05-fa39-4855-059b-67221c5c2f63'))
19+
->setLogger(new NullLogger());
20+
21+
$this->assertEquals($client->getAuthenticationStrategy()->getClient(), $client);
22+
$this->assertTrue($client->authenticate());
23+
$this->assertNotEmpty($client->getToken());
24+
25+
return $client;
26+
}
27+
28+
protected function setUp()
29+
{
30+
\VCR\VCR::turnOn();
31+
32+
\VCR\VCR::insertCassette('authentication-strategies/token');
33+
34+
return parent::setUp();
35+
}
36+
37+
protected function tearDown()
38+
{
39+
// To stop recording requests, eject the cassette
40+
\VCR\VCR::eject();
41+
42+
// Turn off VCR to stop intercepting requests
43+
\VCR\VCR::turnOff();
44+
45+
parent::tearDown();
46+
}
47+
48+
protected function _before()
49+
{
50+
}
51+
52+
protected function _after()
53+
{
54+
}
55+
}

0 commit comments

Comments
 (0)