Issues (35)

Security Analysis    not enabled

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.

spec/Processor/HalJsonProcessorSpec.php (1 issue)

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 spec\TomPHP\HalClient\Processor;
4
5
use PhpSpec\ObjectBehavior;
6
use TomPHP\HalClient\Exception\FieldNotFoundException;
7
use TomPHP\HalClient\Exception\ProcessingException;
8
use TomPHP\HalClient\ResourceFetcher;
9
use Zend\Diactoros\Response;
10
11
class HalJsonProcessorSpec extends ObjectBehavior
12
{
13
    /** @var Response */
14
    private $response;
15
16
    function let()
17
    {
18
        $body = 'data://text/plain,{
19
            "_links": {
20
                "self": {
21
                    "href": "http://www.somewhere.com/",
22
                    "rel": "self"
23
                },
24
                "other": {
25
                    "href": "http://www.somewhere.com/other"
26
                }
27
            },
28
            "field1": "value1",
29
            "map": {
30
                "mapfield": "mapvalue"
31
            },
32
            "collection": [
33
                {"name": "item1"}
34
            ],
35
            "_embedded": {
36
                "resource1": {
37
                    "subfield": "subvalue"
38
                },
39
                "resourcecollection": [
40
                    {"name": "collectionvalue"}
41
                ]
42
            }
43
        }';
44
45
        $this->response = new Response($body, 200, ['content-type' => 'application/hal+json']);
46
    }
47
48
    function it_returns_the_hal_plus_json_content_type()
49
    {
50
        $this->getContentType()->shouldReturn('application/hal+json');
51
    }
52
53
    function it_throws_for_bad_json_error(ResourceFetcher $fetcher)
54
    {
55
        $json = '{bad, josn}';
56
        json_decode($json);
57
        $error = json_last_error_msg();
58
59
        $response = new Response("data://text/plain,$json", 200, ['content-type' => 'application/hal+json']);
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $json instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
60
61
        $this->shouldThrow(ProcessingException::badJson($error))
62
             ->duringProcess($response, $fetcher);
63
    }
64
65
    function it_processes_simple_single_fields(ResourceFetcher $fetcher)
66
    {
67
        $resource = $this->process($this->response, $fetcher);
68
69
        $resource->field1->getValue()->shouldReturn('value1');
70
    }
71
72
    function it_processes_fields_which_are_maps(ResourceFetcher $fetcher)
73
    {
74
        $resource = $this->process($this->response, $fetcher);
75
76
        $resource->map->mapfield->getValue()->shouldReturn('mapvalue');
77
    }
78
79
    function it_processes_fields_which_are_collections(ResourceFetcher $fetcher)
80
    {
81
        $resource = $this->process($this->response, $fetcher);
82
83
        $resource->collection[0]->name->getValue()->shouldReturn('item1');
84
    }
85
86
    function it_processes_links(ResourceFetcher $fetcher)
87
    {
88
        $resource = $this->process($this->response, $fetcher);
89
90
        $resource->getLinks()->shouldReturn(['self', 'other']);
91
    }
92
93
    function it_does_not_add_links_as_a_field(ResourceFetcher $fetcher)
94
    {
95
        $resource = $this->process($this->response, $fetcher);
96
97
        $resource->shouldThrow(new FieldNotFoundException('_links'))
98
                 ->duringGetField('_links');
99
    }
100
101
    function it_does_not_add_embedded_as_a_field(ResourceFetcher $fetcher)
102
    {
103
        $resource = $this->process($this->response, $fetcher);
104
105
        $resource->shouldThrow(new FieldNotFoundException('_embedded'))
106
                 ->duringGetField('_embedded');
107
    }
108
109
    function it_processes_resources(ResourceFetcher $fetcher)
110
    {
111
        $resource = $this->process($this->response, $fetcher);
112
113
        $resource->getResource('resource1')->subfield->getValue()->shouldReturn('subvalue');
114
    }
115
116
    function it_processes_resources_collections(ResourceFetcher $fetcher)
117
    {
118
        $resource = $this->process($this->response, $fetcher);
119
120
        $resource->getResource('resourcecollection')[0]->name->getValue()->shouldReturn('collectionvalue');
121
    }
122
}
123