Issues (34)

Security Analysis    no request data  

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Notifications/NotifiableTest.php (9 issues)

1
<?php
2
3
namespace TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications;
4
5
6
use Spatie\ServerMonitor\Models\Check;
7
use Spatie\ServerMonitor\Models\Enums\CheckStatus;
8
use Spatie\ServerMonitor\Models\Host;
9
use TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded;
10
use TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TestCase;
11
use Spatie\ServerMonitor\Events\Event;
12
13
class NotifiableTest extends TestCase
14
{
15
16
    /**
17
     * @var \TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifiable
18
     */
19
    private $notifiable;
20
21
    public function setUp() {
22
        parent::setUp();
23
        $this->notifiable = new Notifiable();
24
25
        $checks = ['diskspace'];
26
27
        $host = Host::create([
28
            'name' => 'test',
29
            'port' => 22,
30
        ]);
31
32
        $host->checks()->saveMany(collect($checks)->map(function (string $checkName) {
33
            return new Check([
34
                'type' => $checkName,
35
                'status' => CheckStatus::NOT_YET_CHECKED,
36
            ]);
37
        }));
38
39
        $event = new \Spatie\ServerMonitor\Events\CheckSucceeded($host->checks()->first());
40
        $this->notifiable->setEvent($event);
41
    }
42
43
    /** @test */
44
    function route_notification_for_mail() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
       $mail = $this->notifiable->routeNotificationForMail();
46
       $this->assertSame('[email protected]', $mail[0]);
47
    }
48
49
    /** @test */
50 View Code Duplication
    function route_notification_for_mail_custom() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
51
        /* @var $host Host */
52
        $host = $this->notifiable->getEvent()->check->host()->first();
53
        $notifications =  [
54
            'TheCodingMachine\ServerMonitorPluginNotificationByHost\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
55
                [
56
                    'channels' => ['mail']
57
                ],
58
            'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]]
59
        ];
60
61
        $host->setCustomProperty('notifications', $notifications);
62
63
        $host->save();
64
65
        $mail = $this->notifiable->routeNotificationForMail();
66
        $this->assertSame('[email protected]', $mail[0]);
67
    }
68
69
    /** @test */
70 View Code Duplication
    function route_notification_no_custom_data() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
71
        /* @var $host Host */
72
        $host = $this->notifiable->getEvent()->check->host()->first();
73
        $notifications =  [
74
            'TheCodingMachine\ServerMonitorPluginNotificationByHost\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckFailed' =>
75
                [
76
                    'channels' => ['slack']
77
                ],
78
            'configuration' => ['slack' => [ 'webhook' => ['urlSlack'] ]]
79
        ];
80
81
        $host->setCustomProperty('notifications', $notifications);
82
83
        $host->save();
84
85
        $mail = $this->notifiable->routeNotificationForMail();
86
        $this->assertSame('[email protected]', $mail[0]);
87
    }
88
89
    /** @test */
90
    function route_notification_for_mail_custom_array() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
91
        /* @var $host Host */
92
        $host = $this->notifiable->getEvent()->check->host()->first();
93
        $notifications =  [
94
            'TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
95
                [
96
                    'channels' => ['mail']
97
                ],
98
            'configuration' => ['mail' => [ 'to' => ['[email protected]'], 'other' => 'otherData']]
99
        ];
100
101
        $host->setCustomProperty('notifications', $notifications);
102
103
        $host->save();
104
105
        $mail = $this->notifiable->routeNotificationForMail();
106
        $this->assertSame('[email protected]', $mail['to'][0]);
107
        $this->assertSame('otherData', $mail['other']);
108
    }
109
110
    /** @test */
111
    function route_notification_for_slack() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
112
        /* @var $host Host */
113
        $slack = $this->notifiable->routeNotificationForSlack();
114
        $this->assertSame('test', $slack);
115
    }
116
117
    /** @test */
118 View Code Duplication
    function route_notification_for_slack_custom() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
119
        /* @var $host Host */
120
        $host = $this->notifiable->getEvent()->check->host()->first();
121
        $notifications =  [
122
            'TheCodingMachine\ServerMonitorPluginNotificationByHost\Test\TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' =>
123
                [
124
                    'channels' => ['slack']
125
                ],
126
            'configuration' => ['slack' => [ 'webhook_url' => 'urlSlack' ]]
127
        ];
128
129
        $host->setCustomProperty('notifications', $notifications);
130
131
        $host->save();
132
133
        $slack = $this->notifiable->routeNotificationForSlack();
134
        $this->assertSame('urlSlack', $slack);
135
    }
136
}
137