Merge pull request #5004 from appwrite/feat-remove-validators
Replace Appwrite Validators with backported Utopia ones
This commit is contained in:
commit
54f4bef67a
20 changed files with 43 additions and 642 deletions
|
@ -10,8 +10,8 @@ use Appwrite\Event\Mail;
|
|||
use Appwrite\Event\Phone as EventPhone;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Appwrite\Network\Validator\Host;
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use Utopia\Validator\Host;
|
||||
use Utopia\Validator\URL;
|
||||
use Appwrite\OpenSSL\OpenSSL;
|
||||
use Appwrite\Template\Template;
|
||||
use Appwrite\URL\URL as URLParser;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use Utopia\Validator\URL;
|
||||
use Appwrite\URL\URL as URLParse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use chillerlan\QRCode\QRCode;
|
||||
|
|
|
@ -33,8 +33,8 @@ use Utopia\Database\Exception\Structure as StructureException;
|
|||
use Utopia\Locale\Locale;
|
||||
use Appwrite\Auth\Auth;
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Appwrite\Network\Validator\IP;
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use Utopia\Validator\IP;
|
||||
use Utopia\Validator\URL;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
use Appwrite\Utopia\Database\Validator\Query\Limit;
|
||||
use Appwrite\Utopia\Database\Validator\Query\Offset;
|
||||
|
|
|
@ -6,9 +6,9 @@ use Appwrite\Event\Certificate;
|
|||
use Appwrite\Event\Delete;
|
||||
use Appwrite\Event\Validator\Event;
|
||||
use Appwrite\Network\Validator\CNAME;
|
||||
use Appwrite\Network\Validator\Domain as DomainValidator;
|
||||
use Utopia\Validator\Domain as DomainValidator;
|
||||
use Appwrite\Network\Validator\Origin;
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use Utopia\Validator\URL;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
|
|
@ -7,7 +7,7 @@ use Appwrite\Event\Event;
|
|||
use Appwrite\Event\Mail;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Appwrite\Network\Validator\Host;
|
||||
use Utopia\Validator\Host;
|
||||
use Appwrite\Template\Template;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
use Appwrite\Utopia\Database\Validator\Queries;
|
||||
|
|
|
@ -4,7 +4,7 @@ global $utopia, $request, $response;
|
|||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Utopia\Database\Document;
|
||||
use Appwrite\Network\Validator\Host;
|
||||
use Utopia\Validator\Host;
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
|
|
@ -33,8 +33,8 @@ use Appwrite\Extend\PDO;
|
|||
use Appwrite\GraphQL\Promises\Adapter\Swoole;
|
||||
use Appwrite\GraphQL\Schema;
|
||||
use Appwrite\Network\Validator\Email;
|
||||
use Appwrite\Network\Validator\IP;
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use Utopia\Validator\IP;
|
||||
use Utopia\Validator\URL;
|
||||
use Appwrite\OpenSSL\OpenSSL;
|
||||
use Appwrite\Usage\Stats;
|
||||
use MaxMind\Db\Reader;
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
"utopia-php/config": "0.2.*",
|
||||
"utopia-php/database": "0.28.*",
|
||||
"utopia-php/domains": "1.1.*",
|
||||
"utopia-php/framework": "0.25.*",
|
||||
"utopia-php/framework": "0.26.*",
|
||||
"utopia-php/image": "0.5.*",
|
||||
"utopia-php/locale": "0.4.*",
|
||||
"utopia-php/logger": "0.3.*",
|
||||
|
|
44
composer.lock
generated
44
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "dbc502462e4afa550b1a1bc3898020b3",
|
||||
"content-hash": "8782e69514f4564a3dcb44455161eedc",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
|
@ -1946,16 +1946,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
"version": "0.25.1",
|
||||
"version": "0.26.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/framework.git",
|
||||
"reference": "2391b397135586b2100d39e338827bef8d2f4ad0"
|
||||
"reference": "e8da5576370366d3bf9c574ec855f8c96fe4f34e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/2391b397135586b2100d39e338827bef8d2f4ad0",
|
||||
"reference": "2391b397135586b2100d39e338827bef8d2f4ad0",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/e8da5576370366d3bf9c574ec855f8c96fe4f34e",
|
||||
"reference": "e8da5576370366d3bf9c574ec855f8c96fe4f34e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1984,9 +1984,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/framework/issues",
|
||||
"source": "https://github.com/utopia-php/framework/tree/0.25.1"
|
||||
"source": "https://github.com/utopia-php/framework/tree/0.26.0"
|
||||
},
|
||||
"time": "2022-11-23T18:22:23+00:00"
|
||||
"time": "2023-01-13T08:14:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/image",
|
||||
|
@ -2652,16 +2652,16 @@
|
|||
},
|
||||
{
|
||||
"name": "webonyx/graphql-php",
|
||||
"version": "v14.11.8",
|
||||
"version": "v14.11.9",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/webonyx/graphql-php.git",
|
||||
"reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3"
|
||||
"reference": "ff91c9f3cf241db702e30b2c42bcc0920e70ac70"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/04a48693acd785330eefd3b0e4fa67df8dfee7c3",
|
||||
"reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3",
|
||||
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/ff91c9f3cf241db702e30b2c42bcc0920e70ac70",
|
||||
"reference": "ff91c9f3cf241db702e30b2c42bcc0920e70ac70",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2706,7 +2706,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/webonyx/graphql-php/issues",
|
||||
"source": "https://github.com/webonyx/graphql-php/tree/v14.11.8"
|
||||
"source": "https://github.com/webonyx/graphql-php/tree/v14.11.9"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -2714,7 +2714,7 @@
|
|||
"type": "open_collective"
|
||||
}
|
||||
],
|
||||
"time": "2022-09-21T15:35:03+00:00"
|
||||
"time": "2023-01-06T12:12:50+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
@ -2771,30 +2771,30 @@
|
|||
},
|
||||
{
|
||||
"name": "doctrine/instantiator",
|
||||
"version": "1.4.1",
|
||||
"version": "1.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/instantiator.git",
|
||||
"reference": "10dcfce151b967d20fde1b34ae6640712c3891bc"
|
||||
"reference": "0a0fa9780f5d4e507415a065172d26a98d02047b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc",
|
||||
"reference": "10dcfce151b967d20fde1b34ae6640712c3891bc",
|
||||
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b",
|
||||
"reference": "0a0fa9780f5d4e507415a065172d26a98d02047b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^9",
|
||||
"doctrine/coding-standard": "^9 || ^11",
|
||||
"ext-pdo": "*",
|
||||
"ext-phar": "*",
|
||||
"phpbench/phpbench": "^0.16 || ^1",
|
||||
"phpstan/phpstan": "^1.4",
|
||||
"phpstan/phpstan-phpunit": "^1",
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||
"vimeo/psalm": "^4.22"
|
||||
"vimeo/psalm": "^4.30 || ^5.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -2821,7 +2821,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/doctrine/instantiator/issues",
|
||||
"source": "https://github.com/doctrine/instantiator/tree/1.4.1"
|
||||
"source": "https://github.com/doctrine/instantiator/tree/1.5.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -2837,7 +2837,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-03-03T08:28:38+00:00"
|
||||
"time": "2022-12-30T00:15:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
|
@ -5271,5 +5271,5 @@
|
|||
"platform-overrides": {
|
||||
"php": "8.0"
|
||||
},
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.1.0"
|
||||
}
|
||||
|
|
|
@ -228,18 +228,18 @@ class Mapper
|
|||
case 'Appwrite\Network\Validator\CNAME':
|
||||
case 'Appwrite\Task\Validator\Cron':
|
||||
case 'Appwrite\Utopia\Database\Validator\CustomId':
|
||||
case 'Appwrite\Network\Validator\Domain':
|
||||
case 'Utopia\Validator\Domain':
|
||||
case 'Appwrite\Network\Validator\Email':
|
||||
case 'Appwrite\Event\Validator\Event':
|
||||
case 'Utopia\Validator\HexColor':
|
||||
case 'Appwrite\Network\Validator\Host':
|
||||
case 'Appwrite\Network\Validator\IP':
|
||||
case 'Utopia\Validator\Host':
|
||||
case 'Utopia\Validator\IP':
|
||||
case 'Utopia\Database\Validator\Key':
|
||||
case 'Appwrite\Network\Validator\Origin':
|
||||
case 'Utopia\Validator\Origin':
|
||||
case 'Appwrite\Auth\Validator\Password':
|
||||
case 'Utopia\Validator\Text':
|
||||
case 'Utopia\Database\Validator\UID':
|
||||
case 'Appwrite\Network\Validator\URL':
|
||||
case 'Utopia\Validator\URL':
|
||||
case 'Utopia\Validator\WhiteList':
|
||||
default:
|
||||
$type = Type::string();
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
<?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(): string
|
||||
{
|
||||
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): bool
|
||||
{
|
||||
if (empty($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (\filter_var($value, FILTER_VALIDATE_DOMAIN) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is array
|
||||
*
|
||||
* Function will return true if object is array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* Returns validator type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Network\Validator;
|
||||
|
||||
use Utopia\Validator\Hostname;
|
||||
use Utopia\Validator;
|
||||
|
||||
/**
|
||||
* Host
|
||||
*
|
||||
* Validate that a host is allowed from given whitelisted hosts list
|
||||
*
|
||||
* @package Utopia\Validator
|
||||
*/
|
||||
class Host extends Validator
|
||||
{
|
||||
protected $whitelist = [];
|
||||
|
||||
/**
|
||||
* @param array $whitelist
|
||||
*/
|
||||
public function __construct(array $whitelist)
|
||||
{
|
||||
$this->whitelist = $whitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Description
|
||||
*
|
||||
* Returns validator description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'URL host must be one of: ' . \implode(', ', $this->whitelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is valid
|
||||
*
|
||||
* Validation will pass when $value starts with one of the given hosts
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value): bool
|
||||
{
|
||||
// Check if value is valid URL
|
||||
$urlValidator = new URL();
|
||||
|
||||
if (!$urlValidator->isValid($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hostname = \parse_url($value, PHP_URL_HOST);
|
||||
$hostnameValidator = new Hostname($this->whitelist);
|
||||
return $hostnameValidator->isValid($hostname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is array
|
||||
*
|
||||
* Function will return true if object is array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* Returns validator type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Network\Validator;
|
||||
|
||||
use Exception;
|
||||
use Utopia\Validator;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*
|
||||
* Validate that an variable is a valid IP address
|
||||
*
|
||||
* @package Utopia\Validator
|
||||
*/
|
||||
class IP extends Validator
|
||||
{
|
||||
public const ALL = 'all';
|
||||
public const V4 = 'ipv4';
|
||||
public const V6 = 'ipv6';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type = self::ALL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Set a the type of IP check.
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct(string $type = self::ALL)
|
||||
{
|
||||
if (!in_array($type, [self::ALL, self::V4, self::V6])) {
|
||||
throw new Exception('Unsupported IP type');
|
||||
}
|
||||
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Description
|
||||
*
|
||||
* Returns validator description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Value must be a valid IP address';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is valid
|
||||
*
|
||||
* Validation will pass when $value is valid IP address.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value): bool
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::ALL:
|
||||
if (\filter_var($value, FILTER_VALIDATE_IP)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::V4:
|
||||
if (\filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::V6:
|
||||
if (\filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is array
|
||||
*
|
||||
* Function will return true if object is array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* Returns validator type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Network\Validator;
|
||||
|
||||
use Utopia\Validator;
|
||||
|
||||
/**
|
||||
* URL
|
||||
*
|
||||
* Validate that an variable is a valid URL
|
||||
*
|
||||
* @package Appwrite\Network\Validator
|
||||
*/
|
||||
class URL extends Validator
|
||||
{
|
||||
protected array $allowedSchemes;
|
||||
|
||||
/**
|
||||
* @param array $allowedSchemes
|
||||
*/
|
||||
public function __construct(array $allowedSchemes = [])
|
||||
{
|
||||
$this->allowedSchemes = $allowedSchemes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Description
|
||||
*
|
||||
* Returns validator description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
if (!empty($this->allowedSchemes)) {
|
||||
return 'Value must be a valid URL with following schemes (' . \implode(', ', $this->allowedSchemes) . ')';
|
||||
}
|
||||
|
||||
return 'Value must be a valid URL';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is valid
|
||||
*
|
||||
* Validation will pass when $value is valid URL.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value): bool
|
||||
{
|
||||
$sanitizedURL = '';
|
||||
|
||||
foreach (str_split($value) as $character) {
|
||||
$sanitizedURL .= (ord($character) > 127) ? rawurlencode($character) : $character;
|
||||
}
|
||||
|
||||
if (\filter_var($sanitizedURL, FILTER_VALIDATE_URL) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($this->allowedSchemes) && !\in_array(\parse_url($sanitizedURL, PHP_URL_SCHEME), $this->allowedSchemes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is array
|
||||
*
|
||||
* Function will return true if object is array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* Returns validator type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
}
|
|
@ -311,7 +311,7 @@ class OpenAPI3 extends Format
|
|||
$node['schema']['format'] = 'email';
|
||||
$node['schema']['x-example'] = 'email@example.com';
|
||||
break;
|
||||
case 'Appwrite\Network\Validator\URL':
|
||||
case 'Utopia\Validator\URL':
|
||||
$node['schema']['type'] = $validator->getType();
|
||||
$node['schema']['format'] = 'url';
|
||||
$node['schema']['x-example'] = 'https://example.com';
|
||||
|
@ -391,7 +391,7 @@ class OpenAPI3 extends Format
|
|||
case 'Utopia\Validator\Length':
|
||||
$node['schema']['type'] = $validator->getType();
|
||||
break;
|
||||
case 'Appwrite\Network\Validator\Host':
|
||||
case 'Utopia\Validator\Host':
|
||||
$node['schema']['type'] = $validator->getType();
|
||||
$node['schema']['format'] = 'url';
|
||||
$node['schema']['x-example'] = 'https://example.com';
|
||||
|
|
|
@ -312,7 +312,7 @@ class Swagger2 extends Format
|
|||
$node['format'] = 'email';
|
||||
$node['x-example'] = 'email@example.com';
|
||||
break;
|
||||
case 'Appwrite\Network\Validator\URL':
|
||||
case 'Utopia\Validator\URL':
|
||||
$node['type'] = $validator->getType();
|
||||
$node['format'] = 'url';
|
||||
$node['x-example'] = 'https://example.com';
|
||||
|
@ -393,7 +393,7 @@ class Swagger2 extends Format
|
|||
case 'Utopia\Validator\Length':
|
||||
$node['type'] = $validator->getType();
|
||||
break;
|
||||
case 'Appwrite\Network\Validator\Host':
|
||||
case 'Utopia\Validator\Host':
|
||||
$node['type'] = $validator->getType();
|
||||
$node['format'] = 'url';
|
||||
$node['x-example'] = 'https://example.com';
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Network\Validators;
|
||||
|
||||
use Appwrite\Network\Validator\Domain;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DomainTest extends TestCase
|
||||
{
|
||||
protected ?Domain $domain = null;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->domain = new Domain();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->domain = null;
|
||||
}
|
||||
|
||||
public function testIsValid(): void
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Utopia PHP Framework
|
||||
*
|
||||
* @package Framework
|
||||
* @subpackage Tests
|
||||
*
|
||||
* @link https://github.com/utopia-php/framework
|
||||
* @author Appwrite Team <team@appwrite.io>
|
||||
* @version 1.0 RC4
|
||||
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Network\Validators;
|
||||
|
||||
use Appwrite\Network\Validator\Host;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HostTest extends TestCase
|
||||
{
|
||||
protected ?Host $host = null;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->host = new Host(['appwrite.io', 'subdomain.appwrite.test', 'localhost']);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->host = null;
|
||||
}
|
||||
|
||||
public function testIsValid(): void
|
||||
{
|
||||
// Assertions
|
||||
$this->assertEquals($this->host->isValid('https://appwrite.io/link'), true);
|
||||
$this->assertEquals($this->host->isValid('https://localhost'), true);
|
||||
$this->assertEquals($this->host->isValid('localhost'), false);
|
||||
$this->assertEquals($this->host->isValid('http://subdomain.appwrite.test/path'), true);
|
||||
$this->assertEquals($this->host->isValid('http://test.subdomain.appwrite.test/path'), false);
|
||||
$this->assertEquals($this->host->getType(), 'string');
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Utopia PHP Framework
|
||||
*
|
||||
* @package Framework
|
||||
* @subpackage Tests
|
||||
*
|
||||
* @link https://github.com/utopia-php/framework
|
||||
* @author Appwrite Team <team@appwrite.io>
|
||||
* @version 1.0 RC4
|
||||
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Network\Validators;
|
||||
|
||||
use Appwrite\Network\Validator\IP;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class IPTest extends TestCase
|
||||
{
|
||||
protected ?IP $validator;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->validator = new IP();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->validator = null;
|
||||
}
|
||||
|
||||
public function testIsValidIP(): void
|
||||
{
|
||||
$this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
|
||||
$this->assertEquals($this->validator->isValid('109.67.204.101'), true);
|
||||
$this->assertEquals($this->validator->isValid(23.5), false);
|
||||
$this->assertEquals($this->validator->isValid('23.5'), false);
|
||||
$this->assertEquals($this->validator->isValid(null), false);
|
||||
$this->assertEquals($this->validator->isValid(true), false);
|
||||
$this->assertEquals($this->validator->isValid(false), false);
|
||||
$this->assertEquals($this->validator->getType(), 'string');
|
||||
}
|
||||
|
||||
public function testIsValidIPALL(): void
|
||||
{
|
||||
$this->validator = new IP(IP::ALL);
|
||||
|
||||
// Assertions
|
||||
$this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
|
||||
$this->assertEquals($this->validator->isValid('109.67.204.101'), true);
|
||||
$this->assertEquals($this->validator->isValid(23.5), false);
|
||||
$this->assertEquals($this->validator->isValid('23.5'), false);
|
||||
$this->assertEquals($this->validator->isValid(null), false);
|
||||
$this->assertEquals($this->validator->isValid(true), false);
|
||||
$this->assertEquals($this->validator->isValid(false), false);
|
||||
}
|
||||
|
||||
public function testIsValidIPV4(): void
|
||||
{
|
||||
$this->validator = new IP(IP::V4);
|
||||
|
||||
// Assertions
|
||||
$this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), false);
|
||||
$this->assertEquals($this->validator->isValid('109.67.204.101'), true);
|
||||
$this->assertEquals($this->validator->isValid(23.5), false);
|
||||
$this->assertEquals($this->validator->isValid('23.5'), false);
|
||||
$this->assertEquals($this->validator->isValid(null), false);
|
||||
$this->assertEquals($this->validator->isValid(true), false);
|
||||
$this->assertEquals($this->validator->isValid(false), false);
|
||||
}
|
||||
|
||||
public function testIsValidIPV6(): void
|
||||
{
|
||||
$this->validator = new IP(IP::V6);
|
||||
|
||||
// Assertions
|
||||
$this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
|
||||
$this->assertEquals($this->validator->isValid('109.67.204.101'), false);
|
||||
$this->assertEquals($this->validator->isValid(23.5), false);
|
||||
$this->assertEquals($this->validator->isValid('23.5'), false);
|
||||
$this->assertEquals($this->validator->isValid(null), false);
|
||||
$this->assertEquals($this->validator->isValid(true), false);
|
||||
$this->assertEquals($this->validator->isValid(false), false);
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Utopia PHP Framework
|
||||
*
|
||||
* @package Framework
|
||||
* @subpackage Tests
|
||||
*
|
||||
* @link https://github.com/utopia-php/framework
|
||||
* @author Appwrite Team <team@appwrite.io>
|
||||
* @version 1.0 RC4
|
||||
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Network\Validators;
|
||||
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class URLTest extends TestCase
|
||||
{
|
||||
protected ?URL $url;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->url = new URL();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->url = null;
|
||||
}
|
||||
|
||||
public function testIsValid(): void
|
||||
{
|
||||
$this->assertEquals('Value must be a valid URL', $this->url->getDescription());
|
||||
$this->assertEquals(true, $this->url->isValid('http://example.com'));
|
||||
$this->assertEquals(true, $this->url->isValid('https://example.com'));
|
||||
$this->assertEquals(true, $this->url->isValid('htts://example.com')); // does not validate protocol
|
||||
$this->assertEquals(false, $this->url->isValid('example.com')); // though, requires some kind of protocol
|
||||
$this->assertEquals(false, $this->url->isValid('http:/example.com'));
|
||||
$this->assertEquals(true, $this->url->isValid('http://exa-mple.com'));
|
||||
$this->assertEquals(false, $this->url->isValid('htt@s://example.com'));
|
||||
$this->assertEquals(true, $this->url->isValid('http://www.example.com/foo%2\u00c2\u00a9zbar'));
|
||||
$this->assertEquals(true, $this->url->isValid('http://www.example.com/?q=%3Casdf%3E'));
|
||||
$this->assertEquals(true, $this->url->isValid('https://example.com/foo%2\u00c2\u00ä9zbär'));
|
||||
}
|
||||
|
||||
public function testIsValidAllowedSchemes(): void
|
||||
{
|
||||
$this->url = new URL(['http', 'https']);
|
||||
$this->assertEquals('Value must be a valid URL with following schemes (http, https)', $this->url->getDescription());
|
||||
$this->assertEquals(true, $this->url->isValid('http://example.com'));
|
||||
$this->assertEquals(true, $this->url->isValid('https://example.com'));
|
||||
$this->assertEquals(false, $this->url->isValid('gopher://www.example.com'));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue