Issues (166)

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/Rdata/DhcidTest.php (2 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
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Tests\Rdata;
15
16
use Badcow\DNS\Rdata\DHCID;
17
use Badcow\DNS\Rdata\Factory;
18
use PHPUnit\Framework\TestCase;
19
20
class DhcidTest extends TestCase
21
{
22
    public function getDataProvider(): array
23
    {
24
        return [
25
            //[Text,                                             IDType, Identifier,                                  FQDN]
26
            ['AAIBY2/AuCccgoJbsaxcQc9TUapptP69lOjxfNuVAA2kjEA=', 2,      '00:01:00:06:41:2d:f1:66:01:02:03:04:05:06', 'chi6.example.com.'],
27
            ['AAEBOSD+XR3Os/0LozeXVqcNc7FwCfQdWL3b/NaiUDlW2No=', 1,      '01:07:08:09:0a:0b:0c',                      'chi.example.com.'],
28
            ['AAABxLmlskllE0MVjd57zHcWmEH3pCQ6VytcKD//7es/deY=', 0,      '01:02:03:04:05:06',                         'client.example.com.'],
29
        ];
30
    }
31
32
    public function testGetType(): void
33
    {
34
        $dhcid = new DHCID();
35
        $this->assertEquals('DHCID', $dhcid->getType());
36
    }
37
38
    public function testGetTypeCode(): void
39
    {
40
        $dhcid = new DHCID();
41
        $this->assertEquals(49, $dhcid->getTypeCode());
42
    }
43
44 View Code Duplication
    public function testSetGetHtype(): void
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...
45
    {
46
        $dhcid = new DHCID();
47
        $dhcid->setHtype(3);
48
        $this->assertEquals(3, $dhcid->getHtype());
49
50
        $this->expectException(\InvalidArgumentException::class);
51
        $this->expectExceptionMessage('HType must be an 8-bit integer.');
52
        $dhcid->setHtype(256);
53
    }
54
55 View Code Duplication
    public function testSetGetFqdn(): void
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...
56
    {
57
        $dhcid = new DHCID();
58
        $dhcid->setFqdn('abc.example.com.');
59
        $this->assertEquals('abc.example.com.', $dhcid->getFqdn());
60
61
        $this->expectException(\InvalidArgumentException::class);
62
        $this->expectExceptionMessage('"abc.example.com" is not a fully qualified domain name.');
63
        $dhcid->setFqdn('abc.example.com');
64
    }
65
66
    public function testSetIdentifierTypeThrowsExceptionIfTypeIsMoreThanSixteenBits(): void
67
    {
68
        $dhcid = new DHCID();
69
70
        $this->expectException(\InvalidArgumentException::class);
71
        $this->expectExceptionMessage('Identifier type must be a 16-bit integer.');
72
        $dhcid->setIdentifierType(65536);
73
    }
74
75
    public function testCalculateDigestThrowsExceptionIfIdentifierIsNotSet(): void
76
    {
77
        $dhcid = new DHCID();
78
        $dhcid->setFqdn('abc.example.com.');
79
80
        $this->expectException(\BadMethodCallException::class);
81
        $this->expectExceptionMessage('Identifier and Fully Qualified Domain Name (FQDN) must both be set on DHCID object before calling calculateDigest().');
82
        $dhcid->calculateDigest();
83
    }
84
85
    /**
86
     * @dataProvider getDataProvider
87
     */
88
    public function testToText(string $text, int $identifierType, string $identifier, string $fqdn): void
89
    {
90
        $dhcid = new DHCID();
91
        $dhcid->setIdentifier($identifierType, $identifier);
92
        $dhcid->setFqdn($fqdn);
93
94
        $this->assertEquals($identifier, $dhcid->getIdentifier());
95
        $this->assertEquals($text, $dhcid->toText());
96
    }
97
98
    /**
99
     * @dataProvider getDataProvider
100
     */
101
    public function testToFromWire(string $text, int $identifierType, string $identifier, string $fqdn): void
102
    {
103
        $expectation = new DHCID();
104
        $expectation->setIdentifier($identifierType, $identifier);
105
        $expectation->setFqdn($fqdn);
106
107
        $dhcid = new DHCID();
108
        $dhcid->fromWire($expectation->toWire());
109
110
        $this->assertEquals($expectation->getIdentifierType(), $dhcid->getIdentifierType());
111
        $this->assertEquals($expectation->getDigestType(), $dhcid->getDigestType());
112
        $this->assertEquals($expectation->getDigest(), $dhcid->getDigest());
113
        $this->assertEquals($expectation->toText(), $dhcid->toText());
114
        $this->assertEquals($text, $dhcid->toText());
115
    }
116
117
    /**
118
     * @dataProvider getDataProvider
119
     *
120
     * @throws \Exception
121
     */
122
    public function testFromText(string $text, int $identifierType, string $identifier, string $fqdn): void
123
    {
124
        $expectation = new DHCID();
125
        $expectation->setIdentifier($identifierType, $identifier);
126
        $expectation->setFqdn($fqdn);
127
        $expectation->calculateDigest();
128
129
        $dhcid = new DHCID();
130
        $dhcid->fromText($text);
131
132
        $this->assertEquals($expectation->getIdentifierType(), $dhcid->getIdentifierType());
133
        $this->assertEquals($expectation->getDigestType(), $dhcid->getDigestType());
134
        $this->assertEquals($expectation->getDigest(), $dhcid->getDigest());
135
        $this->assertEquals($expectation->toText(), $dhcid->toText());
136
137
        $dhcid = new DHCID();
138
        $this->expectException(\Exception::class);
139
        $this->expectExceptionMessageMatches('/Unable to base64 decode text ".*"\./');
140
        $dhcid->fromText($text.'%');
141
    }
142
143
    /**
144
     * @dataProvider getDataProvider
145
     */
146
    public function testFactory(string $text, int $identifierType, string $identifier, string $fqdn): void
147
    {
148
        $dhcid = Factory::DHCID(null, $identifierType, $identifier, $fqdn);
149
        $this->assertEquals($text, $dhcid->toText());
150
151
        $digest = $dhcid->getDigest();
152
        $_dhcid = Factory::DHCID($digest, $identifierType);
153
154
        $this->assertEquals($dhcid->toText(), $_dhcid->toText());
155
    }
156
157
    public function testFactoryThrowsExceptionIfIdAndFqdnAreNull(): void
158
    {
159
        $this->expectException(\InvalidArgumentException::class);
160
        $this->expectExceptionMessage('Identifier and FQDN cannot be null if digest is null.');
161
        Factory::DHCID(null, 2, null);
162
    }
163
}
164