Completed
Push — update/enable-connected-plugin... ( 2e5284...3ba303 )
by
unknown
177:29 queued 167:49
created

XMLRPC_Connector_Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_is_request_signed_by_jetpack_debugger() 0 11 1
A is_request_signed_by_jetpack_debugger_data() 0 36 1
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