Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CentralNic
Badcow-DNS
Commits
546b840a
Unverified
Commit
546b840a
authored
Feb 18, 2019
by
Sam Williams
Committed by
GitHub
Feb 18, 2019
Browse files
Merge pull request #26 from skirmis/feature/add-caa-type
Rdata: add new CAA record type and unit test
parents
7e50f585
d0a36a7f
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/Rdata/CAA.php
0 → 100644
View file @
546b840a
<?php
/*
* This file is part of Badcow DNS Library.
*
* (c) Samuel Williams <sam@badcow.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Badcow\DNS\Rdata
;
/**
* Class CaaRdata.
*
* CAA is defined in RFC 6844
*
* @see https://tools.ietf.org/html/rfc6844
*
* @author Samuel Williams <sam@badcow.co>
*/
class
CAA
extends
CNAME
{
const
TYPE
=
'CAA'
;
const
MAX_FLAG
=
255
;
const
ALLOWED_TAGS
=
[
'issue'
,
'issuewild'
,
'iodef'
];
/**
* It is currently used to represent the critical flag
*
* @var int
*/
private
$flag
;
/**
* An ASCII string that represents the identifier of the property represented by the record.
* The RFC currently defines 3 available tags:
* - issue: explicity authorizes a single certificate authority to issue a certificate (any type) for the hostname.
* - issuewild: explicity authorizes a single certificate authority to issue a wildcard certificate (and only wildcard) for the hostname.
* - iodef: specifies a URL to which a certificate authority may report policy violations.
*
* @var string
*/
private
$tag
;
/**
* @return int
*/
public
function
getFlag
():
?int
{
return
$this
->
flag
;
}
/**
* @param int $flag
*
* @throws \InvalidArgumentException
*/
public
function
setFlag
(
int
$flag
):
void
{
if
(
$flag
<
0
||
$flag
>
static
::
MAX_FLAG
)
{
throw
new
\
InvalidArgumentException
(
'Flag must be an unsigned integer on the range [0-255]'
);
}
$this
->
flag
=
$flag
;
}
/**
* @return int
*/
public
function
getTag
():
?string
{
return
$this
->
tag
;
}
/**
* @param int $tag
*
* @throws \InvalidArgumentException
*/
public
function
setTag
(
string
$tag
):
void
{
if
(
!
in_array
(
$tag
,
static
::
ALLOWED_TAGS
))
{
throw
new
\
InvalidArgumentException
(
'Tag can be one of this type '
.
implode
(
' '
,
static
::
ALLOWED_TAGS
));
}
$this
->
tag
=
$tag
;
}
/**
* {@inheritdoc}
*/
public
function
output
():
string
{
return
sprintf
(
'%s %s "%s"'
,
$this
->
flag
,
$this
->
tag
,
$this
->
target
);
}
}
lib/Rdata/Factory.php
View file @
546b840a
...
...
@@ -352,4 +352,21 @@ class Factory
return
$rdata
;
}
/**
* @param integer $flag
* @param string $tag
* @param string $target
*
* @return CAA
*/
public
static
function
Caa
(
$flag
,
$tag
,
$target
)
{
$rdata
=
new
CAA
();
$rdata
->
setFlag
(
$flag
);
$rdata
->
setTag
(
$tag
);
$rdata
->
setTarget
(
$target
);
return
$rdata
;
}
}
lib/Tests/Rdata/CaaRdataTest.php
0 → 100644
View file @
546b840a
<?php
/*
* This file is part of Badcow DNS Library.
*
* (c) Samuel Williams <sam@badcow.co>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Badcow\DNS\Tests\Rdata
;
use
Badcow\DNS\Rdata\CAA
;
use
Badcow\DNS\Rdata\Factory
;
class
CaaRdataTest
extends
\
PHPUnit\Framework\TestCase
{
public
function
testOutput
()
{
$caa
=
Factory
::
Caa
(
0
,
'issue'
,
'letsencrypt.org'
);
$expectation
=
'0 issue "letsencrypt.org"'
;
$this
->
assertEquals
(
$expectation
,
$caa
->
output
());
$this
->
assertEquals
(
0
,
$caa
->
getFlag
());
$this
->
assertEquals
(
'issue'
,
$caa
->
getTag
());
}
/**
* @expectedException \InvalidArgumentException
*/
public
function
testFlagException
()
{
$srv
=
new
CAA
();
$srv
->
setFlag
(
CAA
::
MAX_FLAG
+
1
);
}
/**
* @expectedException \InvalidArgumentException
*/
public
function
testTagException
()
{
$srv
=
new
CAA
();
$srv
->
setTag
(
'not_exist'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment