mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Add checks for subdomain validation
This commit is contained in:
parent
6192e014c6
commit
ddcaead160
@ -12,7 +12,8 @@
|
||||
|
||||
namespace App\DataProviders;
|
||||
|
||||
class Domains {
|
||||
class Domains
|
||||
{
|
||||
|
||||
private static array $verify_domains = [
|
||||
'0-00.usa.cc',
|
||||
|
@ -30,6 +30,12 @@ class SubdomainController extends BaseController
|
||||
return response()->json(['message' => ctrans('texts.subdomain_is_not_available')], 401);
|
||||
}
|
||||
|
||||
|
||||
if (!preg_match('/^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$/', request()->input('subdomain'))) {
|
||||
return response()->json(['message' => ctrans('texts.subdomain_is_not_available')], 401);
|
||||
}
|
||||
|
||||
|
||||
return response()->json(['message' => 'Domain available'], 200);
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,20 @@ class DomainCheckTest extends TestCase
|
||||
public function testDomainCheck()
|
||||
{
|
||||
|
||||
$this->assertTrue(in_array('yopmail.com', Domains::getDomains()));
|
||||
$this->assertFalse(in_array('invoiceninja.com', Domains::getDomains()));
|
||||
$this->assertTrue(in_array('yopmail.com', \App\DataProviders\Domains::getDomains()));
|
||||
$this->assertFalse(in_array('invoiceninja.com', \App\DataProviders\Domains::getDomains()));
|
||||
|
||||
}
|
||||
|
||||
public function testSubdomainValidation()
|
||||
{
|
||||
$this->assertFalse($this->checker('invoiceninja'));
|
||||
$this->assertFalse($this->checker('hello'));
|
||||
$this->assertTrue($this->checker('nasty.pasty'));
|
||||
}
|
||||
|
||||
public function checker($subdomain)
|
||||
{
|
||||
return (!preg_match('/^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$/', $subdomain));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user