parent
ebe3d05bb5
commit
bce2412b70
|
@ -6,7 +6,6 @@ use Utopia\Exception;
|
|||
use Utopia\Response;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\Domain as DomainValidator;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
use Utopia\Validator\URL;
|
||||
|
@ -19,6 +18,7 @@ use Appwrite\Database\Document;
|
|||
use Appwrite\Database\Validator\UID;
|
||||
use Appwrite\OpenSSL\OpenSSL;
|
||||
use Appwrite\Network\Validator\CNAME;
|
||||
use Appwrite\Network\Validator\Domain as DomainValidator;
|
||||
use Cron\CronExpression;
|
||||
|
||||
$scopes = include __DIR__.'/../../../app/config/scopes.php';
|
||||
|
|
|
@ -361,7 +361,7 @@ $customDomainsTarget = $this->getParam('customDomainsTarget', false);
|
|||
<input type="hidden" name="projectId" data-ls-bind="{{router.params.project}}" />
|
||||
|
||||
<label for="name">Domain Name</label>
|
||||
<input type="text" class="full-width" id="domain" name="domain" placeholder="appwrite.example.com" required autocomplete="off" title="Enter a valid domain name" pattern="^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$" />
|
||||
<input type="text" class="full-width" id="domain" name="domain" placeholder="appwrite.example.com" required autocomplete="off" title="Enter a valid domain name" pattern="^^([a-zA-Z0-9][a-zA-Z0-9-_]*\.)*[a-zA-Z0-9]*[a-zA-Z0-9-_]*[[a-zA-Z0-9]+$" />
|
||||
|
||||
<hr />
|
||||
|
||||
|
|
54
src/Appwrite/Network/Validator/Domain.php
Normal file
54
src/Appwrite/Network/Validator/Domain.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Network\Validator;
|
||||
|
||||
use Utopia\Validator;
|
||||
|
||||
/**
|
||||
* Domain
|
||||
*
|
||||
* Validate that an variable is a valid domain address
|
||||
*
|
||||
* @package Utopia\Validator
|
||||
*/
|
||||
class Domain extends Validator
|
||||
{
|
||||
/**
|
||||
* Get Description
|
||||
*
|
||||
* Returns validator description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return 'Value must be a valid domain';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is valid
|
||||
*
|
||||
* Validation will pass when $value is valid domain.
|
||||
*
|
||||
* Validates domain names against RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181, and RFC 1123.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if(empty($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (\filter_var($value, FILTER_VALIDATE_DOMAIN) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
46
tests/unit/Network/Validators/DomianTest.php
Normal file
46
tests/unit/Network/Validators/DomianTest.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Appwrite\Network\Validator\Domain;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DomainTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Domain
|
||||
*/
|
||||
protected $domain = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->domain = new Domain();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->domain = null;
|
||||
}
|
||||
|
||||
public function testIsValid()
|
||||
{
|
||||
// Assertions
|
||||
$this->assertEquals(true, $this->domain->isValid('example.com'));
|
||||
$this->assertEquals(true, $this->domain->isValid('subdomain.example.com'));
|
||||
$this->assertEquals(true, $this->domain->isValid('subdomain.example-app.com'));
|
||||
$this->assertEquals(true, $this->domain->isValid('subdomain.example_app.com'));
|
||||
$this->assertEquals(true, $this->domain->isValid('subdomain-new.example.com'));
|
||||
$this->assertEquals(true, $this->domain->isValid('subdomain_new.example.com'));
|
||||
$this->assertEquals(true, $this->domain->isValid('localhost'));
|
||||
$this->assertEquals(true, $this->domain->isValid('appwrite.io'));
|
||||
$this->assertEquals(true, $this->domain->isValid('appwrite.org'));
|
||||
$this->assertEquals(true, $this->domain->isValid('appwrite.org'));
|
||||
$this->assertEquals(false, $this->domain->isValid(false));
|
||||
$this->assertEquals(false, $this->domain->isValid('.'));
|
||||
$this->assertEquals(false, $this->domain->isValid('..'));
|
||||
$this->assertEquals(false, $this->domain->isValid(''));
|
||||
$this->assertEquals(false, $this->domain->isValid(['string', 'string']));
|
||||
$this->assertEquals(false, $this->domain->isValid(1));
|
||||
$this->assertEquals(false, $this->domain->isValid(1.2));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue