-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSigningTestCase.php
More file actions
104 lines (80 loc) · 3.06 KB
/
SigningTestCase.php
File metadata and controls
104 lines (80 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
declare(strict_types=1);
namespace SimpleSAML\TestUtils;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use SimpleSAML\Configuration;
/**
* A test case that provides a certificate directory with public and private
* keys.
*
* @package SimpleSAMLphp
*/
class SigningTestCase extends TestCase
{
protected Configuration $config;
protected string $root_directory;
protected string $cert_directory = 'certificates/rsa-pem';
protected string $ca_private_key_file = 'simplesamlphp.org-ca_nopasswd.key';
protected string $ca_certificate_file = 'simplesamlphp.org-ca.crt';
protected string $good_private_key_file = 'signed.simplesamlphp.org_nopasswd.key';
protected string $good_certificate_file = 'signed.simplesamlphp.org.crt';
// openssl genrsa -out example.org-ca.key 1024
protected string $ca_private_key;
// openssl req -key example.org-ca.key -new -x509 -days 36500 -out example.org-ca.crt
protected string $ca_certificate;
// openssl genrsa -out signed.example.org.key 1024
protected string $good_private_key;
// openssl req -key signed.example.org.key -new -out signed.example.org.crt
protected string $good_certificate;
/**
* Constructor
*/
public function __construct()
{
$this->root_directory = dirname(dirname(__FILE__));
$base = $this->root_directory . DIRECTORY_SEPARATOR . $this->cert_directory;
$this->ca_private_key = file_get_contents($base . DIRECTORY_SEPARATOR . $this->ca_private_key_file);
$this->ca_certificate = file_get_contents($base . DIRECTORY_SEPARATOR . $this->ca_certificate_file);
$this->good_private_key = file_get_contents($base . DIRECTORY_SEPARATOR . $this->good_private_key_file);
$this->good_certificate = file_get_contents($base . DIRECTORY_SEPARATOR . $this->good_certificate_file);
}
/**
*/
public function getCertDirContent(): array
{
return [
$this->ca_private_key_file => $this->ca_private_key,
$this->ca_certificate_file => $this->ca_certificate,
$this->good_private_key_file => $this->good_private_key,
$this->good_certificate_file => $this->good_certificate,
];
}
/**
*/
public function setUp(): void
{
$this->config = Configuration::loadFromArray([
'certdir' => $this->cert_directory,
], '[ARRAY]', 'simplesaml');
}
/**
*/
public function tearDown(): void
{
$this->clearInstance($this->config, Configuration::class, []);
}
/**
* @param \SimpleSAML\Configuration $service
* @param class-string $className
* @param mixed|null $value
*/
protected function clearInstance(Configuration $service, string $className, $value = null): void
{
$reflectedClass = new ReflectionClass($className);
$reflectedInstance = $reflectedClass->getProperty('instance');
$reflectedInstance->setAccessible(true);
$reflectedInstance->setValue($service, $value);
$reflectedInstance->setAccessible(false);
}
}