Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix sub sub domain issue (#175)

Guilherme Oenning16811b5c4c40
diff --git a/app/middlewares/domain_test.go b/app/middlewares/domain_test.go
index df39853ea..6495c1a4a 100644
--- a/app/middlewares/domain_test.go
+++ b/app/middlewares/domain_test.go
@@ -51,6 +51,19 @@ func TestMultiTenant(t *testing.T) {
}
}
+func TestMultiTenant_SubSubDomain(t *testing.T) {
+ RegisterTestingT(t)
+
+ server, _ := mock.NewServer()
+ server.Use(middlewares.MultiTenant())
+
+ status, _ := server.WithURL("http://demo.demo.test.fider.io").Execute(func(c web.Context) error {
+ return c.String(http.StatusOK, c.Tenant().Name)
+ })
+
+ Expect(status).To(Equal(http.StatusNotFound))
+}
+
func TestMultiTenant_UnknownDomain(t *testing.T) {
RegisterTestingT(t)
diff --git a/app/storage/inmemory/tenant.go b/app/storage/inmemory/tenant.go
index 794ab456f..b107328c4 100644
--- a/app/storage/inmemory/tenant.go
+++ b/app/storage/inmemory/tenant.go
@@ -6,6 +6,7 @@ import (
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
+ "github.com/getfider/fider/app/pkg/env"
)
// TenantStorage contains read and write operations for tenants
@@ -128,9 +129,11 @@ func (s *TenantStorage) SetKeyAsVerified(key string) error {
return nil
}
-func extractSubdomain(domain string) string {
- if idx := strings.Index(domain, "."); idx != -1 {
- return domain[:idx]
+func extractSubdomain(hostname string) string {
+ domain := env.MultiTenantDomain()
+ if domain == "" {
+ return ""
}
- return domain
+
+ return strings.Replace(hostname, domain, "", -1)
}
diff --git a/app/storage/postgres/tenant.go b/app/storage/postgres/tenant.go
index cb96dab49..d462bccae 100644
--- a/app/storage/postgres/tenant.go
+++ b/app/storage/postgres/tenant.go
@@ -9,6 +9,7 @@ import (
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/dbx"
+ "github.com/getfider/fider/app/pkg/env"
)
// TenantStorage contains read and write operations for tenants
@@ -167,9 +168,11 @@ func (s *TenantStorage) SetKeyAsVerified(key string) error {
return s.trx.Execute(query, time.Now(), s.current.ID, key)
}
-func extractSubdomain(domain string) string {
- if idx := strings.Index(domain, "."); idx != -1 {
- return domain[:idx]
+func extractSubdomain(hostname string) string {
+ domain := env.MultiTenantDomain()
+ if domain == "" {
+ return ""
}
- return domain
+
+ return strings.Replace(hostname, domain, "", -1)
}