| 
									
										
										
										
											2016-09-10 17:23:28 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-04-10 02:39:42 +08:00
										 |  |  |  * MinIO Cloud Storage, (C) 2016, 2017, 2018 MinIO, Inc. | 
					
						
							| 
									
										
										
										
											2016-09-10 17:23:28 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2018-09-06 23:03:18 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	"path" | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 	"testing" | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/auth" | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 	"github.com/minio/minio/pkg/event/target" | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestServerConfig(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	objLayer, fsDir, err := prepareFS() | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer os.RemoveAll(fsDir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil { | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 		t.Fatalf("Init Test config failed") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	if globalServerConfig.GetRegion() != globalMinioDefaultRegion { | 
					
						
							|  |  |  | 		t.Errorf("Expecting region `us-east-1` found %s", globalServerConfig.GetRegion()) | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Set new region and verify.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	globalServerConfig.SetRegion("us-west-1") | 
					
						
							|  |  |  | 	if globalServerConfig.GetRegion() != "us-west-1" { | 
					
						
							|  |  |  | 		t.Errorf("Expecting region `us-west-1` found %s", globalServerConfig.GetRegion()) | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Match version.
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	if globalServerConfig.GetVersion() != serverConfigVersion { | 
					
						
							|  |  |  | 		t.Errorf("Expecting version %s found %s", globalServerConfig.GetVersion(), serverConfigVersion) | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 23:03:18 +08:00
										 |  |  | 	if err := saveServerConfig(context.Background(), objLayer, globalServerConfig); err != nil { | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 		t.Fatalf("Unable to save updated config file %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Initialize server config.
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	if err := loadConfig(objLayer); err != nil { | 
					
						
							| 
									
										
										
										
											2016-09-10 15:51:25 +08:00
										 |  |  | 		t.Fatalf("Unable to initialize from updated config file %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TestServerConfigWithEnvs(t *testing.T) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	os.Setenv("MINIO_BROWSER", "off") | 
					
						
							|  |  |  | 	defer os.Unsetenv("MINIO_BROWSER") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 	os.Setenv("MINIO_WORM", "on") | 
					
						
							|  |  |  | 	defer os.Unsetenv("MINIO_WORM") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	os.Setenv("MINIO_ACCESS_KEY", "minio") | 
					
						
							|  |  |  | 	defer os.Unsetenv("MINIO_ACCESS_KEY") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	os.Setenv("MINIO_SECRET_KEY", "minio123") | 
					
						
							|  |  |  | 	defer os.Unsetenv("MINIO_SECRET_KEY") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-10 01:44:10 +08:00
										 |  |  | 	os.Setenv("MINIO_REGION", "us-west-1") | 
					
						
							|  |  |  | 	defer os.Unsetenv("MINIO_REGION") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 	os.Setenv("MINIO_DOMAIN", "domain.com") | 
					
						
							|  |  |  | 	defer os.Unsetenv("MINIO_DOMAIN") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-10 01:44:10 +08:00
										 |  |  | 	defer resetGlobalIsEnvs() | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	objLayer, fsDir, err := prepareFS() | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 		t.Fatal(err) | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	defer os.RemoveAll(fsDir) | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Init Test config failed") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-31 02:21:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	globalObjLayerMutex.Lock() | 
					
						
							|  |  |  | 	globalObjectAPI = objLayer | 
					
						
							|  |  |  | 	globalObjLayerMutex.Unlock() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	serverHandleEnvVars() | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Init config
 | 
					
						
							| 
									
										
										
										
											2018-08-20 04:57:18 +08:00
										 |  |  | 	initConfig(objLayer) | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 	// Check if serverConfig has browser disabled
 | 
					
						
							| 
									
										
										
										
											2018-09-21 05:56:32 +08:00
										 |  |  | 	if globalIsBrowserEnabled { | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 		t.Error("Expected browser to be disabled but it is not") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Check if serverConfig returns WORM config from the env
 | 
					
						
							|  |  |  | 	if !globalServerConfig.GetWorm() { | 
					
						
							|  |  |  | 		t.Error("Expected WORM to be enabled but it is not") | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 	// Check if serverConfig has region from the environment
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	if globalServerConfig.GetRegion() != "us-west-1" { | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 		t.Errorf("Expected region to be \"us-west-1\", found %v", globalServerConfig.GetRegion()) | 
					
						
							| 
									
										
										
										
											2017-04-10 01:44:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 	// Check if serverConfig has credentials from the environment
 | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	cred := globalServerConfig.GetCredential() | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if cred.AccessKey != "minio" { | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 		t.Errorf("Expected access key to be `minio`, found %s", cred.AccessKey) | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if cred.SecretKey != "minio123" { | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 		t.Errorf("Expected access key to be `minio123`, found %s", cred.SecretKey) | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-10 01:44:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 05:36:14 +08:00
										 |  |  | 	// Check if serverConfig has the correct domain
 | 
					
						
							| 
									
										
										
										
											2019-02-23 11:18:01 +08:00
										 |  |  | 	if globalDomainNames[0] != "domain.com" { | 
					
						
							|  |  |  | 		t.Errorf("Expected Domain to be `domain.com`, found " + globalDomainNames[0]) | 
					
						
							| 
									
										
										
										
											2017-11-15 08:56:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-28 06:59:53 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 02:06:17 +08:00
										 |  |  | // Tests config validator..
 | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | func TestValidateConfig(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	objLayer, fsDir, err := prepareFS() | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 		t.Fatal(err) | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	defer os.RemoveAll(fsDir) | 
					
						
							| 
									
										
										
										
											2017-03-17 02:06:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	if err = newTestConfig(globalMinioDefaultRegion, objLayer); err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Init Test config failed") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 	configPath := path.Join(minioConfigPrefix, minioConfigFile) | 
					
						
							| 
									
										
										
										
											2017-11-30 05:12:47 +08:00
										 |  |  | 	v := serverConfigVersion | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	testCases := []struct { | 
					
						
							|  |  |  | 		configData string | 
					
						
							|  |  |  | 		shouldPass bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// Test 1 - wrong json
 | 
					
						
							|  |  |  | 		{`{`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Test 2 - empty json
 | 
					
						
							|  |  |  | 		{`{}`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Test 3 - wrong config version
 | 
					
						
							|  |  |  | 		{`{"version": "10"}`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Test 4 - wrong browser parameter
 | 
					
						
							|  |  |  | 		{`{"version": "` + v + `", "browser": "foo"}`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Test 5 - missing credential
 | 
					
						
							|  |  |  | 		{`{"version": "` + v + `", "browser": "on"}`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Test 6 - missing secret key
 | 
					
						
							|  |  |  | 		{`{"version": "` + v + `", "browser": "on", "credential" : {"accessKey":"minio", "secretKey":""}}`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 02:06:17 +08:00
										 |  |  | 		// Test 7 - missing region should pass, defaults to 'us-east-1'.
 | 
					
						
							|  |  |  | 		{`{"version": "` + v + `", "browser": "on", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, true}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Test 8 - missing browser should pass, defaults to 'on'.
 | 
					
						
							|  |  |  | 		{`{"version": "` + v + `", "region": "us-east-1", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, true}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 02:06:17 +08:00
										 |  |  | 		// Test 9 - success
 | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 		{`{"version": "` + v + `", "browser": "on", "region":"us-east-1", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, true}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 02:06:17 +08:00
										 |  |  | 		// Test 10 - duplicated json keys
 | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 		{`{"version": "` + v + `", "browser": "on", "browser": "on", "region":"us-east-1", "credential" : {"accessKey":"minio", "secretKey":"minio123"}}`, false}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 11 - Test AMQP
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "amqp": { "1": { "enable": true, "url": "", "exchange": "", "routingKey": "", "exchangeType": "", "mandatory": false, "immediate": false, "durable": false, "internal": false, "noWait": false, "autoDeleted": false }}}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 12 - Test NATS
 | 
					
						
							| 
									
										
										
										
											2018-11-30 13:16:17 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "nats": { "1": { "enable": true, "address": "", "subject": "", "username": "", "password": "", "token": "", "secure": false, "pingInterval": 0, "streaming": { "enable": false, "clusterID": "", "async": false, "maxPubAcksInflight": 0 } } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 13 - Test ElasticSearch
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "elasticsearch": { "1": { "enable": true, "url": "", "index": "" } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 14 - Test Redis
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "redis": { "1": { "enable": true, "address": "", "password": "", "key": "" } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 15 - Test PostgreSQL
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "postgresql": { "1": { "enable": true, "connectionString": "", "table": "", "host": "", "port": "", "user": "", "password": "", "database": "" }}}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 16 - Test Kafka
 | 
					
						
							| 
									
										
										
										
											2019-05-30 04:19:48 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "kafka": { "1": { "enable": true, "brokers": null, "topic": "", "queueDir": "", "queueLimit": 0 } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 17 - Test Webhook
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "webhook": { "1": { "enable": true, "endpoint": "" } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-18 00:29:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 18 - Test MySQL
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "mysql": { "1": { "enable": true, "dsnString": "",  "table": "", "host": "", "port": "", "user": "", "password": "", "database": "" }}}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 19 - Test Format for MySQL
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "mysql": { "1": { "enable": true, "dsnString": "",  "format": "invalid", "table": "xxx", "host": "10.0.0.1", "port": "3306", "user": "abc", "password": "pqr", "database": "test1" }}}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 20 - Test valid Format for MySQL
 | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "mysql": { "1": { "enable": true, "dsnString": "",  "format": "namespace", "table": "xxx", "host": "10.0.0.1", "port": "3306", "user": "abc", "password": "pqr", "database": "test1" }}}}`, true}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 21 - Test Format for PostgreSQL
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "postgresql": { "1": { "enable": true, "connectionString": "", "format": "invalid", "table": "xxx", "host": "myhost", "port": "5432", "user": "abc", "password": "pqr", "database": "test1" }}}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 22 - Test valid Format for PostgreSQL
 | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "postgresql": { "1": { "enable": true, "connectionString": "", "format": "namespace", "table": "xxx", "host": "myhost", "port": "5432", "user": "abc", "password": "pqr", "database": "test1" }}}}`, true}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 23 - Test Format for ElasticSearch
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "elasticsearch": { "1": { "enable": true, "format": "invalid", "url": "example.com", "index": "myindex" } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 24 - Test valid Format for ElasticSearch
 | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "elasticsearch": { "1": { "enable": true, "format": "namespace", "url": "example.com", "index": "myindex" } }}}`, true}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 25 - Test Format for Redis
 | 
					
						
							| 
									
										
										
										
											2018-07-19 02:22:29 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "redis": { "1": { "enable": true, "format": "invalid", "address": "example.com:80", "password": "xxx", "key": "key1" } }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-28 02:27:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 26 - Test valid Format for Redis
 | 
					
						
							| 
									
										
										
										
											2017-03-31 19:47:40 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "redis": { "1": { "enable": true, "format": "namespace", "address": "example.com:80", "password": "xxx", "key": "key1" } }}}`, true}, | 
					
						
							| 
									
										
										
										
											2017-06-15 08:27:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 		// Test 27 - Test MQTT
 | 
					
						
							| 
									
										
										
										
											2019-02-26 10:01:13 +08:00
										 |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "mqtt": { "1": { "enable": true, "broker": "",  "topic": "", "qos": 0, "username": "", "password": "", "queueDir": "", "queueLimit": 0}}}}`, false}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Test 28 - Test NSQ
 | 
					
						
							|  |  |  | 		{`{"version": "` + v + `", "credential": { "accessKey": "minio", "secretKey": "minio123" }, "region": "us-east-1", "browser": "on", "notify": { "nsq": { "1": { "enable": true, "nsqdAddress": "", "topic": ""} }}}`, false}, | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, testCase := range testCases { | 
					
						
							| 
									
										
										
										
											2018-10-10 05:00:01 +08:00
										 |  |  | 		if err = saveConfig(context.Background(), objLayer, configPath, []byte(testCase.configData)); err != nil { | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 			t.Fatal(err) | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 		_, err = getValidConfig(objLayer) | 
					
						
							|  |  |  | 		if testCase.shouldPass && err != nil { | 
					
						
							|  |  |  | 			t.Errorf("Test %d, should pass but it failed with err = %v", i+1, err) | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-15 12:41:47 +08:00
										 |  |  | 		if !testCase.shouldPass && err == nil { | 
					
						
							| 
									
										
										
										
											2017-12-06 15:18:29 +08:00
										 |  |  | 			t.Errorf("Test %d, should fail but it succeeded.", i+1) | 
					
						
							| 
									
										
										
										
											2017-03-16 07:30:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TestConfigDiff(t *testing.T) { | 
					
						
							|  |  |  | 	testCases := []struct { | 
					
						
							|  |  |  | 		s, t *serverConfig | 
					
						
							|  |  |  | 		diff string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// 1
 | 
					
						
							|  |  |  | 		{&serverConfig{}, nil, "Given configuration is empty"}, | 
					
						
							|  |  |  | 		// 2
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-10-10 05:00:01 +08:00
										 |  |  | 			&serverConfig{Credential: auth.Credentials{ | 
					
						
							|  |  |  | 				AccessKey:  "u1", | 
					
						
							|  |  |  | 				SecretKey:  "p1", | 
					
						
							|  |  |  | 				Expiration: timeSentinel, | 
					
						
							|  |  |  | 			}}, | 
					
						
							|  |  |  | 			&serverConfig{Credential: auth.Credentials{ | 
					
						
							|  |  |  | 				AccessKey:  "u1", | 
					
						
							|  |  |  | 				SecretKey:  "p2", | 
					
						
							|  |  |  | 				Expiration: timeSentinel, | 
					
						
							|  |  |  | 			}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"Credential configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// 3
 | 
					
						
							|  |  |  | 		{&serverConfig{Region: "us-east-1"}, &serverConfig{Region: "us-west-1"}, "Region configuration differs"}, | 
					
						
							|  |  |  | 		// 4
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			&serverConfig{StorageClass: storageClassConfig{storageClass{"1", 8}, storageClass{"2", 6}}}, | 
					
						
							|  |  |  | 			&serverConfig{StorageClass: storageClassConfig{storageClass{"1", 8}, storageClass{"2", 4}}}, | 
					
						
							|  |  |  | 			"StorageClass configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-09-21 05:56:32 +08:00
										 |  |  | 		// 5
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{AMQP: map[string]target.AMQPArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{AMQP: map[string]target.AMQPArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"AMQP Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-09-21 05:56:32 +08:00
										 |  |  | 		// 6
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{NATS: map[string]target.NATSArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{NATS: map[string]target.NATSArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"NATS Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-09-21 05:56:32 +08:00
										 |  |  | 		// 7
 | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{NSQ: map[string]target.NSQArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{NSQ: map[string]target.NSQArgs{"1": {Enable: false}}}}, | 
					
						
							|  |  |  | 			"NSQ Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// 8
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{Elasticsearch: map[string]target.ElasticsearchArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{Elasticsearch: map[string]target.ElasticsearchArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"ElasticSearch Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 9
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{Redis: map[string]target.RedisArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{Redis: map[string]target.RedisArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"Redis Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 10
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{PostgreSQL: map[string]target.PostgreSQLArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{PostgreSQL: map[string]target.PostgreSQLArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"PostgreSQL Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 11
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{Kafka: map[string]target.KafkaArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{Kafka: map[string]target.KafkaArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"Kafka Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 12
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{Webhook: map[string]target.WebhookArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{Webhook: map[string]target.WebhookArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"Webhook Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 13
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{MySQL: map[string]target.MySQLArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{MySQL: map[string]target.MySQLArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"MySQL Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 14
 | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-03-16 04:03:41 +08:00
										 |  |  | 			&serverConfig{Notify: notifier{MQTT: map[string]target.MQTTArgs{"1": {Enable: true}}}}, | 
					
						
							|  |  |  | 			&serverConfig{Notify: notifier{MQTT: map[string]target.MQTTArgs{"1": {Enable: false}}}}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 			"MQTT Notification configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-11-08 02:23:13 +08:00
										 |  |  | 		// 15
 | 
					
						
							| 
									
										
										
										
											2018-07-20 06:55:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			&serverConfig{Logger: loggerConfig{ | 
					
						
							|  |  |  | 				Console: loggerConsole{Enabled: true}, | 
					
						
							|  |  |  | 				HTTP:    map[string]loggerHTTP{"1": {Endpoint: "http://address1"}}, | 
					
						
							|  |  |  | 			}}, | 
					
						
							|  |  |  | 			&serverConfig{Logger: loggerConfig{ | 
					
						
							|  |  |  | 				Console: loggerConsole{Enabled: true}, | 
					
						
							|  |  |  | 				HTTP:    map[string]loggerHTTP{"1": {Endpoint: "http://address2"}}, | 
					
						
							|  |  |  | 			}}, | 
					
						
							|  |  |  | 			"Logger configuration differs", | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2018-02-01 00:15:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, testCase := range testCases { | 
					
						
							|  |  |  | 		got := testCase.s.ConfigDiff(testCase.t) | 
					
						
							|  |  |  | 		if got != testCase.diff { | 
					
						
							|  |  |  | 			t.Errorf("Test %d: got %s expected %s", i+1, got, testCase.diff) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |