Raise an exception when accessing a domain as subdomain
We were returning `nil` in this case, meaning we would be accessing the main tenant in this situation instead of returning "Not Found".
This commit is contained in:
@@ -30,7 +30,11 @@ class Tenant < ApplicationRecord
|
||||
host_domain = allowed_domains.find { |domain| host == domain || host.ends_with?(".#{domain}") }
|
||||
schema = host_without_www.sub(/\.?#{host_domain}\Z/, "").presence
|
||||
|
||||
schema unless find_by_domain(schema)
|
||||
if find_by_domain(schema)
|
||||
raise Apartment::TenantNotFound
|
||||
else
|
||||
schema
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -86,10 +86,10 @@ describe Tenant do
|
||||
expect(Tenant.resolve_host("saturn.consul.dev")).to eq "saturn"
|
||||
end
|
||||
|
||||
it "returns nil when a domain is accessed as a subdomain" do
|
||||
it "raises an exception when a domain is accessed as a subdomain" do
|
||||
insert(:tenant, :domain, schema: "saturn.dev")
|
||||
|
||||
expect(Tenant.resolve_host("saturn.dev.consul.dev")).to be nil
|
||||
expect { Tenant.resolve_host("saturn.dev.consul.dev") }.to raise_exception(Apartment::TenantNotFound)
|
||||
end
|
||||
|
||||
it "returns nested subdomains when there's a subdomain-type tenant with nested subdomains" do
|
||||
|
||||
Reference in New Issue
Block a user