Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 56e4ff8

Browse files
committed
🚿
1 parent 74736c5 commit 56e4ff8

File tree

5 files changed

+62
-216
lines changed

5 files changed

+62
-216
lines changed

resources/db.mysql.sql

Lines changed: 0 additions & 53 deletions
This file was deleted.

resources/providers.json

Lines changed: 0 additions & 114 deletions
This file was deleted.

tests/Providers/GenericOAuth2Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @property \chillerlan\OAuthExamples\OAuth2Testprovider $provider
1919
*/
2020
class GenericOAuth2Test extends OAuth2Test{
21-
use SupportsOAuth2ClientCredentials, SupportsOAuth2TokenRefresh;
21+
use SupportsOAuth2ClientCredentials, SupportsOAuth2TokenRefresh, SupportsCSRFToken;
2222

2323
protected $FQCN = OAuth2Testprovider::class;
2424
}

tests/Providers/OAuth2Test.php

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
namespace chillerlan\OAuthTest\Providers;
1414

15-
use chillerlan\OAuth\{
16-
OAuthOptions, Providers\ClientCredentials, Providers\CSRFToken, Providers\OAuth2Interface, Providers\TokenRefresh, Token
17-
};
1815
use chillerlan\HTTP\{
19-
HTTPClientInterface, HTTPClientAbstract, HTTPResponse, HTTPResponseInterface
16+
HTTPClientAbstract, HTTPClientInterface, HTTPResponse, HTTPResponseInterface
17+
};
18+
use chillerlan\OAuth\{
19+
OAuthOptions, Providers\ClientCredentials, Providers\CSRFToken, Providers\TokenRefresh, Token
2020
};
2121

2222
/**
@@ -59,7 +59,10 @@ protected function setUp(){
5959
$this->setProperty($this->provider, 'clientCredentialsTokenURL', 'https://localhost/oauth2/client_credentials');
6060
}
6161

62-
$this->storage->storeCSRFState($this->provider->serviceName, 'test_state');
62+
if($this->provider instanceof CSRFToken){
63+
$this->storage->storeCSRFState($this->provider->serviceName, 'test_state');
64+
}
65+
6366
}
6467

6568
protected function initHttp():HTTPClientInterface{
@@ -135,49 +138,6 @@ public function testParseTokenResponseNoToken(){
135138
->invokeArgs($this->provider, [new HTTPResponse(['body' => json_encode(['foo' => 'bar'])])]);
136139
}
137140

138-
public function testCheckCSRFState(){
139-
140-
if(!$this->provider instanceof CSRFToken){
141-
$this->markTestSkipped('N/A');
142-
}
143-
144-
$provider = $this
145-
->getMethod('checkState')
146-
->invokeArgs($this->provider, ['test_state']);
147-
148-
$this->assertInstanceOf(OAuth2Interface::class, $provider);
149-
}
150-
151-
/**
152-
* @expectedException \chillerlan\OAuth\Providers\ProviderException
153-
* @expectedExceptionMessage invalid state
154-
*/
155-
public function testCheckStateInvalid(){
156-
157-
if(!$this->provider instanceof CSRFToken){
158-
$this->markTestSkipped('N/A');
159-
}
160-
161-
$this
162-
->getMethod('checkState')
163-
->invoke($this->provider);
164-
}
165-
166-
/**
167-
* @expectedException \chillerlan\OAuth\Providers\ProviderException
168-
* @expectedExceptionMessage invalid CSRF state
169-
*/
170-
public function testCheckStateInvalidCSRFState(){
171-
172-
if(!$this->provider instanceof CSRFToken){
173-
$this->markTestSkipped('N/A');
174-
}
175-
176-
$this
177-
->getMethod('checkState')
178-
->invokeArgs($this->provider, ['invalid_test_state']);
179-
}
180-
181141
public function testRequest(){
182142
$this->storeToken(new Token(['accessToken' => 'test_access_token_secret', 'expires' => 1]));
183143

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Trait SupportsCSRFToken
4+
*
5+
* @filesource SupportsCSRFToken.php
6+
* @created 20.04.2018
7+
* @package chillerlan\OAuthTest\Providers
8+
* @author smiley <smiley@chillerlan.net>
9+
* @copyright 2018 smiley
10+
* @license MIT
11+
*/
12+
13+
namespace chillerlan\OAuthTest\Providers;
14+
15+
use chillerlan\OAuth\Providers\OAuth2Interface;
16+
17+
/**
18+
*/
19+
trait SupportsCSRFToken{
20+
21+
public function testCheckCSRFState(){
22+
23+
$provider = $this
24+
->getMethod('checkState')
25+
->invokeArgs($this->provider, ['test_state']);
26+
27+
$this->assertInstanceOf(OAuth2Interface::class, $provider);
28+
}
29+
30+
/**
31+
* @expectedException \chillerlan\OAuth\Providers\ProviderException
32+
* @expectedExceptionMessage invalid state
33+
*/
34+
public function testCheckStateInvalid(){
35+
36+
$this
37+
->getMethod('checkState')
38+
->invoke($this->provider);
39+
}
40+
41+
/**
42+
* @expectedException \chillerlan\OAuth\Providers\ProviderException
43+
* @expectedExceptionMessage invalid CSRF state
44+
*/
45+
public function testCheckStateInvalidCSRFState(){
46+
47+
$this
48+
->getMethod('checkState')
49+
->invokeArgs($this->provider, ['invalid_test_state']);
50+
}
51+
52+
53+
}

0 commit comments

Comments
 (0)