Passed
Push — master ( c44d00...13b3c2 )
by David
53s
created

HostHeaderTest::testMultipleHostHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

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 7
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\Middlewares\OriginFetchers;
4
5
use TheCodingMachine\Middlewares\CsrfHeaderCheckMiddlewareException;
6
use Zend\Diactoros\ServerRequest;
7
8
class HostHeaderTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function testFetchHost()
11
    {
12
        $request = new ServerRequest([], [], "http://alice.com:8080/hello", "Post");
13
14
        $hostHeader = new HostHeader();
15
16
        $hosts = $hostHeader($request);
17
18
        $this->assertSame(['alice.com'], $hosts);
19
    }
20
21 View Code Duplication
    public function testForwardedHostIgnored()
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...
22
    {
23
        $request = new ServerRequest([], [], "http://alice.com:8080/hello", "Post");
24
        $request = $request->withHeader('X-Forwarded-Host', 'eve.com');
25
26
        $hostHeader = new HostHeader();
27
28
        $hosts = $hostHeader($request);
29
30
        $this->assertSame(['alice.com'], $hosts);
31
    }
32
33
    public function testMultipleHostHeaders()
34
    {
35
        $request = new ServerRequest([], [], "http://alice.com:8080/hello", "Post");
36
        $request = $request->withAddedHeader('Host', 'eve.com');
37
38
        $hostHeader = new HostHeader();
39
40
        $this->expectException(CsrfHeaderCheckMiddlewareException::class);
41
        $this->expectExceptionMessage("Unexpected request: more than one HOST header sent.");
42
        $hostHeader($request);
43
    }
44
}
45