mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 09:04:03 +00:00
Merge a5a243469f into 37b2a91aa9
This commit is contained in:
commit
9d4ef321be
3 changed files with 23 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Resolvers;
|
|||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Stancl\Tenancy\Contracts\Domain;
|
||||
use Stancl\Tenancy\Contracts\SingleDomainTenant;
|
||||
|
|
@ -58,7 +59,19 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
|
|||
|
||||
public static function isSubdomain(string $domain): bool
|
||||
{
|
||||
return Str::endsWith($domain, config('tenancy.identification.central_domains'));
|
||||
$centralDomains = Arr::wrap(config('tenancy.identification.central_domains'));
|
||||
|
||||
foreach ($centralDomains as $centralDomain) {
|
||||
if ($domain === $centralDomain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Str::endsWith($domain, '.' . $centralDomain)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function resolved(Tenant $tenant, mixed ...$args): void
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ test('using different default route modes works with global domain identificatio
|
|||
$exception = match ($middleware) {
|
||||
InitializeTenancyByDomain::class => TenantCouldNotBeIdentifiedOnDomainException::class,
|
||||
InitializeTenancyBySubdomain::class => NotASubdomainException::class,
|
||||
InitializeTenancyByDomainOrSubdomain::class => NotASubdomainException::class,
|
||||
InitializeTenancyByDomainOrSubdomain::class => TenantCouldNotBeIdentifiedOnDomainException::class,
|
||||
};
|
||||
|
||||
expect(fn () => $this->withoutExceptionHandling()->get('http://localhost/central-route'))->toThrow($exception);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use Stancl\Tenancy\Database\Concerns\HasDomains;
|
|||
use Stancl\Tenancy\Exceptions\NotASubdomainException;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain;
|
||||
use Stancl\Tenancy\Database\Models;
|
||||
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
||||
use function Stancl\Tenancy\Tests\pest;
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
@ -108,6 +109,13 @@ test('we cant use a subdomain that doesnt belong to our central domains', functi
|
|||
->get('http://foo.localhost/foo/abc/xyz');
|
||||
});
|
||||
|
||||
test('domain resolver correctly determines if string is a subdomain', function() {
|
||||
config(['tenancy.identification.central_domains' => ['app.test']]);
|
||||
|
||||
expect(DomainTenantResolver::isSubdomain('foo.app.test'))->toBeTrue();
|
||||
expect(DomainTenantResolver::isSubdomain('fooapp.test'))->toBeFalse();
|
||||
});
|
||||
|
||||
class SubdomainTenant extends Models\Tenant
|
||||
{
|
||||
use HasDomains;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue