Allow having tenants with different domains
Some institutions using CONSUL have expressed interest in this feature since some of their tenants might already have their own domains. We've considered many options for the user interface to select whether we're using a subdomain or a domain, like having two separate fields, using a check box, ... In the end we've chosen radio buttons because they make it easier to follow a logical sequence: first you decide whether you're introducing a domain or subdomain, and then you enter it. We've also considered hiding this option and assuming "if it's got a dot, it's a domain". However, this wouldn't work with nested subdomains and it wouldn't work with domains which are simply machine names. Note that a group of radio buttons (or check boxes) is difficult to style when the text of the label might expand over more than one line (as is the case here on small screens); in this case, most solutions result in the second line of the label appearing immediately under the radio button, instead of being aligned with the first line of the label. That's why I've added a container for the input+label combination.
This commit is contained in:
@@ -74,6 +74,49 @@ describe Tenant do
|
||||
expect(Tenant.resolve_host("www.mercury.anotherconsul.dev")).to eq "mercury.anotherconsul.dev"
|
||||
end
|
||||
|
||||
it "returns full domains when there's a tenant with a domain including the host" do
|
||||
insert(:tenant, :domain, schema: "saturn.consul.dev")
|
||||
|
||||
expect(Tenant.resolve_host("saturn.consul.dev")).to eq "saturn.consul.dev"
|
||||
end
|
||||
|
||||
it "returns subdomains when there's a subdomain-type tenant with that domain" do
|
||||
insert(:tenant, schema: "saturn.consul.dev")
|
||||
|
||||
expect(Tenant.resolve_host("saturn.consul.dev")).to eq "saturn"
|
||||
end
|
||||
|
||||
it "returns nil 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
|
||||
end
|
||||
|
||||
it "returns nested subdomains when there's a subdomain-type tenant with nested subdomains" do
|
||||
insert(:tenant, schema: "saturn.dev")
|
||||
|
||||
expect(Tenant.resolve_host("saturn.dev.consul.dev")).to eq "saturn.dev"
|
||||
end
|
||||
|
||||
it "returns domains when there are two tenants resolving to the same domain" do
|
||||
insert(:tenant, schema: "saturn")
|
||||
insert(:tenant, :domain, schema: "saturn.consul.dev")
|
||||
|
||||
expect(Tenant.resolve_host("saturn.consul.dev")).to eq "saturn.consul.dev"
|
||||
end
|
||||
|
||||
it "returns domains when there's a tenant using the default host" do
|
||||
insert(:tenant, :domain, schema: "consul.dev")
|
||||
|
||||
expect(Tenant.resolve_host("consul.dev")).to eq "consul.dev"
|
||||
end
|
||||
|
||||
it "returns domains including www when the tenant contains it" do
|
||||
insert(:tenant, :domain, schema: "www.consul.dev")
|
||||
|
||||
expect(Tenant.resolve_host("www.consul.dev")).to eq "www.consul.dev"
|
||||
end
|
||||
|
||||
context "multitenancy disabled" do
|
||||
before { allow(Rails.application.config).to receive(:multitenancy).and_return(false) }
|
||||
|
||||
@@ -151,6 +194,18 @@ describe Tenant do
|
||||
|
||||
expect(Tenant.host_for("uranus")).to eq "uranus.lvh.me"
|
||||
end
|
||||
|
||||
it "ignores the default host when given a full domain" do
|
||||
insert(:tenant, :domain, schema: "whole.galaxy")
|
||||
|
||||
expect(Tenant.host_for("whole.galaxy")).to eq "whole.galaxy"
|
||||
end
|
||||
|
||||
it "uses the default host when given nested subdomains" do
|
||||
insert(:tenant, schema: "whole.galaxy")
|
||||
|
||||
expect(Tenant.host_for("whole.galaxy")).to eq "whole.galaxy.consul.dev"
|
||||
end
|
||||
end
|
||||
|
||||
describe ".current_secrets" do
|
||||
@@ -230,6 +285,22 @@ describe Tenant do
|
||||
end
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
describe ".domain" do
|
||||
it "returns tenants with domain schema type" do
|
||||
insert(:tenant, schema_type: :domain, schema: "full.domain")
|
||||
|
||||
expect(Tenant.domain.pluck(:schema)).to eq ["full.domain"]
|
||||
end
|
||||
|
||||
it "does not return tenants with subdomain schema type" do
|
||||
insert(:tenant, schema_type: :subdomain, schema: "nested.subdomain")
|
||||
|
||||
expect(Tenant.domain).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
let(:tenant) { build(:tenant) }
|
||||
|
||||
@@ -273,6 +344,20 @@ describe Tenant do
|
||||
insert(:tenant, name: "Name X")
|
||||
expect(build(:tenant, name: "Name X")).not_to be_valid
|
||||
end
|
||||
|
||||
context "Domain schema type" do
|
||||
before { tenant.schema_type = :domain }
|
||||
|
||||
it "is valid with domains" do
|
||||
tenant.schema = "my.domain"
|
||||
expect(tenant).to be_valid
|
||||
end
|
||||
|
||||
it "is valid with domains which are machine names" do
|
||||
tenant.schema = "localmachine"
|
||||
expect(tenant).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create_schema" do
|
||||
|
||||
Reference in New Issue
Block a user