1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 15:24:03 +00:00

Make central domain order not matter in isSubdomain()

This commit is contained in:
lukinovec 2026-04-13 17:59:57 +02:00
parent 3976880dcb
commit f4ee0a7943
2 changed files with 8 additions and 7 deletions

View file

@ -61,11 +61,11 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
{
$centralDomains = Arr::wrap(config('tenancy.identification.central_domains'));
foreach ($centralDomains as $centralDomain) {
if ($domain === $centralDomain) {
return false;
}
if (in_array($domain, $centralDomains, true)) {
return false;
}
foreach ($centralDomains as $centralDomain) {
if (Str::endsWith($domain, '.' . $centralDomain)) {
return true;
}

View file

@ -110,10 +110,11 @@ test('we cant use a subdomain that doesnt belong to our central domains', functi
});
test('domain resolver correctly determines if string is a subdomain', function() {
config(['tenancy.identification.central_domains' => ['app.test']]);
config(['tenancy.identification.central_domains' => ['site.com', 'blog.site.com']]);
expect(DomainTenantResolver::isSubdomain('foo.app.test'))->toBeTrue();
expect(DomainTenantResolver::isSubdomain('fooapp.test'))->toBeFalse();
expect(DomainTenantResolver::isSubdomain('blog.site.com'))->toBeFalse();
expect(DomainTenantResolver::isSubdomain('tenant.site.com'))->toBeTrue();
expect(DomainTenantResolver::isSubdomain('tenantsite.com'))->toBeFalse();
});
class SubdomainTenant extends Models\Tenant