Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/GeoIPLocationTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ipGeolocation\tests;
4
5
use GuzzleHttp\Exception\RequestException;
6
use GuzzleHttp\Handler\MockHandler;
7
use GuzzleHttp\Psr7\Request;
8
use GuzzleHttp\Psr7\Response;
9
use ipGeolocation\GeoIPLocation;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * Tests for GeoIPLocation class
14
 *
15
 * PHP version 7
16
 *
17
 * @author yasir khurshid <[email protected]>
18
 */
19
class GeoIPLocationTest extends TestCase
20
{
21
    /**
22
     * Success response
23
     *
24
     * @var array
25
     */
26
    private $responseSuccess = array (
27
        'status' => 'success',
28
        'country' => 'Germany',
29
        'countryCode' => 'DE',
30
        'region' => 'NW',
31
        'regionName' => 'North Rhine-Westphalia',
32
        'city' => 'Wesseling',
33
        'zip' => '50389',
34
        'lat' => '50.8271',
35
        'lon' => '6.9747',
36
        'timezone' => 'Europe/Berlin',
37
    );
38
39
    /**
40
     * Fail response
41
     *
42
     * @var array
43
     */
44
    private $responseFail = array (
45
        'status' => 'fail',
46
        'message' => 'reserved range',
47
    );
48
49
    /**
50
     * Test for getGeoLocation method
51
     */
52
    public function testGetGeoLocation()
53
    {
54
        $_SERVER['REMOTE_ADDR'] = '188.110.9.8';
55
56
        $location = $this->getMock($this->responseSuccess)->getGeoLocation();
57
58
        $this->assertInstanceOf('ipGeolocation\Location', $location);
59
        $this->assertTrue($location->getStatus());
60
        $this->assertSame('Germany', $location->getCountry());
61
        $this->assertSame('Wesseling', $location->getCity());
62
        $this->assertSame('DE', $location->getCountryCode());
63
        $this->assertSame(50.8271, $location->getLatitude());
64
        $this->assertSame(6.9747, $location->getLongitude());
65
        $this->assertSame('NW', $location->getRegionCode());
66
        $this->assertSame('North Rhine-Westphalia', $location->getRegionName());
67
        $this->assertSame('Europe/Berlin', $location->getTimezone());
68
        $this->assertSame(50389, $location->getPostalCode());
69
        $this->assertSame('EUR', $location->getCurrencyIso());
70
    }
71
72
    /**
73
     * Fail test case for getGeoLocation
74
     */
75 View Code Duplication
    public function testGetGeoLocationFail()
0 ignored issues
show
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...
76
    {
77
        $_SERVER['REMOTE_ADDR'] = '';
78
        $location = $this->getMock($this->responseFail)->getGeoLocation();
79
80
        $this->assertFalse($location->getStatus());
81
        $this->assertSame('reserved range', $location->getMessage());
82
    }
83
84
    /**
85
     * Test case for invalid Ip Address
86
     */
87
    public function testGetGeoLocationIpInvalid()
88
    {
89
        $_SERVER['REMOTE_ADDR'] = '188.11098';
90
        $geoIp = $this->getMock($this->responseFail);
91
        $location = $geoIp->getGeoLocation();
92
93
        $this->assertFalse($location->getStatus());
94
        $this->assertSame('reserved range', $location->getMessage());
95
        $this->assertSame('127.0.0.1', $geoIp->getIpAddress());
96
    }
97
98
    /**
99
     * Test case for invalid request
100
     */
101
    public function testRequestInvalid()
102
    {
103
        $location = $this->getMockRequestException()->getGeoLocation();
104
105
        $this->assertFalse($location->getStatus());
106
        $this->assertSame('Client error: 400', $location->getMessage());
107
    }
108
109
    /**
110
     * Test case for invalid response
111
     */
112 View Code Duplication
    public function testResponseInvalid()
0 ignored issues
show
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...
113
    {
114
        $location = $this->getMock(array(), 500)->getGeoLocation();
115
116
        $this->assertFalse($location->getStatus());
117
        $this->assertSame('Request failed with response code: 500 and response: Internal Server Error', $location->getMessage());
118
    }
119
120
    /**
121
     * Get mocked object to avoid live api requests
122
     *
123
     * @param array $response Response
124
     * @param int $statusCode       Http status code
125
     *
126
     * @return GeoIPLocation
127
     */
128
    private function getMock(array $response = array(), int $statusCode = 200): GeoIPLocation
129
    {
130
       $mock = new MockHandler(array(
131
            new Response($statusCode, [], \json_encode($response), '1.1', ''),
132
            new RequestException('Client error: 400', new Request('GET', 'test'))
133
        ));
134
135
        return (new GeoIPLocation())->setMockHandler($mock);
136
    }
137
138
    /**
139
     * Get mock object for exception to test edge error case
140
     *
141
     * @return GeoIPLocation
142
     */
143
    private function getMockRequestException()
144
    {
145
        $mock = new MockHandler(array(
146
            new RequestException('Client error: 400', new Request('GET', 'test'))
147
        ));
148
149
        return (new GeoIPLocation())->setMockHandler($mock);
150
    }
151
}
152