|
1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
|
2
|
|
|
/** |
|
3
|
|
|
* Connection Manager functionality testing. |
|
4
|
|
|
* |
|
5
|
|
|
* @package automattic/jetpack-connection |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Connection; |
|
9
|
|
|
|
|
10
|
|
|
use Brain\Monkey\Functions; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Text XMLRPC Connector |
|
15
|
|
|
*/ |
|
16
|
|
|
class XMLRPC_Connector_Test extends TestCase { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Tests is_request_signed_by_jetpack_debugger |
|
20
|
|
|
* |
|
21
|
|
|
* @param array $get_params The value of $_GET. |
|
22
|
|
|
* @param mixed $openss_verify_output What openssl_verify will output. |
|
23
|
|
|
* @param bool $expected The expected return of is_request_signed_by_jetpack_debugger. |
|
24
|
|
|
* |
|
25
|
|
|
* @dataProvider is_request_signed_by_jetpack_debugger_data |
|
26
|
|
|
* @covers Automattic\Jetpack\Connection\REST_Connector::is_request_signed_by_jetpack_debugger |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function test_is_request_signed_by_jetpack_debugger( $get_params, $openss_verify_output, $expected ) { |
|
30
|
|
|
|
|
31
|
|
|
Functions\when( 'openssl_verify' )->justReturn( $openss_verify_output ); |
|
32
|
|
|
|
|
33
|
|
|
$old_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
34
|
|
|
$_GET = $get_params; |
|
35
|
|
|
$response = REST_Connector::is_request_signed_by_jetpack_debugger(); |
|
36
|
|
|
$_GET = $old_get; |
|
37
|
|
|
|
|
38
|
|
|
$this->assertSame( $expected, $response ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Data provider for test_is_request_signed_by_jetpack_debugger |
|
43
|
|
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function is_request_signed_by_jetpack_debugger_data() { |
|
47
|
|
|
return array( |
|
48
|
|
|
'empty get' => array( |
|
49
|
|
|
array(), |
|
50
|
|
|
1, |
|
51
|
|
|
false, |
|
52
|
|
|
), |
|
53
|
|
|
'valid get' => array( |
|
54
|
|
|
array( |
|
55
|
|
|
'signature' => 'asd', |
|
56
|
|
|
'timestamp' => time(), |
|
57
|
|
|
'url' => 'https://example.com', |
|
58
|
|
|
), |
|
59
|
|
|
1, |
|
60
|
|
|
true, |
|
61
|
|
|
), |
|
62
|
|
|
'valid get, invalid signature' => array( |
|
63
|
|
|
array( |
|
64
|
|
|
'signature' => 'asd', |
|
65
|
|
|
'timestamp' => time(), |
|
66
|
|
|
'url' => 'https://example.com', |
|
67
|
|
|
), |
|
68
|
|
|
0, |
|
69
|
|
|
false, |
|
70
|
|
|
), |
|
71
|
|
|
'valid get, valid but outdated signature' => array( |
|
72
|
|
|
array( |
|
73
|
|
|
'signature' => 'asd', |
|
74
|
|
|
'timestamp' => time() - 400, |
|
75
|
|
|
'url' => 'https://example.com', |
|
76
|
|
|
), |
|
77
|
|
|
1, |
|
78
|
|
|
false, |
|
79
|
|
|
), |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|