GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 9d7a62...7e48e6 )
by Rob
03:32
created

SafeUrlsTest::testGetResults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RattfieldNz\SafeUrls;
6
7
use RattfieldNz\SafeUrls\Tests\TestCase;
8
9
class SafeUrlsTest extends TestCase
10
{
11
    /** @var SafeUrls */
12
    private $safeUrls;
13
14
    private $urlsToTest;
15
16
    protected function setUp():void
17
    {
18
        parent::setUp();
19
20
        $this->safeUrls = new SafeUrls();
21
        $this->urlsToTest = [
22
            'https://testsafebrowsing.appspot.com/s/phishing.html',
23
            'https://testsafebrowsing.appspot.com/s/malware.html',
24
            'http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/',
25
            'http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/SOCIAL_ENGINEERING/URL/',
26
            'http://malware.testing.google.test/testing/malware/',
27
        ];
28
    }
29
30
    public function testAddUrls()
31
    {
32
        $this->safeUrls->add($this->urlsToTest);
33
34
        $expected = $this->urlsToTest;
35
        $actual = $this->safeUrls->getCurrentUrls(true);
36
37
        $this->assertEquals($expected, $actual);
38
    }
39
40
    public function testRemoveUrls()
41
    {
42
        $this->safeUrls->add($this->urlsToTest);
43
        $urlToRemove = 'https://testsafebrowsing.appspot.com/s/phishing.html';
44
45
        $expected = [
46
            $this->urlsToTest[1],
47
            $this->urlsToTest[2],
48
            $this->urlsToTest[3],
49
            $this->urlsToTest[4]
50
        ];
51
        $this->safeUrls->remove([$urlToRemove]);
52
53
        $actual = $this->safeUrls->getCurrentUrls(true);
54
55
        $this->assertEquals($expected, $actual);
56
    }
57
58
    public function testRemoveAllUrls(){
59
        $this->safeUrls->add($this->urlsToTest);
60
61
        $expected = [];
62
        $this->safeUrls->remove($this->urlsToTest);
63
        $actual = $this->safeUrls->getCurrentUrls(true);
64
65
        $this->assertEquals($expected, $actual);
66
    }
67
68
    public function testExecute(){
69
70
        // Only testing with returned HTTP status, as Google Safebrowsing API not working as
71
        // documented. See tests\Libraries\Curl\CurlTest testMalwareSocialEngineeringAnyPlatformUrl().
72
73
        $this->safeUrls->add($this->urlsToTest);
74
75
        $expected = '{ "status": 200, "response": { "matches": [ { "threatType": "SOCIAL_ENGINEERING", "platformType": "ANY_PLATFORM", "threat": { "url": "https://testsafebrowsing.appspot.com/s/phishing.html" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "MALWARE", "platformType": "ANY_PLATFORM", "threat": { "url": "https://testsafebrowsing.appspot.com/s/malware.html" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "MALWARE", "platformType": "ANY_PLATFORM", "threat": { "url": "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "SOCIAL_ENGINEERING", "platformType": "ANY_PLATFORM", "threat": { "url": "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/SOCIAL_ENGINEERING/URL/" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "MALWARE", "platformType": "ANY_PLATFORM", "threat": { "url": "http://malware.testing.google.test/testing/malware/" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "SOCIAL_ENGINEERING", "platformType": "ANY_PLATFORM", "threat": { "url": "http://malware.testing.google.test/testing/malware/" }, "cacheDuration": "300s", "threatEntryType": "URL" } ] } }';
76
77
        $expected = json_decode($expected, true)["status"];
78
        $actual = json_decode((string)$this->safeUrls->execute()->getResults(), true)["status"];
79
80
        $this->assertEquals($expected, $actual);
81
82
    }
83
84
    public function testGetResults(){
85
86
        $this->testExecute();
87
    }
88
89
    public function testCheck(){
90
91
        $expected = '{ "status": 200, "response": { "matches": [ { "threatType": "SOCIAL_ENGINEERING", "platformType": "ANY_PLATFORM", "threat": { "url": "https://testsafebrowsing.appspot.com/s/phishing.html" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "MALWARE", "platformType": "ANY_PLATFORM", "threat": { "url": "https://testsafebrowsing.appspot.com/s/malware.html" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "MALWARE", "platformType": "ANY_PLATFORM", "threat": { "url": "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "SOCIAL_ENGINEERING", "platformType": "ANY_PLATFORM", "threat": { "url": "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/SOCIAL_ENGINEERING/URL/" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "MALWARE", "platformType": "ANY_PLATFORM", "threat": { "url": "http://malware.testing.google.test/testing/malware/" }, "cacheDuration": "300s", "threatEntryType": "URL" }, { "threatType": "SOCIAL_ENGINEERING", "platformType": "ANY_PLATFORM", "threat": { "url": "http://malware.testing.google.test/testing/malware/" }, "cacheDuration": "300s", "threatEntryType": "URL" } ] } }';
92
        $expected = json_decode($expected, true)["status"];
93
94
        $actual = json_decode($this->safeUrls::check($this->urlsToTest), true)["status"];
95
96
        $this->assertEquals($expected, $actual);
97
    }
98
99
    /**
100
     * @expectedException \ErrorException
101
     */
102
    public function testCheckThrowErrorException(){
103
        $this->safeUrls->add($this->urlsToTest);
104
105
        $safeUrlsMock = $this->getMockBuilder(SafeUrls::class)
106
            ->setMethods(['callStatic'])
107
            ->getMock();
108
109
        $safeUrlsMock->method("callStatic")
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
        $safeUrlsMock->/** @scrutinizer ignore-call */ 
110
                       method("callStatic")

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
            ->with(SafeUrls::class, 'check', $this->urlsToTest)
111
            ->willThrowException(new \ErrorException('Expected Exception was thrown'));
112
113
        $safeUrlsMock->checkCallStatic($this->urlsToTest);
0 ignored issues
show
Bug introduced by
The method checkCallStatic() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        $safeUrlsMock->/** @scrutinizer ignore-call */ 
114
                       checkCallStatic($this->urlsToTest);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
115
    }
116
117
    public function testIsDangerous(){
118
        $this->safeUrls->add($this->urlsToTest);
119
        $this->safeUrls->execute();
120
121
        $dangerousUrl = "http://malware.testing.google.test/testing/malware/";
122
123
        // See tests\Libraries\Curl\CurlTest testMalwareSocialEngineeringAnyPlatformUrl().
124
        $expected = true;
125
        $actual = !$this->safeUrls->isDangerous($dangerousUrl);
126
127
        $this->assertEquals($expected, $actual);
128
129
    }
130
}
131