mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	support etcd credentials in etcd plugin (#2442)
* support etcd credentials in etcd plugin fixes #2441 * try to fix cleanup of authentication
This commit is contained in:
		
				
					committed by
					
						 Miek Gieben
						Miek Gieben
					
				
			
			
				
	
			
			
			
						parent
						
							b455f86824
						
					
				
				
					commit
					d878eeebbb
				
			| @@ -14,43 +14,69 @@ func TestSetupEtcd(t *testing.T) { | ||||
| 		expectedPath       string | ||||
| 		expectedEndpoint   []string | ||||
| 		expectedErrContent string // substring from the expected error. Empty for positive cases. | ||||
| 		username           string | ||||
| 		password           string | ||||
| 	}{ | ||||
| 		// positive | ||||
| 		{ | ||||
| 			`etcd`, false, "skydns", []string{"http://localhost:2379"}, "", | ||||
| 			`etcd`, false, "skydns", []string{"http://localhost:2379"}, "", "", "", | ||||
| 		}, | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 	endpoint http://localhost:2379 http://localhost:3379 http://localhost:4379 | ||||
|  | ||||
| }`, false, "skydns", []string{"http://localhost:2379", "http://localhost:3379", "http://localhost:4379"}, "", | ||||
| }`, false, "skydns", []string{"http://localhost:2379", "http://localhost:3379", "http://localhost:4379"}, "", "", "", | ||||
| 		}, | ||||
| 		{ | ||||
| 			`etcd skydns.local { | ||||
| 	endpoint localhost:300 | ||||
| } | ||||
| `, false, "skydns", []string{"localhost:300"}, "", | ||||
| `, false, "skydns", []string{"localhost:300"}, "", "", "", | ||||
| 		}, | ||||
| 		//test for upstream | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 	endpoint localhost:300 | ||||
| 	upstream 8.8.8.8:53 8.8.4.4:53 | ||||
| }`, false, "skydns", []string{"localhost:300"}, "", | ||||
| }`, false, "skydns", []string{"localhost:300"}, "", "", "", | ||||
| 		}, | ||||
| 		//test for optional upstream address | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 	endpoint localhost:300 | ||||
| 	upstream | ||||
| }`, false, "skydns", []string{"localhost:300"}, "", | ||||
| }`, false, "skydns", []string{"localhost:300"}, "", "", "", | ||||
| 		}, | ||||
| 		// negative | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 	endpoints localhost:300 | ||||
| } | ||||
| `, true, "", []string{""}, "unknown property 'endpoints'", | ||||
| `, true, "", []string{""}, "unknown property 'endpoints'", "", "", | ||||
| 		}, | ||||
| 		// with valid credentials | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 			endpoint http://localhost:2379 | ||||
| 			credentials username password | ||||
| 		} | ||||
| 			`, false, "skydns", []string{"http://localhost:2379"}, "", "username", "password", | ||||
| 		}, | ||||
| 		// with credentials, missing password | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 			endpoint http://localhost:2379 | ||||
| 			credentials username | ||||
| 		} | ||||
| 			`, true, "skydns", []string{"http://localhost:2379"}, "credentials requires 2 arguments", "username", "", | ||||
| 		}, | ||||
| 		// with credentials, missing username and  password | ||||
| 		{ | ||||
| 			`etcd { | ||||
| 			endpoint http://localhost:2379 | ||||
| 			credentials | ||||
| 		} | ||||
| 			`, true, "skydns", []string{"http://localhost:2379"}, "Wrong argument count", "", "", | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| @@ -69,7 +95,7 @@ func TestSetupEtcd(t *testing.T) { | ||||
| 			} | ||||
|  | ||||
| 			if !strings.Contains(err.Error(), test.expectedErrContent) { | ||||
| 				t.Errorf("Test %d: Expected error to contain: %v, found error: %v, input: %s", i, test.expectedErrContent, err, test.input) | ||||
| 				t.Errorf("Test %d: Expected error to contain: %v, found error: %v, input: %s", i, test.expectedErrContent, err.Error(), test.input) | ||||
| 				continue | ||||
| 			} | ||||
| 		} | ||||
| @@ -87,5 +113,19 @@ func TestSetupEtcd(t *testing.T) { | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if !test.shouldErr { | ||||
| 			if test.username != "" { | ||||
| 				if etcd.Client.Username != test.username { | ||||
| 					t.Errorf("Etcd username not correctly set for input %s. Excpeted: '%+v', actual: '%+v'", test.input, test.username, etcd.Client.Username) | ||||
| 				} | ||||
| 			} | ||||
| 			if test.password != "" { | ||||
| 				if etcd.Client.Password != test.password { | ||||
| 					t.Errorf("Etcd password not correctly set for input %s. Excpeted: '%+v', actual: '%+v'", test.input, test.password, etcd.Client.Password) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user