Issues (10)

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/models/ReservationTest.php (4 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 namespace VojtaSvoboda\Reservations\Tests\Models;
2
3
use App;
4
use Carbon\Carbon;
5
use Config;
6
use Illuminate\Support\Facades\Validator;
7
use PluginTestCase;
8
use October\Rain\Database\ModelException;
9
use VojtaSvoboda\Reservations\Facades\ReservationsFacade;
10
use VojtaSvoboda\Reservations\Models\Reservation;
11
use VojtaSvoboda\Reservations\Models\Status;
12
use VojtaSvoboda\Reservations\Validators\ReservationsValidators;
13
14
class ReservationTest extends PluginTestCase
15
{
16
    private $defaultStatus;
17
18 View Code Duplication
    public function setUp()
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...
19
    {
20
        parent::setUp();
21
22
        $this->app->bind('vojtasvoboda.reservations.facade', ReservationsFacade::class);
23
24
        // registrate reservations validators
25
        Validator::resolver(function($translator, $data, $rules, $messages, $customAttributes) {
26
            return new ReservationsValidators($translator, $data, $rules, $messages, $customAttributes);
27
        });
28
    }
29
30
    /**
31
     * Get tested model.
32
     *
33
     * @return Reservation
34
     */
35
    public function getModel()
36
    {
37
        return App::make(Reservation::class);
38
    }
39
40
    public function testBeforeCreate()
41
    {
42
        $model = $this->getModel();
43
44
        // create reservation
45
        $reservation = $model->create($this->getTestingReservationData());
46
        $this->assertNotEmpty($reservation->hash, 'Reservation hash is empty.');
47
        $this->assertNotEmpty($reservation->number, 'Number hash is empty.');
48
        $this->assertSame(App::getLocale(), $reservation->locale, 'Reservation locale should be same as app locale.');
49
        $this->assertNotEmpty($reservation->ip, 'IP address is empty.');
50
        $this->assertNotEmpty($reservation->user_agent, 'User Agent is empty.');
51
        $this->assertSame($this->getDefaultStatus(), $reservation->status, 'Reservation status should be ' . $this->getDefaultStatus()->name . '.');
52
    }
53
54
    public function testIsDateAvailableFailing()
55
    {
56
        $model = $this->getModel();
57
58
        // create reservation
59
        $model->create($this->getTestingReservationData());
60
61
        // try to do second reservation with same date and time
62
        $this->setExpectedException(ModelException::class, 'vojtasvoboda.reservations::lang.errors.already_booked');
63
        $model->create($this->getTestingReservationData());
64
    }
65
66
    public function testIsDateAvailablePassed()
67
    {
68
        $model = $this->getModel();
69
70
        // create reservation
71
        $model->create($this->getTestingReservationData());
72
73
        // try to do second reservation with same date and time after 2 hours
74
        $data = $this->getTestingReservationData();
75
        $nextMonday = Carbon::parse('next monday')->format('Y-m-d 13:00');
76
        $data['date'] = Carbon::createFromFormat('Y-m-d H:i', $nextMonday);
77
        $model->create($data);
78
    }
79
80
    public function testIsDateAvailableForCancelled()
81
    {
82
        $model = $this->getModel();
83
84
        // create reservation
85
        $reservation = $model->create($this->getTestingReservationData());
86
87
        // cancel status
88
        $cancelledStatuses = Config::get('vojtasvoboda.reservations::config.statuses.cancelled', ['cancelled']);
89
        $statusIdent = empty($cancelledStatuses) ? 'cancelled' : $cancelledStatuses[0];
90
91
        // cancell reservation
92
        $reservation->status = Status::where('ident', $statusIdent)->first();
93
        $reservation->save();
94
95
        // try to do second reservation with same date and time
96
        $data = $this->getTestingReservationData();
97
        $model->create($data);
98
    }
99
100
    public function testIsCancelled()
101
    {
102
        $model = $this->getModel();
103
104
        $reservation = $model->create($this->getTestingReservationData());
105
        $this->assertFalse($reservation->isCancelled());
106
        $this->assertTrue($reservation->isCancelled('cancelled'));
107
    }
108
109
    public function testGetHash()
110
    {
111
        $model = $this->getModel();
112
113
        $firstHash = $model->getUniqueHash();
114
        $secondHash = $model->getUniqueHash();
115
116
        $this->assertNotEquals($firstHash, $secondHash);
117
    }
118
119
    public function testGetEmptyHash()
120
    {
121
        $model = $this->getModel();
122
        Config::set('vojtasvoboda.reservations::config.hash', 0);
123
        $this->assertNull($model->getUniqueHash());
124
    }
125
126
    public function testGetNumber()
127
    {
128
        $model = $this->getModel();
129
130
        $firstNumber = $model->getUniqueNumber();
131
        $secondNumber = $model->getUniqueNumber();
132
133
        $this->assertNotEquals($firstNumber, $secondNumber);
134
    }
135
136
    public function testGetEmptyNumber()
137
    {
138
        $model = $this->getModel();
139
        Config::set('vojtasvoboda.reservations::config.number.min', 0);
140
        $this->assertNull($model->getUniqueNumber());
141
    }
142
143 View Code Duplication
    public function testScopeNotCancelled()
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...
144
    {
145
        $model = $this->getModel();
146
147
        // create reservation
148
        $reservation = $model->create($this->getTestingReservationData());
149
        $reservations = $model->notCancelled()->get();
150
        $this->assertNotEmpty($reservations);
151
152
        // change reservation to cancelled
153
        $reservation->status = Status::where('ident', 'cancelled')->first();
154
        $reservation->save();
155
        $reservations = $model->notCancelled()->get();
156
        $this->assertEmpty($reservations);
157
    }
158
159 View Code Duplication
    public function testScopeCurrentDate()
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...
160
    {
161
        $model = $this->getModel();
162
163
        // create reservation
164
        $reservation = $model->create($this->getTestingReservationData());
165
        $reservations = $model->currentDate()->get();
166
        $this->assertNotEmpty($reservations);
167
168
        // change reservation to the past
169
        $reservation->date = Carbon::parse('-1 month');
170
        $reservation->save();
171
        $reservations = $model->currentDate()->get();
172
        $this->assertEmpty($reservations);
173
    }
174
175
    /**
176
     * Get testing reservation data.
177
     *
178
     * @return array
179
     */
180 View Code Duplication
    private function getTestingReservationData()
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...
181
    {
182
        $nextMonday = Carbon::parse('next monday')->format('Y-m-d 11:00');
183
184
        return [
185
            'date' => Carbon::createFromFormat('Y-m-d H:i', $nextMonday),
186
            'email' => '[email protected]',
187
            'phone' => '777111222',
188
            'street' => 'ABCDE',
189
            'name' => 'Vojta Svoboda',
190
            'message' => 'Hello.',
191
            'status' => $this->getDefaultStatus(),
192
        ];
193
    }
194
195
    /**
196
     * Get default status object.
197
     *
198
     * @return mixed
199
     */
200
    private function getDefaultStatus()
201
    {
202
        if ($this->defaultStatus === null) {
203
            $statusIdent = 'received';
204
            $this->defaultStatus = Status::where('ident', $statusIdent)->first();
205
        }
206
207
        return $this->defaultStatus;
208
    }
209
}
210