Issues (5)

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/ClientTest.php (5 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 LeverTest\Api;
4
5
use GuzzleHttp\Client as HttpClient;
6
use Lever\Api\Client;
7
use PHPUnit_Framework_TestCase;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * LeverTest\Api\ClientTest
12
 */
13
class ClientTest extends PHPUnit_Framework_TestCase
14
{
15
    /** @var Client */
16
    protected $client;
17
18
    /** @var HttpClient | \Prophecy\Prophecy\ObjectProphecy */
19
    protected $mockClient;
20
21
    public function setUp()
22
    {
23
        $this->client = new Client(
24
            [
25
                'authToken'  => 'myToken',
26
                'httpClient' => $this->mockClient()->reveal(),
27
            ]
28
        );
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function hasDefaultEndpoint()
35
    {
36
        $this->assertEquals('https://api.lever.co/v1', $this->client->getEndpoint());
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function canMutateEndpoint()
43
    {
44
        $this->client = new Client(['endpoint' => 'https://test.lever.co/v2/']);
45
        $this->assertEquals('https://test.lever.co/v2', $this->client->getEndpoint());
46
    }
47
48
    /**
49
     * @test
50
     */
51 View Code Duplication
    public function canMakeGetRequests()
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...
52
    {
53
        $query = ['foo' => 'bar'];
54
55
        $this->mockClient()->request(
56
            'GET',
57
            $this->url('/foo'),
58
            [
59
                'auth'  => ['myToken', ''],
60
                'query' => $query,
61
            ]
62
        )->willReturn($this->fooBarResponse());
63
64
        $data = $this->client->get('/foo', $query);
65
66
        $this->assertFooBarResponse($data);
67
    }
68
69
    /**
70
     * @test
71
     */
72 View Code Duplication
    public function canMakePostRequests()
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...
73
    {
74
        $postData = ['foo' => 'bar'];
75
76
        $this->mockClient()->request(
77
            'POST',
78
            $this->url('/foo'),
79
            [
80
                'auth'        => ['myToken', ''],
81
                'form_params' => $postData,
82
            ]
83
        )->willReturn($this->fooBarResponse());
84
85
        $data = $this->client->post('/foo', $postData);
86
87
        $this->assertFooBarResponse($data);
88
    }
89
90
    /**
91
     * @test
92
     */
93 View Code Duplication
    public function canMakePutRequest()
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...
94
    {
95
        $putData = ['foo' => 'bar'];
96
97
        $this->mockClient()->request(
98
            'PUT',
99
            $this->url('/foo'),
100
            [
101
                'auth' => ['myToken', ''],
102
                'json' => $putData,
103
            ]
104
        )->willReturn($this->fooBarResponse());
105
106
        $data = $this->client->put('/foo', $putData);
107
108
        $this->assertFooBarResponse($data);
109
    }
110
111
    /**
112
     * @return \Prophecy\Prophecy\ObjectProphecy
113
     */
114
    private function mockClient()
115
    {
116
        if ($this->mockClient === null) {
117
            $this->mockClient = $this->prophesize(HttpClient::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\GuzzleHttp\Client::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<GuzzleHttp\Client> of property $mockClient.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
118
        }
119
120
        return $this->mockClient;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->mockClient; of type Prophecy\Prophecy\ObjectProphecy|GuzzleHttp\Client adds the type GuzzleHttp\Client to the return on line 120 which is incompatible with the return type documented by LeverTest\Api\ClientTest::mockClient of type Prophecy\Prophecy\ObjectProphecy.
Loading history...
121
    }
122
123
    /**
124
     * @param string $path
125
     *
126
     * @return string
127
     */
128
    private function url($path = '/')
129
    {
130
        return 'https://api.lever.co/v1' . $path;
131
    }
132
133
    private function fooBarResponse()
134
    {
135
        $response = $this->prophesize(ResponseInterface::class);
136
        $response->getBody()->willReturn('{"foo":"bar"}');
137
138
        return $response->reveal();
139
    }
140
141
    /**
142
     * @param array $data
143
     */
144
    private function assertFooBarResponse($data)
145
    {
146
        $this->assertEquals(['foo' => 'bar'], $data);
147
    }
148
}
149