1
0
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:
David Bomba 2023-12-08 12:57:34 +11:00
parent 6192e014c6
commit ddcaead160
3 changed files with 22 additions and 3 deletions

View File

@ -12,7 +12,8 @@
namespace App\DataProviders;
class Domains {
class Domains
{
private static array $verify_domains = [
'0-00.usa.cc',

View File

@ -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);
}
}

View File

@ -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));
}
}