Merge pull request #5041 from consul/not_found_tenants

Respond with not found on missing tenants
This commit is contained in:
Javi Martín
2022-12-12 11:49:55 +01:00
committed by GitHub
2 changed files with 15 additions and 4 deletions

View File

@@ -48,6 +48,7 @@ module Consul
# Handle custom exceptions # Handle custom exceptions
config.action_dispatch.rescue_responses["FeatureFlags::FeatureDisabled"] = :forbidden config.action_dispatch.rescue_responses["FeatureFlags::FeatureDisabled"] = :forbidden
config.action_dispatch.rescue_responses["Apartment::TenantNotFound"] = :not_found
# Store uploaded files on the local file system (see config/storage.yml for options). # Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local config.active_storage.service = :local

View File

@@ -1,12 +1,10 @@
require "rails_helper" require "rails_helper"
describe "Multitenancy", :seed_tenants do describe "Multitenancy", :seed_tenants do
before do before { create(:tenant, schema: "mars") }
create(:tenant, schema: "mars")
create(:tenant, schema: "venus")
end
scenario "Disabled features", :no_js do scenario "Disabled features", :no_js do
create(:tenant, schema: "venus")
Tenant.switch("mars") { Setting["process.debates"] = true } Tenant.switch("mars") { Setting["process.debates"] = true }
Tenant.switch("venus") { Setting["process.debates"] = nil } Tenant.switch("venus") { Setting["process.debates"] = nil }
@@ -22,6 +20,7 @@ describe "Multitenancy", :seed_tenants do
end end
scenario "Content is different for differents tenants" do scenario "Content is different for differents tenants" do
create(:tenant, schema: "venus")
Tenant.switch("mars") { create(:poll, name: "Human rights for Martians?") } Tenant.switch("mars") { create(:poll, name: "Human rights for Martians?") }
with_subdomain("mars") do with_subdomain("mars") do
@@ -69,6 +68,7 @@ describe "Multitenancy", :seed_tenants do
end end
scenario "Creating content in one tenant doesn't affect other tenants" do scenario "Creating content in one tenant doesn't affect other tenants" do
create(:tenant, schema: "venus")
Tenant.switch("mars") { login_as(create(:user)) } Tenant.switch("mars") { login_as(create(:user)) }
with_subdomain("mars") do with_subdomain("mars") do
@@ -96,6 +96,7 @@ describe "Multitenancy", :seed_tenants do
end end
scenario "Users from another tenant cannot vote" do scenario "Users from another tenant cannot vote" do
create(:tenant, schema: "venus")
Tenant.switch("mars") { create(:proposal, title: "Earth invasion") } Tenant.switch("mars") { create(:proposal, title: "Earth invasion") }
Tenant.switch("venus") { login_as(create(:user)) } Tenant.switch("venus") { login_as(create(:user)) }
@@ -138,6 +139,7 @@ describe "Multitenancy", :seed_tenants do
end end
scenario "Users from another tenant can't sign in" do scenario "Users from another tenant can't sign in" do
create(:tenant, schema: "venus")
Tenant.switch("mars") { create(:user, email: "marty@consul.dev", password: "20151021") } Tenant.switch("mars") { create(:user, email: "marty@consul.dev", password: "20151021") }
with_subdomain("mars") do with_subdomain("mars") do
@@ -171,4 +173,12 @@ describe "Multitenancy", :seed_tenants do
expect(page).not_to have_css "html.tenant-public" expect(page).not_to have_css "html.tenant-public"
end end
end end
scenario "Shows the not found page when accessing a non-existing tenant", :show_exceptions do
with_subdomain("jupiter") do
visit root_path
expect(page).to have_title "Not found"
end
end
end end