From 829176ac76c1dc25373800824602261940fca121 Mon Sep 17 00:00:00 2001 From: Nick Thomas <nick@gitlab.com> Date: Mon, 24 Apr 2017 17:31:28 +0100 Subject: [PATCH] Fix reading configuration for multiple custom domains Without this patch, the different domains end up with pointers to the same domainsConfig struct, as go re-uses the same region of memory on each iteration of a for loop. --- domains.go | 3 ++- domains_test.go | 7 +++++++ shared/pages/group/group.test.io/config.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/domains.go b/domains.go index d298b63..1fed632 100644 --- a/domains.go +++ b/domains.go @@ -44,8 +44,9 @@ func (d domains) readProjectConfig(rootDomain, group, project string) (err error } for _, domainConfig := range config.Domains { + config := domainConfig // domainConfig is reused for each loop iteration if domainConfig.Valid(rootDomain) { - d.addDomain(rootDomain, group, project, &domainConfig) + d.addDomain(rootDomain, group, project, &config) } } return diff --git a/domains_test.go b/domains_test.go index 5a2882d..6ce11f5 100644 --- a/domains_test.go +++ b/domains_test.go @@ -40,6 +40,13 @@ func TestReadProjects(t *testing.T) { for _, actual := range domains { assert.Contains(t, expectedDomains, actual) } + + // Check that multiple domains in the same project are recorded faithfully + exp1 := &domainConfig{Domain: "test.domain.com"} + assert.Equal(t, exp1, d["test.domain.com"].Config) + + exp2 := &domainConfig{Domain: "other.domain.com", Certificate: "test", Key: "key"} + assert.Equal(t, exp2, d["other.domain.com"].Config) } func writeRandomTimestamp() { diff --git a/shared/pages/group/group.test.io/config.json b/shared/pages/group/group.test.io/config.json index 1643525..5b9be1f 100644 --- a/shared/pages/group/group.test.io/config.json +++ b/shared/pages/group/group.test.io/config.json @@ -9,7 +9,7 @@ { "Domain": "other.domain.com", "Certificate": "test", - "Certificate": "key" + "Key": "key" } ] } -- GitLab