Completed
Pull Request — master (#1)
by David
02:43
created

testFailingPostRequestNoOrigin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\Middlewares\OriginFetchers;
4
5
use PHPUnit\Framework\TestCase;
6
use TheCodingMachine\Middlewares\CsrfHeaderCheckMiddlewareException;
7
use Zend\Diactoros\ServerRequest;
8
9
class OriginOrRefererHeaderTest extends TestCase
10
{
11
    public function testFailingPostRequestNoOrigin()
12
    {
13
        $request = new ServerRequest([], [], "http://alice.com/hello", "Post");
14
15
        $headerFetcher = new OriginOrRefererHeader();
16
17
        $this->expectException(CsrfHeaderCheckMiddlewareException::class);
18
        $this->expectExceptionMessage('Could not find neither the ORIGIN header nor the REFERER header in the HTTP request.');
19
20
        $headerFetcher($request);
21
    }
22
23 View Code Duplication
    public function testOriginFetch()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $request = new ServerRequest([], [], "http://alice.com/hello", "Post");
26
        $request = $request->withHeader('Origin', 'http://eve.com');
27
28
        $headerFetcher = new OriginOrRefererHeader();
29
30
        $this->assertSame('eve.com', $headerFetcher($request));
31
    }
32
33 View Code Duplication
    public function testRefererFetch()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $request = new ServerRequest([], [], "http://alice.com/hello", "Post");
36
        $request = $request->withHeader('Referer', 'http://eve.com/foobar?id=42');
37
38
        $headerFetcher = new OriginOrRefererHeader();
39
40
        $this->assertSame('eve.com', $headerFetcher($request));
41
    }
42
}
43