HostHeaderTest::testFetchHost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
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 HostHeaderTest extends TestCase
10
{
11
    public function testFetchHost()
12
    {
13
        $request = new ServerRequest([], [], "http://alice.com:8080/hello", "Post");
14
15
        $hostHeader = new HostHeader();
16
17
        $hosts = $hostHeader($request);
18
19
        $this->assertSame(['alice.com'], $hosts);
20
    }
21
22 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...
23
    {
24
        $request = new ServerRequest([], [], "http://alice.com:8080/hello", "Post");
25
        $request = $request->withHeader('X-Forwarded-Host', 'eve.com');
26
27
        $hostHeader = new HostHeader();
28
29
        $hosts = $hostHeader($request);
30
31
        $this->assertSame(['alice.com'], $hosts);
32
    }
33
34
    public function testMultipleHostHeaders()
35
    {
36
        $request = new ServerRequest([], [], "http://alice.com:8080/hello", "Post");
37
        $request = $request->withAddedHeader('Host', 'eve.com');
38
39
        $hostHeader = new HostHeader();
40
41
        $this->expectException(CsrfHeaderCheckMiddlewareException::class);
42
        $this->expectExceptionMessage("Unexpected request: more than one HOST header sent.");
43
        $hostHeader($request);
44
    }
45
}
46