Issues (8)

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/Services/TestServices.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
 * Created by PhpStorm.
4
 * User: davis
5
 * Date: 7/23/17
6
 * Time: 2:12 PM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Tests\Services;
10
11
use DateTime;
12
use DavisPeixoto\BlogCore\Entity\Author;
13
use DavisPeixoto\BlogCore\Entity\Post;
14
use DavisPeixoto\BlogCore\Entity\Tag;
15
use DavisPeixoto\BlogCore\Entity\Trail;
16
use DavisPeixoto\BlogCore\Repository\AbstractAuthorRepository;
17
use DavisPeixoto\BlogCore\Repository\AbstractPostRepository;
18
use DavisPeixoto\BlogCore\Repository\AbstractTagRepository;
19
use DavisPeixoto\BlogCore\Repository\AbstractTrailRepository;
20
use DavisPeixoto\BlogCore\Service\CreateAuthor;
21
use DavisPeixoto\BlogCore\Service\CreatePost;
22
use DavisPeixoto\BlogCore\Service\CreateTag;
23
use DavisPeixoto\BlogCore\Service\CreateTrail;
24
use DavisPeixoto\BlogCore\Service\DeleteAuthor;
25
use DavisPeixoto\BlogCore\Service\DeletePost;
26
use DavisPeixoto\BlogCore\Service\DeleteTag;
27
use DavisPeixoto\BlogCore\Service\DeleteTrail;
28
use DavisPeixoto\BlogCore\Service\EditAuthor;
29
use DavisPeixoto\BlogCore\Service\EditPost;
30
use DavisPeixoto\BlogCore\Service\EditTag;
31
use DavisPeixoto\BlogCore\Service\EditTrail;
32
use DavisPeixoto\BlogCore\Service\GetAuthor;
33
use DavisPeixoto\BlogCore\Service\GetPost;
34
use DavisPeixoto\BlogCore\Service\GetTag;
35
use DavisPeixoto\BlogCore\Service\GetTrail;
36
use DavisPeixoto\BlogCore\Service\ListAuthors;
37
use DavisPeixoto\BlogCore\Service\ListPosts;
38
use DavisPeixoto\BlogCore\Service\ListTags;
39
use DavisPeixoto\BlogCore\Service\ListTrails;
40
use Exception;
41
use PHPUnit\Framework\TestCase;
42
use Psr\Log\LoggerInterface;
43
use Ramsey\Uuid\Uuid;
44
45
class TestServices extends TestCase
46
{
47
    /**
48
     * @param $repository
49
     * @param $entity
50
     * @param $logger
51
     * @param $serviceName
52
     * @param $method
53
     * @param $willReturn
54
     * @param $expected
55
     * @param $message
56
     * @dataProvider valueServiceProvider
57
     */
58
    public function testIsSuccessService(
59
        $serviceName,
60
        $method,
61
        $willReturn,
62
        $repository,
63
        $entity,
64
        $logger,
65
        $expected,
66
        $message
67
    ) {
68
        $repository->expects($this->once())->method($method)->will($this->returnValue($willReturn));
69
        $service = new $serviceName($repository, $entity, $logger);
70
        $this->assertEquals($expected, $service->run(), $message);
71
    }
72
73
    /**
74
     * @param $serviceName
75
     * @param $method
76
     * @param $repository
77
     * @param $entity
78
     * @param $logger
79
     * @param $expected
80
     * @param $message
81
     * @dataProvider exceptionServiceProvider
82
     */
83
    public function testIsExceptionService($serviceName, $method, $repository, $entity, $logger, $expected, $message)
84
    {
85
        $logger->expects($this->once())->method('error');
86
        $repository->expects($this->once())->method($method)->will($this->throwException(new Exception()));
87
        $service = new $serviceName($repository, $entity, $logger);
88
        $this->assertEquals($expected, $service->run(), $message);
89
    }
90
91
    public function valueServiceProvider()
92
    {
93
        $authorUuid = Uuid::uuid4()->toString();
94
        $postUuid = Uuid::uuid4()->toString();
95
        $tagUuid = Uuid::uuid4()->toString();
96
        $trailUuid = Uuid::uuid4()->toString();
97
98
        $author = new Author('Davis', '[email protected]', 'Some string', $authorUuid, new DateTime());
99
        $post = new Post('A Post', 'Lorem ipsum', $author, $postUuid, [], null);
100
        $tag = new Tag('A tag', $tagUuid);
101
        $trail = new Trail('A trail', 'An amazing trail', $trailUuid, [$post]);
102
        $filters = [];
103
104
        return [
105
            [CreateAuthor::class, 'save', $authorUuid, $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), $authorUuid, 'Create author service'],
0 ignored issues
show
This line exceeds maximum limit of 200 characters; contains 210 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
106
            [EditAuthor::class, 'save', $authorUuid, $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), $authorUuid, 'Edit author service'],
0 ignored issues
show
This line exceeds maximum limit of 200 characters; contains 206 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
107
            [DeleteAuthor::class, 'delete', true, $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), true, 'Delete author service'],
108
            [GetAuthor::class, 'get', $author, $this->getMockForAbstractClass(AbstractAuthorRepository::class), $authorUuid, $this->createMock(LoggerInterface::class), $author, 'Get author service'],
109
            [ListAuthors::class, 'getList', [$author], $this->getMockForAbstractClass(AbstractAuthorRepository::class), $filters, $this->createMock(LoggerInterface::class), [$author], 'List authors service'],
0 ignored issues
show
This line exceeds maximum limit of 200 characters; contains 208 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
110
            [CreatePost::class, 'save', $postUuid, $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), $postUuid, 'Create post service'],
111
            [EditPost::class, 'save', $postUuid, $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), $postUuid, 'Edit post service'],
112
            [DeletePost::class, 'delete', true, $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), true, 'Delete post service'],
113
            [GetPost::class, 'get', $post, $this->getMockForAbstractClass(AbstractPostRepository::class), $postUuid, $this->createMock(LoggerInterface::class), $post, 'Get post service'],
114
            [ListPosts::class, 'getList', [$post], $this->getMockForAbstractClass(AbstractPostRepository::class), $filters, $this->createMock(LoggerInterface::class), [$post], 'List posts service'],
115
            [CreateTag::class, 'save', $tagUuid, $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), $tagUuid, 'Create tag service'],
116
            [EditTag::class, 'save', $tagUuid, $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), $tagUuid, 'Edit tag service'],
117
            [DeleteTag::class, 'delete', true, $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), true, 'Delete tag service'],
118
            [GetTag::class, 'get', $tag, $this->getMockForAbstractClass(AbstractTagRepository::class), $tagUuid, $this->createMock(LoggerInterface::class), $tag, 'Get tag service'],
119
            [ListTags::class, 'getList', [$tag], $this->getMockForAbstractClass(AbstractTagRepository::class), $filters, $this->createMock(LoggerInterface::class), [$tag], 'List tags service'],
120
            [CreateTrail::class, 'save', $trailUuid, $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), $trailUuid, 'Create trail service'],
0 ignored issues
show
This line exceeds maximum limit of 200 characters; contains 204 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
121
            [EditTrail::class, 'save', $trailUuid, $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), $trailUuid, 'Edit trail service'],
122
            [DeleteTrail::class, 'delete', true, $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), true, 'Delete trail service'],
123
            [GetTrail::class, 'get', $trail, $this->getMockForAbstractClass(AbstractTrailRepository::class), $trailUuid, $this->createMock(LoggerInterface::class), $trail, 'Get trail service'],
124
            [ListTrails::class, 'getList', [$trail], $this->getMockForAbstractClass(AbstractTrailRepository::class), $filters, $this->createMock(LoggerInterface::class), [$trail], 'List trails service'],
0 ignored issues
show
This line exceeds maximum limit of 200 characters; contains 203 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
125
            [DeleteAuthor::class, 'delete', false, $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), false, 'Delete author service'],
126
            [GetAuthor::class, 'get', null, $this->getMockForAbstractClass(AbstractAuthorRepository::class), $authorUuid, $this->createMock(LoggerInterface::class), null, 'Get author service'],
127
            [ListAuthors::class, 'getList', [], $this->getMockForAbstractClass(AbstractAuthorRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List authors service'],
128
            [DeletePost::class, 'delete', false, $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), false, 'Delete post service'],
129
            [GetPost::class, 'get', null, $this->getMockForAbstractClass(AbstractPostRepository::class), $postUuid, $this->createMock(LoggerInterface::class), null, 'Get post service'],
130
            [ListPosts::class, 'getList', [], $this->getMockForAbstractClass(AbstractPostRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List posts service'],
131
            [DeleteTag::class, 'delete', false, $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), false, 'Delete tag service'],
132
            [GetTag::class, 'get', null, $this->getMockForAbstractClass(AbstractTagRepository::class), $tagUuid, $this->createMock(LoggerInterface::class), null, 'Get tag service'],
133
            [ListTags::class, 'getList', [], $this->getMockForAbstractClass(AbstractTagRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List tags service'],
134
            [DeleteTrail::class, 'delete', false, $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), false, 'Delete trail service'],
135
            [GetTrail::class, 'get', null, $this->getMockForAbstractClass(AbstractTrailRepository::class), $trailUuid, $this->createMock(LoggerInterface::class), null, 'Get trail service'],
136
            [ListTrails::class, 'getList', [], $this->getMockForAbstractClass(AbstractTrailRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List trails service']
137
        ];
138
    }
139
140
    public function exceptionServiceProvider()
141
    {
142
        $authorUuid = Uuid::uuid4()->toString();
143
        $postUuid = Uuid::uuid4()->toString();
144
        $tagUuid = Uuid::uuid4()->toString();
145
        $trailUuid = Uuid::uuid4()->toString();
146
147
        $author = new Author('Davis', '[email protected]', 'Some string', $authorUuid, new DateTime());
148
        $post = new Post('A Post', 'Lorem ipsum', $author, $postUuid, [], null);
149
        $tag = new Tag('A tag', $tagUuid);
150
        $trail = new Trail('A trail', 'An amazing trail', $trailUuid, [$post]);
151
        $filters = [];
152
153
        return [
154
            [CreateAuthor::class, 'save', $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), null, 'Create author service'],
155
            [EditAuthor::class, 'save', $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), null, 'Edit author service'],
156
            [DeleteAuthor::class, 'delete', $this->getMockForAbstractClass(AbstractAuthorRepository::class), $author, $this->createMock(LoggerInterface::class), false, 'Delete author service'],
157
            [GetAuthor::class, 'get', $this->getMockForAbstractClass(AbstractAuthorRepository::class), $authorUuid, $this->createMock(LoggerInterface::class), null, 'Get author service'],
158
            [ListAuthors::class, 'getList', $this->getMockForAbstractClass(AbstractAuthorRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List authors service'],
159
            [CreatePost::class, 'save', $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), null, 'Create post service'],
160
            [EditPost::class, 'save', $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), null, 'Edit post service'],
161
            [DeletePost::class, 'delete', $this->getMockForAbstractClass(AbstractPostRepository::class), $post, $this->createMock(LoggerInterface::class), false, 'Delete post service'],
162
            [GetPost::class, 'get', $this->getMockForAbstractClass(AbstractPostRepository::class), $postUuid, $this->createMock(LoggerInterface::class), null, 'Get post service'],
163
            [ListPosts::class, 'getList', $this->getMockForAbstractClass(AbstractPostRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List posts service'],
164
            [CreateTag::class, 'save', $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), null, 'Create tag service'],
165
            [EditTag::class, 'save', $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), null, 'Edit tag service'],
166
            [DeleteTag::class, 'delete', $this->getMockForAbstractClass(AbstractTagRepository::class), $tag, $this->createMock(LoggerInterface::class), false, 'Delete tag service'],
167
            [GetTag::class, 'get', $this->getMockForAbstractClass(AbstractTagRepository::class), $tagUuid, $this->createMock(LoggerInterface::class), null, 'Get tag service'],
168
            [ListTags::class, 'getList', $this->getMockForAbstractClass(AbstractTagRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List tags service'],
169
            [CreateTrail::class, 'save', $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), null, 'Create trail service'],
170
            [EditTrail::class, 'save', $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), null, 'Edit trail service'],
171
            [DeleteTrail::class, 'delete', $this->getMockForAbstractClass(AbstractTrailRepository::class), $trail, $this->createMock(LoggerInterface::class), false, 'Delete trail service'],
172
            [GetTrail::class, 'get', $this->getMockForAbstractClass(AbstractTrailRepository::class), $trailUuid, $this->createMock(LoggerInterface::class), null, 'Get trail service'],
173
            [ListTrails::class, 'getList', $this->getMockForAbstractClass(AbstractTrailRepository::class), $filters, $this->createMock(LoggerInterface::class), [], 'List trails service']
174
        ];
175
    }
176
}
177