forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreferer.php
More file actions
159 lines (132 loc) · 5.26 KB
/
referer.php
File metadata and controls
159 lines (132 loc) · 5.26 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Test wp_get_referer().
*
* @group functions.php
* @covers ::wp_get_referer
* @covers ::wp_get_raw_referer
*/
class Tests_Functions_Referer extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_REFERER'] = '';
$_SERVER['REQUEST_URI'] = '';
$_REQUEST['_wp_http_referer'] = '';
}
public function tearDown() {
parent::tearDown();
$_SERVER['HTTP_REFERER'] = '';
$_SERVER['REQUEST_URI'] = '';
$_REQUEST['_wp_http_referer'] = '';
}
public function _fake_subfolder_install() {
return 'http://' . WP_TESTS_DOMAIN . '/subfolder';
}
public function filter_allowed_redirect_hosts( $hosts ) {
$hosts[] = 'another.' . WP_TESTS_DOMAIN;
return $hosts;
}
public function test_from_request_relative_referrer() {
$_REQUEST['_wp_http_referer'] = addslashes( '/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertFalse( wp_get_referer() );
}
public function test_from_request_same_url() {
$_REQUEST['_wp_http_referer'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertFalse( wp_get_referer() );
}
public function test_from_request_different_resource() {
$_REQUEST['_wp_http_referer'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/another.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/another.php?id=123', wp_get_referer() );
}
public function test_from_request_different_query_args() {
$_REQUEST['_wp_http_referer'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/test.php?another=555' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/test.php?another=555', wp_get_referer() );
}
/**
* @ticket 19856
*/
public function test_from_request_subfolder_install() {
add_filter( 'site_url', array( $this, '_fake_subfolder_install' ) );
$_REQUEST['_wp_http_referer'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/subfolder/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/subfolder/test.php?id=123' );
$this->assertFalse( wp_get_referer() );
remove_filter( 'site_url', array( $this, '_fake_subfolder_install' ) );
}
/**
* @ticket 19856
*/
public function test_from_request_subfolder_install_different_resource() {
add_filter( 'site_url', array( $this, '_fake_subfolder_install' ) );
$_REQUEST['_wp_http_referer'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/subfolder/another.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/subfolder/test.php?id=123' );
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/subfolder/another.php?id=123', wp_get_referer() );
remove_filter( 'site_url', array( $this, '_fake_subfolder_install' ) );
}
public function test_relative_referrer() {
$_REQUEST['HTTP_REFERER'] = addslashes( '/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertFalse( wp_get_referer() );
}
public function test_same_url() {
$_SERVER['HTTP_REFERER'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertFalse( wp_get_referer() );
}
public function test_different_resource() {
$_SERVER['HTTP_REFERER'] = addslashes( 'http://' . WP_TESTS_DOMAIN . '/another.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/another.php?id=123', wp_get_referer() );
}
/**
* @ticket 19856
* @ticket 27152
*/
public function test_different_server() {
$_SERVER['HTTP_REFERER'] = addslashes( 'http://another.' . WP_TESTS_DOMAIN . '/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertFalse( wp_get_referer() );
}
/**
* @ticket 19856
* @ticket 27152
*/
public function test_different_server_allowed_redirect_host() {
add_filter( 'allowed_redirect_hosts', array( $this, 'filter_allowed_redirect_hosts' ) );
$_SERVER['HTTP_REFERER'] = addslashes( 'http://another.' . WP_TESTS_DOMAIN . '/test.php?id=123' );
$_SERVER['REQUEST_URI'] = addslashes( '/test.php?id=123' );
$this->assertSame( 'http://another.' . WP_TESTS_DOMAIN . '/test.php?id=123', wp_get_referer() );
remove_filter( 'allowed_redirect_hosts', array( $this, 'filter_allowed_redirect_hosts' ) );
}
/**
* @ticket 27152
*/
public function test_raw_referer_empty() {
$this->assertFalse( wp_get_raw_referer() );
}
/**
* @ticket 27152
*/
public function test_raw_referer() {
$_SERVER['HTTP_REFERER'] = addslashes( 'http://example.com/foo?bar' );
$this->assertSame( 'http://example.com/foo?bar', wp_get_raw_referer() );
}
/**
* @ticket 27152
*/
public function test_raw_referer_from_request() {
$_REQUEST['_wp_http_referer'] = addslashes( 'http://foo.bar/baz' );
$this->assertSame( 'http://foo.bar/baz', wp_get_raw_referer() );
}
/**
* @ticket 27152
*/
public function test_raw_referer_both() {
$_SERVER['HTTP_REFERER'] = addslashes( 'http://example.com/foo?bar' );
$_REQUEST['_wp_http_referer'] = addslashes( 'http://foo.bar/baz' );
$this->assertSame( 'http://foo.bar/baz', wp_get_raw_referer() );
}
}