From 06d2dfa31c1d6fc262883146e266498ce96bf099 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Fri, 24 Aug 2018 22:36:14 +0100 Subject: [PATCH] Fix WORM and BROWSER status calculation (#6360) One typo introduced in a recent commit miscalculates if worm and browser are enabled or not. A simple test is also added to detect this issue in the future if it ever happens again. --- cmd/config-current.go | 8 ++++---- cmd/config-current_test.go | 25 +++++++++++++++++-------- cmd/test-utils_test.go | 1 + 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cmd/config-current.go b/cmd/config-current.go index 4fddd8444..92c852aa2 100644 --- a/cmd/config-current.go +++ b/cmd/config-current.go @@ -128,8 +128,8 @@ func (s *serverConfig) GetStorageClass() (storageClass, storageClass) { // GetBrowser get current credentials. func (s *serverConfig) GetBrowser() bool { - if globalIsEnvWORM { - return globalWORMEnabled + if globalIsEnvBrowser { + return globalIsBrowserEnabled } if s == nil { return true @@ -139,8 +139,8 @@ func (s *serverConfig) GetBrowser() bool { // GetWorm get current credentials. func (s *serverConfig) GetWorm() bool { - if globalIsEnvBrowser { - return globalIsBrowserEnabled + if globalIsEnvWORM { + return globalWORMEnabled } if s == nil { return false diff --git a/cmd/config-current_test.go b/cmd/config-current_test.go index a5e33d5f9..3db9c017f 100644 --- a/cmd/config-current_test.go +++ b/cmd/config-current_test.go @@ -66,6 +66,9 @@ func TestServerConfigWithEnvs(t *testing.T) { os.Setenv("MINIO_BROWSER", "off") defer os.Unsetenv("MINIO_BROWSER") + os.Setenv("MINIO_WORM", "on") + defer os.Unsetenv("MINIO_WORM") + os.Setenv("MINIO_ACCESS_KEY", "minio") defer os.Unsetenv("MINIO_ACCESS_KEY") @@ -99,29 +102,35 @@ func TestServerConfigWithEnvs(t *testing.T) { // Init config initConfig(objLayer) - // Check if serverConfig has + // Check if serverConfig has browser disabled if globalServerConfig.GetBrowser() { - t.Errorf("Expecting browser is set to false found %v", globalServerConfig.GetBrowser()) + t.Error("Expected browser to be disabled but it is not") } - // Check if serverConfig has + // Check if serverConfig returns WORM config from the env + if !globalServerConfig.GetWorm() { + t.Error("Expected WORM to be enabled but it is not") + } + + // Check if serverConfig has region from the environment if globalServerConfig.GetRegion() != "us-west-1" { - t.Errorf("Expecting region to be \"us-west-1\" found %v", globalServerConfig.GetRegion()) + t.Errorf("Expected region to be \"us-west-1\", found %v", globalServerConfig.GetRegion()) } - // Check if serverConfig has + // Check if serverConfig has credentials from the environment cred := globalServerConfig.GetCredential() if cred.AccessKey != "minio" { - t.Errorf("Expecting access key to be `minio` found %s", cred.AccessKey) + t.Errorf("Expected access key to be `minio`, found %s", cred.AccessKey) } if cred.SecretKey != "minio123" { - t.Errorf("Expecting access key to be `minio123` found %s", cred.SecretKey) + t.Errorf("Expected access key to be `minio123`, found %s", cred.SecretKey) } + // Check if serverConfig has the correct domain if globalServerConfig.Domain != "domain.com" { - t.Errorf("Expecting Domain to be `domain.com` found " + globalServerConfig.Domain) + t.Errorf("Expected Domain to be `domain.com`, found " + globalServerConfig.Domain) } } diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 4445b8247..3befb18c6 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -434,6 +434,7 @@ func resetGlobalIsXL() { func resetGlobalIsEnvs() { globalIsEnvCreds = false + globalIsEnvWORM = false globalIsEnvBrowser = false globalIsEnvRegion = false globalIsStorageClass = false