Issues (13)

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.

tests/Controller/RestApiControllerTest.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
2
3
/*
4
 * This file is part of the Moo\FlashCard package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Moo\FlashCard\Tests\Controller;
13
14
use Illuminate\Foundation\Testing\TestResponse;
15
use Moo\FlashCard\Entity\Card;
16
use Moo\FlashCard\Entity\Category;
17
use Moo\FlashCard\Tests\BaseTestCase;
18
19
/**
20
 * RestApiControllerTest contains test cases for the REST API controller.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 */
24
class RestApiControllerTest extends BaseTestCase
25
{
26
    public function setUp()
27
    {
28
        parent::setUp();
29
30
        // Create categories
31
        $category1 = $this->category();
32
        $category2 = $this->category([
33
            'title' => 'Category 2',
34
        ]);
35
        $category3 = $this->category([
36
            'title' => 'Category 3',
37
        ]);
38
        $this->category([
39
            'title' => 'Category 4',
40
        ]);
41
42
        // Create cards
43 View Code Duplication
        for ($i = 1; $i < 5; $i++) {
0 ignored issues
show
This code seems to be duplicated across 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...
44
            $this->card([
45
                'title'       => 'Card ' . $i,
46
                'category_id' => $category1->id,
47
            ]);
48
        }
49
50 View Code Duplication
        for ($i = 5; $i < 8; $i++) {
0 ignored issues
show
This code seems to be duplicated across 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
            $this->card([
52
                'title'       => 'Card ' . $i,
53
                'category_id' => $category2->id,
54
            ]);
55
        }
56
57
        $this->card([
58
            'title'       => 'Card 9',
59
            'category_id' => $category3->id,
60
        ]);
61
    }
62
63
    public function testViewACardDetails()
64
    {
65
        // Get card by slug
66
        $card = Card::where('slug', 'card-1')->first();
67
68
        /** @var TestResponse $response */
69
        // Request to get all cards
70
        $response = $this->getJson('/api/cards');
71
72
        // Assert that the above card exists in the response
73
        $response->assertStatus(200);
74
        $response->assertJsonFragment(['title' => $card->title]);
75
        $response->assertJsonFragment(['category_id' => (string) $card->category_id]);
76
    }
77
78
    public function testGetLimitCard()
79
    {
80
        // Count of cards to return
81
        $count = 1;
82
83
        /** @var TestResponse $response */
84
        // Request to get limit cards
85
        $response = $this->getJson('/api/cards?limit=' . $count);
86
87
        // Assert the response contains same amount of records based on count above
88
        $response->assertJsonFragment(['current_page' => 1]);
89
        $response->assertJsonCount($count, 'data');
90
        $response->assertStatus(200);
91
    }
92
93 View Code Duplication
    public function testSearchValidCards()
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...
94
    {
95
        // Search query
96
        $keyword = 'card 1';
97
98
        /** @var TestResponse $response */
99
        // Request to get cards by a search query and include category details
100
        $response = $this->getJson(sprintf('/api/cards?filter[search]=%s&include=category', $keyword));
101
102
        // Assert that records found and category included
103
        $response->assertJsonFragment(['category']);
104
        $this->assertEquals('Category 1', $response->json('0.category.title'));
105
        $response->assertJsonFragment(['slug' => 'card-1']);
106
        $response->assertJsonCount(1);
107
        $response->assertStatus(200);
108
    }
109
110
    public function testSearchInvalidCards()
111
    {
112
        // Search query
113
        $keyword = 'ca 1';
114
115
        /** @var TestResponse $response */
116
        // Request to get cards by search query
117
        $response = $this->getJson(sprintf('/api/cards?filter[search]=%s', $keyword));
118
119
        // Assert that nothing found based on above search query
120
        $response->assertJsonCount(0);
121
        $response->assertStatus(200);
122
    }
123
124 View Code Duplication
    public function testSearchValidCardsWithoutCategory()
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...
125
    {
126
        // Search query
127
        $keyword = 'card 1';
128
129
        /** @var TestResponse $response */
130
        // Request to get cards by a search query and does not include category details
131
        $response = $this->getJson(sprintf('/api/cards?filter[search]=%s', $keyword));
132
133
        // Assert that records does not include category details
134
        $response->assertJsonMissing(['category']);
135
        $this->assertNull($response->json('0.category.title'));
136
        $response->assertJsonFragment(['slug' => 'card-1']);
137
        $response->assertJsonCount(1);
138
        $response->assertStatus(200);
139
    }
140
141
    public function testFilterCardsByCategory()
142
    {
143
        // Get a category
144
        $category = Category::all()->first();
145
146
        /** @var TestResponse $response */
147
        // Request to get cards filtered by a category
148
        $response = $this->getJson(sprintf('/api/cards?filter[category_id]=%s&include=category', $category->id));
149
150
        // Assert that the records are belongs to the category above
151
        $cards = $response->json();
152
        foreach ($cards as $card) {
153
            $this->assertArrayHasKey('category', $card);
154
            $this->assertEquals($category->id, $card['category']['id']);
155
        }
156
        $this->assertTrue(count($cards) > 0);
157
        $response->assertStatus(200);
158
    }
159
}
160