Added DNS validator

This commit is contained in:
Eldad Fux
2020-02-21 00:15:53 +02:00
parent d1e57b23aa
commit 0fc51eba1e
4 changed files with 97 additions and 8 deletions
+1
View File
@@ -15,6 +15,7 @@
"Auth\\": "src/Auth",
"Database\\": "src/Database",
"Event\\": "src/Event",
"Network\\": "src/Network",
"OpenSSL\\": "src/OpenSSL",
"Resize\\": "src/Resize",
"Storage\\": "src/Storage",
Generated
+8 -8
View File
@@ -1935,12 +1935,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "edea3e869367921987704325b997a80cdaea6d66"
"reference": "5463f8d32cf0f31f3d8e6230eb80170a2602b55a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/edea3e869367921987704325b997a80cdaea6d66",
"reference": "edea3e869367921987704325b997a80cdaea6d66",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/5463f8d32cf0f31f3d8e6230eb80170a2602b55a",
"reference": "5463f8d32cf0f31f3d8e6230eb80170a2602b55a",
"shasum": ""
},
"require": {
@@ -1980,7 +1980,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2020-02-12T20:05:04+00:00"
"time": "2020-02-20T20:42:36+00:00"
},
{
"name": "phpdocumentor/type-resolver",
@@ -1988,12 +1988,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "70d7abb1fdad964379676d629923de0dd1918f4f"
"reference": "7462d5f123dfc080dfdf26897032a6513644fc95"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/70d7abb1fdad964379676d629923de0dd1918f4f",
"reference": "70d7abb1fdad964379676d629923de0dd1918f4f",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95",
"reference": "7462d5f123dfc080dfdf26897032a6513644fc95",
"shasum": ""
},
"require": {
@@ -2026,7 +2026,7 @@
}
],
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"time": "2020-02-14T12:50:24+00:00"
"time": "2020-02-18T18:59:58+00:00"
},
{
"name": "phpspec/prophecy",
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Network\Validators;
use Utopia\Validator;
class CNAME extends Validator
{
/**
* @var int
*/
protected $target;
/**
* @param string $target
*/
public function __construct($target)
{
$this->target = $target;
}
public function getDescription()
{
return 'Inavlid CNAME record';
}
/**
* Check if CNAME record target value matches selected target
*
* @param string $domain
*
* @return bool
*/
public function isValid($domain)
{
try {
$records = dns_get_record($domain, DNS_CNAME);
} catch (\Throwable $th) {
return false;
}
if(!$records || !is_array($records)) {
return false;
}
foreach($records as $record) {
if(isset($record['target']) && $record['target'] === $this->target) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,34 @@
<?php
namespace Appwrite\Tests;
use Network\Validators\CNAME;
use PHPUnit\Framework\TestCase;
class CNAMETest extends TestCase
{
/**
* @var CNAME
*/
protected $object = null;
public function setUp()
{
$this->object = new CNAME('new.appwrite.io');
}
public function tearDown()
{
}
public function testValues()
{
$this->assertEquals($this->object->isValid(''), false);
$this->assertEquals($this->object->isValid(null), false);
$this->assertEquals($this->object->isValid(false), false);
$this->assertEquals($this->object->isValid('cert1.tests.appwrite.io'), true);
$this->assertEquals($this->object->isValid('cert2.tests.appwrite.io'), true);
$this->assertEquals($this->object->isValid('cert1.tests.appwrite.com'), false);
$this->assertEquals($this->object->isValid('cert1.tests.appwrite.com'), false);
}
}