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.

src/Object/Tests/ApparatObjectTest.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
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Infrastructure
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Tests;
38
39
use Apparat\Kernel\Ports\Kernel;
40
use Apparat\Object\Application\Model\Object\Article as ApplicationArticle;
41
use Apparat\Object\Infrastructure\Model\Object\Object;
42
use Apparat\Object\Ports\Facades\RepositoryFacade;
43
use Apparat\Object\Ports\Factory\SelectorFactory;
44
use Apparat\Object\Ports\Object\Article;
45
use Apparat\Object\Ports\Object\Contact;
46
use Apparat\Object\Ports\Types\Object as ObjectTypes;
47
48
/**
49
 * Object URL tests
50
 *
51
 * @package Apparat\Object
52
 * @subpackage Apparat\Object\Test
53
 */
54
class ApparatObjectTest extends AbstractRepositoryEnabledTest
55
{
56
    /**
57
     * Example article locator
58
     *
59
     * @var string
60
     */
61
    const ARTICLE_LOCATOR = '/repo/2015/12/21/1-article/1';
62
    /**
63
     * Example contact locator
64
     *
65
     * @var string
66
     */
67
    const CONTACT_LOCATOR = '/repo/2016/01/08/2-contact/2';
68
69
    /**
70
     * Test the apparat object factory with an invalid object type
71
     *
72
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
73
     * @expectedExceptionCode 1465368597
74
     */
75
    public function testApparatObjectFactoryInvalidType()
76
    {
77
        /** @var ApplicationArticle $articleObj */
78
        $articleObj = Object::load(self::ARTICLE_LOCATOR);
79
        TestApparatObjectFactory::create($articleObj);
80
    }
81
82
    /**
83
     * Test the selection of apparat objects via the repository facade
84
     */
85
    public function testApparatObjectFindCollection()
86
    {
87
        $selector = SelectorFactory::createFromString('/2015/*/*/*-article');
88
        $apparatObjects = RepositoryFacade::instance(getenv('REPOSITORY_URL'))->findObjects($selector);
89
        $this->assertTrue(is_array($apparatObjects));
90
        foreach ($apparatObjects as $apparatObject) {
91
            $this->assertInstanceOf(Article::class, $apparatObject);
92
        }
93
        $this->assertEquals(
94
            count($apparatObjects),
95
            count(RepositoryFacade::instance(getenv('REPOSITORY_URL'))->findObjects('/2015/*/*/*-article'))
96
        );
97
    }
98
99
    /**
100
     * Test the article apparat object with an illegal setter
101
     *
102
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
103
     * @expectedExceptionCode 1466804125
104
     */
105
    public function testArticleApparatObjectIllegalSetter()
106
    {
107
        /** @var Article $articleApparatObj */
108
        $articleApparatObj = RepositoryFacade::instance('repo')->loadObject(self::ARTICLE_LOCATOR);
109
        $this->assertInstanceOf(Article::class, $articleApparatObj);
110
111
        $this->assertEquals(ObjectTypes::ARTICLE, $articleApparatObj['type']);
112
        $this->assertTrue(isset($articleApparatObj['name']));
113
        $this->assertEquals('First repository article', $articleApparatObj['name']);
114
        $this->assertEquals('First repository article', $articleApparatObj->getName());
115
        $articleApparatObj['name'] = null;
116
    }
117
118
    /**
119
     * Test the article apparat object with an invalid getter
120
     *
121
     * @expectedException \BadMethodCallException
122
     */
123
    public function testArticleApparatObjectInvalidGetter()
124
    {
125
        /** @var Article $articleApparatObj */
126
        $articleApparatObj = RepositoryFacade::instance('repo')->loadObject(self::ARTICLE_LOCATOR);
127
        $this->assertInstanceOf(Article::class, $articleApparatObj);
128
129
        // Test serialization / deserialization
130
        $serialized = serialize($articleApparatObj);
131
        $unserializedArticle = unserialize($serialized);
132
        $this->assertEquals($unserializedArticle['name'], $articleApparatObj['name']);
133
134
        // Test iteration
135
        $articleArray = $articleApparatObj->getArrayCopy();
136
        $this->assertEquals(count($articleArray), count($articleApparatObj));
137
        foreach ($articleApparatObj as $property => $value) {
138
            $this->assertTrue(array_key_exists($property, $articleArray));
139
            $this->assertEquals($articleArray[$property], $value);
140
            unset($articleArray[$property]);
141
        }
142
        $this->assertEquals(0, count($articleArray));
143
144
        /** @noinspection PhpUndefinedMethodInspection */
145
        $articleApparatObj->getInvalid();
0 ignored issues
show
Documentation Bug introduced by
The method getInvalid does not exist on object<Apparat\Object\Ports\Object\Article>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
146
    }
147
148
    /**
149
     * Test the article apparat object with an invalid array getter
150
     *
151
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
152
     * @expectedExceptionCode 1465330399
153
     */
154
    public function testArticleApparatObjectInvalidArrayGetter()
155
    {
156
        /** @var Article $articleApparatObj */
157
        $articleApparatObj = RepositoryFacade::instance('repo')->loadObject(self::ARTICLE_LOCATOR);
158
        $this->assertInstanceOf(Article::class, $articleApparatObj);
159
160
        $articleApparatObj['invalid'];
161
    }
162
163
    /**
164
     * Test the article apparat object with an invalid array append
165
     *
166
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
167
     * @expectedExceptionCode 1466804193
168
     */
169
    public function testArticleApparatObjectInvalidArrayAppend()
170
    {
171
        /** @var Article $articleApparatObj */
172
        $articleApparatObj = RepositoryFacade::instance('repo')->loadObject(self::ARTICLE_LOCATOR);
173
        $this->assertInstanceOf(Article::class, $articleApparatObj);
174
175
        $articleApparatObj->append('invalid');
176
    }
177
178
    /**
179
     * Test sorting and exchange methods of an article apparat object
180
     *
181
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
182
     * @expectedExceptionCode 1466805183
183
     */
184
    public function testArticleApparatObjectSortingExchange()
185
    {
186
        /** @var Article $articleApparatObj */
187
        $articleApparatObj = RepositoryFacade::instance('repo')->loadObject(self::ARTICLE_LOCATOR);
188
        $this->assertInstanceOf(Article::class, $articleApparatObj);
189
190
        $articleApparatObj->asort();
191
        $articleApparatObj->ksort();
192
        $articleApparatObj->uasort(function () {
193
        });
194
        $articleApparatObj->uksort(function () {
195
        });
196
        $articleApparatObj->natsort();
197
        $articleApparatObj->natcasesort();
198
199
        /** @var ApplicationArticle $articleObj */
200
        $articleObj = Object::load(self::ARTICLE_LOCATOR);
201
        $articleApparatObj->exchangeArray($articleObj);
202
        $articleApparatObj->exchangeArray(new \stdClass());
203
    }
204
205
    /**
206
     * Test illegal unsetting of apparat object property
207
     *
208
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
209
     * @expectedExceptionCode 1465330565
210
     */
211
    public function testArticleApparatObjectUnvalidUnset()
212
    {
213
        /** @var Article $articleApparatObj */
214
        $articleApparatObj = RepositoryFacade::instance('repo')->loadObject(self::ARTICLE_LOCATOR);
215
        unset($articleApparatObj['name']);
216
    }
217
218
    /**
219
     * Test invalid apparat object getter
220
     *
221
     * @expectedException \Apparat\Object\Ports\Exceptions\InvalidArgumentException
222
     * @expectedExceptionCode 1465330399
223
     */
224
    public function testInvalidApparatObjectGetter()
225
    {
226
        /** @var ApplicationArticle $articleObj */
227
        $articleObj = Object::load(self::ARTICLE_LOCATOR);
228
        $articleApparatObj = Kernel::create(TestApparatObject::class, [$articleObj]);
229
        $articleApparatObj['invalid'];
230
    }
231
232
    /**
233
     * Test the contact object
234
     */
235
    public function testContactObject()
236
    {
237
        $contactApparatObject = RepositoryFacade::instance('repo')->loadObject(self::CONTACT_LOCATOR);
238
        $this->assertInstanceOf(Contact::class, $contactApparatObject);
239
    }
240
}
241