1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\AuthorizationEndpoint\Tests\UserAccount; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\Authorization; |
17
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\CreateRedirectionException; |
18
|
|
|
use OAuth2Framework\Component\AuthorizationEndpoint\UserAccount\PromptNoneParameterAccountChecker; |
19
|
|
|
use OAuth2Framework\Component\Core\Client\Client; |
20
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccount; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @group UserAccountChecker |
25
|
|
|
* @group PromptNoneParameterAccountChecker |
26
|
|
|
*/ |
27
|
|
|
class PromptNoneParameterAccountCheckerTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
*/ |
32
|
|
|
public function theUserAccountIsNotAvailableAndThePromptNoneIsSetThenAnExceptionIsThrown() |
33
|
|
|
{ |
34
|
|
|
$client = $this->prophesize(Client::class); |
35
|
|
|
|
36
|
|
|
$authorization = $this->prophesize(Authorization::class); |
37
|
|
|
$authorization->hasPrompt('none')->willReturn(true); |
38
|
|
|
$authorization->getUserAccount()->willReturn(null); |
39
|
|
|
$authorization->getClient()->willReturn($client->reveal()); |
40
|
|
|
$checker = new PromptNoneParameterAccountChecker(); |
41
|
|
|
|
42
|
|
|
try { |
43
|
|
|
$checker->check($authorization->reveal()); |
44
|
|
|
$this->fail('The expected exception has not been thrown.'); |
45
|
|
|
} catch (CreateRedirectionException $e) { |
46
|
|
|
self::assertTrue(true); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function theUserAccountIsAvailableAndThePromptNoneIsSetThenTheCheckSucceeded() |
54
|
|
|
{ |
55
|
|
|
$userAccount = $this->prophesize(UserAccount::class); |
56
|
|
|
|
57
|
|
|
$client = $this->prophesize(Client::class); |
58
|
|
|
|
59
|
|
|
$authorization = $this->prophesize(Authorization::class); |
60
|
|
|
$authorization->hasPrompt('none')->willReturn(true); |
61
|
|
|
$authorization->getUserAccount()->willReturn($userAccount->reveal()); |
62
|
|
|
$authorization->getClient()->willReturn($client->reveal()); |
63
|
|
|
$checker = new PromptNoneParameterAccountChecker(); |
64
|
|
|
|
65
|
|
|
$checker->check($authorization->reveal()); |
66
|
|
|
self::assertTrue(true); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @test |
71
|
|
|
*/ |
72
|
|
|
public function theUserAccountIsAvailableAndThePromptNoneIsNotSetThenTheCheckSucceeded() |
73
|
|
|
{ |
74
|
|
|
$userAccount = $this->prophesize(UserAccount::class); |
75
|
|
|
|
76
|
|
|
$client = $this->prophesize(Client::class); |
77
|
|
|
|
78
|
|
|
$authorization = $this->prophesize(Authorization::class); |
79
|
|
|
$authorization->hasPrompt('none')->willReturn(false); |
80
|
|
|
$authorization->getUserAccount()->willReturn($userAccount->reveal()); |
81
|
|
|
$authorization->getClient()->willReturn($client->reveal()); |
82
|
|
|
$checker = new PromptNoneParameterAccountChecker(); |
83
|
|
|
|
84
|
|
|
$checker->check($authorization->reveal()); |
85
|
|
|
self::assertTrue(true); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|