Repository navigation
Expand file tree
/
Copy pathSslTestCase.php
More file actions
124 lines (110 loc) · 3.17 KB
/
Copy pathSslTestCase.php
File metadata and controls
124 lines (110 loc) · 3.17 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace WpOrg\Requests\Tests\Ssl;
use WpOrg\Requests\Tests\Fixtures\StringableObject;
use WpOrg\Requests\Tests\TestCase;
abstract class SslTestCase extends TestCase {
/**
* Test helper to mock a certificate.
*
* @param string $dnsname DNS name to match against.
* @param bool|string $with_san Optional. How to generate the fake certificate.
* - false: plain, CN only;
* - true: CN + subjectAltName, alt set to same as CN;
* - string: CN + subjectAltName, alt set to string value.
*
* @return array
*/
protected function fakeCertificate($dnsname, $with_san = true) {
$certificate = [
'subject' => [
'CN' => $dnsname,
],
];
if ($with_san !== false) {
// If SAN is set to true, default it to the dNSName.
if ($with_san === true) {
$with_san = 'DNS: ' . $dnsname;
}
$certificate['extensions'] = [
'subjectAltName' => $with_san,
];
}
return $certificate;
}
/**
* Data provider.
*
* @return array
*/
public static function dataMatch() {
return [
'top-level domain (stringable object)' => [
'host' => new StringableObject('example.com'),
'reference' => new StringableObject('example.com'),
],
'subdomain' => [
'host' => 'test.example.com',
'reference' => 'test.example.com',
],
'subdomain with wildcard reference' => [
'host' => 'test.example.com',
'reference' => '*.example.com',
],
];
}
/**
* Data provider.
*
* @return array
*/
public static function dataNoMatch() {
return [
// Check that we need at least 3 components.
'not a domain; wildcard reference' => [
'host' => 'com',
'reference' => '*',
],
'domain name; wildcard on TLD as reference' => [
'host' => 'example.com',
'reference' => '*.com',
],
// Check that double wildcards don't work.
'domain name; double wildcard in reference' => [
'host' => 'abc.def.example.com',
'reference' => '*.*.example.com',
],
// Check that we only match with the correct number of components.
'four-level domain; three-level reference' => [
'host' => 'abc.def.example.com',
'reference' => 'def.example.com',
],
'four-level domain; three-level wildcard reference' => [
'host' => 'abc.def.example.com',
'reference' => '*.example.com',
],
// Check that the wildcard only works as the full first component.
'four-level domain; four-level reference, but wildcard not stand-alone' => [
'host' => 'abc.def.example.com',
'reference' => 'a*.def.example.com',
],
// Check that wildcards are not allowed for IPs.
'IP address; wildcard in reference (start)' => [
'host' => '192.168.0.1',
'reference' => '*.168.0.1',
],
'IP address; wildcard in reference (end)' => [
'host' => '192.168.0.1',
'reference' => '192.168.0.*',
],
// IP vs named address.
'IP address vs named address' => [
'host' => '192.168.0.1',
'reference' => '*.example.com',
],
'Named address vs IP address' => [
'host' => 'example.com',
'reference' => '192.168.0.1',
],
];
}
}