1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\Compat; |
6
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
8
|
|
|
use Psr\Log\NullLogger; |
9
|
|
|
|
10
|
|
|
use function chmod; |
11
|
|
|
use function file_put_contents; |
12
|
|
|
use function sys_get_temp_dir; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class \SimpleSAML\SAML2\Compat\MockContainer |
16
|
|
|
*/ |
17
|
|
|
class MockContainer extends AbstractContainer |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private string $id = '123'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private array $debugMessages = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private string $redirectUrl; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private array $redirectData = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string|null |
41
|
|
|
*/ |
42
|
|
|
private ?string $postRedirectUrl = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
private array $postRedirectData; |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get a PSR-3 compatible logger. |
52
|
|
|
* @return \Psr\Log\LoggerInterface |
53
|
|
|
*/ |
54
|
|
|
public function getLogger(): LoggerInterface |
55
|
|
|
{ |
56
|
|
|
return new NullLogger(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Generate a random identifier for identifying SAML2 documents. |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function generateId(): string |
65
|
|
|
{ |
66
|
|
|
return $this->id; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Log an incoming message to the debug log. |
72
|
|
|
* |
73
|
|
|
* Type can be either: |
74
|
|
|
* - **in** XML received from third party |
75
|
|
|
* - **out** XML that will be sent to third party |
76
|
|
|
* - **encrypt** XML that is about to be encrypted |
77
|
|
|
* - **decrypt** XML that was just decrypted |
78
|
|
|
* |
79
|
|
|
* @param \DOMElement|string $message |
80
|
|
|
* @param string $type |
81
|
|
|
*/ |
82
|
|
|
public function debugMessage($message, string $type): void |
83
|
|
|
{ |
84
|
|
|
$this->debugMessages[$type] = $message; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Trigger the user to perform a GET to the given URL with the given data. |
90
|
|
|
* |
91
|
|
|
* @param string $url |
92
|
|
|
* @param array $data |
93
|
|
|
*/ |
94
|
|
|
public function redirect(string $url, array $data = []): void |
95
|
|
|
{ |
96
|
|
|
$this->redirectUrl = $url; |
97
|
|
|
$this->redirectData = $data; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Trigger the user to perform a POST to the given URL with the given data. |
103
|
|
|
* |
104
|
|
|
* @param string|null $url |
105
|
|
|
* @param array $data |
106
|
|
|
*/ |
107
|
|
|
public function postRedirect(string $url = null, array $data = []): void |
108
|
|
|
{ |
109
|
|
|
$this->postRedirectUrl = $url; |
110
|
|
|
$this->postRedirectData = $data; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function getTempDir(): string |
118
|
|
|
{ |
119
|
|
|
return sys_get_temp_dir(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $filename |
125
|
|
|
* @param string $data |
126
|
|
|
* @param int|null $mode |
127
|
|
|
*/ |
128
|
|
|
public function writeFile(string $filename, string $data, int $mode = null): void |
129
|
|
|
{ |
130
|
|
|
if ($mode === null) { |
131
|
|
|
$mode = 0600; |
132
|
|
|
} |
133
|
|
|
file_put_contents($filename, $data); |
134
|
|
|
chmod($filename, $mode); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @inheritDoc |
140
|
|
|
*/ |
141
|
|
|
public function setBlacklistedAlgorithms(?array $algos): void { |
142
|
|
|
$this->blacklistedEncryptionAlgorithms = []; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|