Skip to content

Commit 11b5c26

Browse files
committed
test: fix tests
Security object should be created after setting super globals.
1 parent fa78859 commit 11b5c26

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

tests/system/Security/SecurityTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public function testGetHashSetsCookieWhenNotPOST()
7979

8080
public function testCSRFVerifyPostThrowsExceptionOnNoMatch()
8181
{
82-
$security = new MockSecurity(new MockAppConfig());
83-
$request = new IncomingRequest(new MockAppConfig(), new URI('http://badurl.com'), null, new UserAgent());
84-
8582
$_SERVER['REQUEST_METHOD'] = 'POST';
8683
$_POST['csrf_test_name'] = '8b9218a55906f9dcc1dc263dce7f005a';
8784
$_COOKIE['csrf_cookie_name'] = '8b9218a55906f9dcc1dc263dce7f005b';
8885

86+
$security = new MockSecurity(new MockAppConfig());
87+
$request = new IncomingRequest(new MockAppConfig(), new URI('http://badurl.com'), null, new UserAgent());
88+
8989
$this->expectException(SecurityException::class);
9090
$security->verify($request);
9191
}
@@ -108,14 +108,14 @@ public function testCSRFVerifyPostReturnsSelfOnMatch()
108108

109109
public function testCSRFVerifyHeaderThrowsExceptionOnNoMatch()
110110
{
111+
$_SERVER['REQUEST_METHOD'] = 'POST';
112+
$_COOKIE['csrf_cookie_name'] = '8b9218a55906f9dcc1dc263dce7f005b';
113+
111114
$security = new MockSecurity(new MockAppConfig());
112115
$request = new IncomingRequest(new MockAppConfig(), new URI('http://badurl.com'), null, new UserAgent());
113116

114117
$request->setHeader('X-CSRF-TOKEN', '8b9218a55906f9dcc1dc263dce7f005a');
115118

116-
$_SERVER['REQUEST_METHOD'] = 'POST';
117-
$_COOKIE['csrf_cookie_name'] = '8b9218a55906f9dcc1dc263dce7f005b';
118-
119119
$this->expectException(SecurityException::class);
120120
$security->verify($request);
121121
}
@@ -139,14 +139,14 @@ public function testCSRFVerifyHeaderReturnsSelfOnMatch()
139139

140140
public function testCSRFVerifyJsonThrowsExceptionOnNoMatch()
141141
{
142+
$_SERVER['REQUEST_METHOD'] = 'POST';
143+
$_COOKIE['csrf_cookie_name'] = '8b9218a55906f9dcc1dc263dce7f005b';
144+
142145
$security = new MockSecurity(new MockAppConfig());
143146
$request = new IncomingRequest(new MockAppConfig(), new URI('http://badurl.com'), null, new UserAgent());
144147

145148
$request->setBody('{"csrf_test_name":"8b9218a55906f9dcc1dc263dce7f005a"}');
146149

147-
$_SERVER['REQUEST_METHOD'] = 'POST';
148-
$_COOKIE['csrf_cookie_name'] = '8b9218a55906f9dcc1dc263dce7f005b';
149-
150150
$this->expectException(SecurityException::class);
151151
$security->verify($request);
152152
}

0 commit comments

Comments
 (0)