Issues (158)

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/Resource/OrdersTest.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
namespace Moip\Tests\Resource;
4
5
use Moip\Resource\Orders;
6
use Moip\Tests\TestCase;
7
8
class OrdersTest extends TestCase
9
{
10
    /**
11
     * Send http request.
12
     *
13
     * @param \Moip\Resource\Orders $order
14
     * @param string                $body
15
     *
16
     * @return \Moip\Resource\Orders
17
     */
18
    private function executeOrder(Orders $order = null, $body = null)
19
    {
20
        if (empty($body)) {
21
            $body = $this->body_order;
22
        }
23
        if (empty($order)) {
24
            $order = $this->createOrder();
25
        }
26
        $this->mockHttpSession($body);
27
28
        return $order->create();
0 ignored issues
show
Bug Compatibility introduced by
The expression $order->create(); of type Moip\Resource\Orders|stdClass adds the type stdClass to the return on line 28 which is incompatible with the return type documented by Moip\Tests\Resource\OrdersTest::executeOrder of type Moip\Resource\Orders.
Loading history...
29
    }
30
31
    /**
32
     * @const string
33
     */
34
    public function testAssertConstPath()
35
    {
36
        $this->assertEquals('orders', Orders::PATH);
37
    }
38
39
    /**
40
     * Tests if the primary receiver constant has the correct value.
41
     *
42
     * @const string
43
     */
44
    public function testAssertConstReceiverTypePrimary()
45
    {
46
        $this->assertEquals('PRIMARY', Orders::RECEIVER_TYPE_PRIMARY);
47
    }
48
49
    /**
50
     * Tests if the secondary receiver constant has the correct value.
51
     *
52
     * @const string
53
     */
54
    public function testAssertConstReceiverTypeSecpndary()
55
    {
56
        $this->assertEquals('SECONDARY', Orders::RECEIVER_TYPE_SECONDARY);
57
    }
58
59
    /**
60
     * Tests the currency in the order creation response.
61
     *
62
     * @const string
63
     */
64
    public function testAssertConstAmountCurrency()
65
    {
66
        $this->assertEquals('BRL', Orders::AMOUNT_CURRENCY);
67
    }
68
69
    /**
70
     * MoipTest creating an order.
71
     */
72
    public function testCreateOrder()
73
    {
74
        $order_created = $this->executeOrder();
75
76
        $this->assertEquals($this->last_ord_id, $order_created->getOwnId());
77
        $this->assertEquals('CREATED', $order_created->getStatus());
78
        $this->assertEquals(new \DateTime('2016-02-19T12:24:55.849-02'), $order_created->getCreatedAt());
79
        $this->assertEquals(new \DateTime('2016-02-19T12:24:55.849-02'), $order_created->getUpdatedAt());
80
    }
81
82
    /**
83
     * Tests if created items price are correct.
84
     */
85
    public function testItems()
86
    {
87
        $order_created = $this->executeOrder();
88
        $itens = $order_created->getItemIterator()->getArrayCopy();
89
        $this->assertEquals(100000, $itens[0]->price);
90
        $this->assertEquals(990, $itens[1]->price);
91
    }
92
93
    /**
94
     * Test if created order shipping address is correct.
95
     */
96
    public function testShippingAddress()
97
    {
98
        $order_created = $this->executeOrder();
99
100
        $this->assertEquals('01234000', $order_created->getCustomer()->getShippingAddress()->{'zipCode'});
101
        $this->assertEquals('Avenida Faria Lima', $order_created->getCustomer()->getShippingAddress()->{'street'});
102
        $this->assertEquals('2927', $order_created->getCustomer()->getShippingAddress()->{'streetNumber'});
103
        $this->assertEquals('8', $order_created->getCustomer()->getShippingAddress()->{'complement'});
104
        $this->assertEquals('Sao Paulo', $order_created->getCustomer()->getShippingAddress()->{'city'});
105
        $this->assertEquals('Itaim', $order_created->getCustomer()->getShippingAddress()->{'district'});
106
        $this->assertEquals('SP', $order_created->getCustomer()->getShippingAddress()->{'state'});
107
        $this->assertEquals('BRA', $order_created->getCustomer()->getShippingAddress()->{'country'});
108
    }
109
110
    /**
111
     *MoipTest if the total is correct.
112
     */
113
    public function testTotal()
114
    {
115
        $order = $this->executeOrder();
116
117
        $total = $order->getSubtotalItems() + $order->getSubtotalShipping() + $order->getSubtotalAddition() - $order->getSubtotalDiscount();
118
        $this->assertEquals($total, $order->getAmountTotal());
119
    }
120
121
    /**
122
     * MoipTest if the total is equal to the expected total.
123
     */
124
    public function testTotalConstant()
125
    {
126
        $order = $this->executeOrder();
127
        $expected = (100000 + 2 * 990 + 1490) - 1000;
128
        $total_calculated = $order->getSubtotalItems() + $order->getSubtotalShipping() + $order->getSubtotalAddition() - $order->getSubtotalDiscount();
129
130
        $this->assertEquals($expected, $total_calculated);
131
        $this->assertEquals($expected, $order->getAmountTotal());
132
    }
133
134
    /**
135
     * MoipTest if order is created with installment preferences.
136
     */
137
    public function testCreateOrderWithInstallmentPreferences()
138
    {
139
        $quantity = [1, 6];
140
        $discount = 0;
141
        $additional = 100;
142
        $order = $this->createOrder()->addInstallmentCheckoutPreferences($quantity, $discount, $additional);
143
        $returned_order = $this->executeOrder($order);
144
        $this->assertNotEmpty($returned_order->getId());
145
        $this->assertEquals([1, 6], $returned_order->getCheckoutPreferences()->installments[0]->quantity);
146
    }
147
148
    public function testCreateOrderAddingReceiverNoAmount()
149
    {
150
        $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY');
151
        $receivers = $order->getReceiverIterator();
152
        $this->assertEquals('MPA-7ED9D2D0BC81', $receivers[0]->moipAccount->id);
153
    }
154
155
    public function testCreateOrderAddingReceiverAmountFixed()
156
    {
157
        $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', 30000);
158
        $receivers = $order->getReceiverIterator();
159
        $this->assertEquals(30000, $receivers[0]->amount->fixed);
160
    }
161
162
    public function testCreateOrderAddingReceiverAmountPercentual()
163
    {
164
        $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', null, 40);
165
        $receivers = $order->getReceiverIterator();
166
        $this->assertEquals(40, $receivers[0]->amount->percentual);
167
    }
168
169
    public function testCreateOrderAddingReceiverFeePayor()
170
    {
171
        $order = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', null, 40, true);
172
        $receivers = $order->getReceiverIterator();
173
        $this->assertEquals(40, $receivers[0]->amount->percentual);
174
        $this->assertTrue($receivers[0]->feePayor);
175
        $order2 = $this->createOrder()->addReceiver('MPA-7ED9D2D0BC81', 'PRIMARY', 30000, null, true);
176
        $receivers2 = $order2->getReceiverIterator();
177
        $this->assertEquals(30000, $receivers2[0]->amount->fixed);
178
        $this->assertTrue($receivers2[0]->feePayor);
179
    }
180
}
181