mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	cli/api: Update plugin listing to always include version info in the response (#17347)
This commit is contained in:
		| @@ -7,6 +7,7 @@ import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/hashicorp/vault/sdk/helper/consts" | ||||
| 	"github.com/hashicorp/vault/sdk/helper/strutil" | ||||
| ) | ||||
|  | ||||
| func TestRegisterPlugin(t *testing.T) { | ||||
| @@ -39,27 +40,78 @@ func TestListPlugins(t *testing.T) { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	resp, err := client.Sys().ListPluginsWithContext(context.Background(), &ListPluginsInput{}) | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	expectedPlugins := map[consts.PluginType][]string{ | ||||
| 		consts.PluginTypeCredential: {"alicloud"}, | ||||
| 		consts.PluginTypeDatabase:   {"cassandra-database-plugin"}, | ||||
| 		consts.PluginTypeSecrets:    {"ad", "alicloud"}, | ||||
| 	} | ||||
|  | ||||
| 	for pluginType, expected := range expectedPlugins { | ||||
| 		actualPlugins := resp.PluginsByType[pluginType] | ||||
| 		if len(expected) != len(actualPlugins) { | ||||
| 			t.Fatal("Wrong number of plugins", expected, actualPlugins) | ||||
| 		} | ||||
| 		for i := range actualPlugins { | ||||
| 			if expected[i] != actualPlugins[i] { | ||||
| 				t.Fatalf("Expected %q but got %q", expected[i], actualPlugins[i]) | ||||
| 	for name, tc := range map[string]struct { | ||||
| 		input           ListPluginsInput | ||||
| 		expectedPlugins map[consts.PluginType][]string | ||||
| 	}{ | ||||
| 		"no type specified": { | ||||
| 			input: ListPluginsInput{}, | ||||
| 			expectedPlugins: map[consts.PluginType][]string{ | ||||
| 				consts.PluginTypeCredential: {"alicloud"}, | ||||
| 				consts.PluginTypeDatabase:   {"cassandra-database-plugin"}, | ||||
| 				consts.PluginTypeSecrets:    {"ad", "alicloud"}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"only auth plugins": { | ||||
| 			input: ListPluginsInput{Type: consts.PluginTypeCredential}, | ||||
| 			expectedPlugins: map[consts.PluginType][]string{ | ||||
| 				consts.PluginTypeCredential: {"alicloud"}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"only database plugins": { | ||||
| 			input: ListPluginsInput{Type: consts.PluginTypeDatabase}, | ||||
| 			expectedPlugins: map[consts.PluginType][]string{ | ||||
| 				consts.PluginTypeDatabase: {"cassandra-database-plugin"}, | ||||
| 			}, | ||||
| 		}, | ||||
| 		"only secret plugins": { | ||||
| 			input: ListPluginsInput{Type: consts.PluginTypeSecrets}, | ||||
| 			expectedPlugins: map[consts.PluginType][]string{ | ||||
| 				consts.PluginTypeSecrets: {"ad", "alicloud"}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} { | ||||
| 		t.Run(name, func(t *testing.T) { | ||||
| 			resp, err := client.Sys().ListPluginsWithContext(context.Background(), &tc.input) | ||||
| 			if err != nil { | ||||
| 				t.Fatal(err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 			for pluginType, expected := range tc.expectedPlugins { | ||||
| 				actualPlugins := resp.PluginsByType[pluginType] | ||||
| 				if len(expected) != len(actualPlugins) { | ||||
| 					t.Fatal("Wrong number of plugins", expected, actualPlugins) | ||||
| 				} | ||||
| 				for i := range actualPlugins { | ||||
| 					if expected[i] != actualPlugins[i] { | ||||
| 						t.Fatalf("Expected %q but got %q", expected[i], actualPlugins[i]) | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 				for _, expectedPlugin := range expected { | ||||
| 					found := false | ||||
| 					for _, plugin := range resp.Details { | ||||
| 						if plugin.Type == pluginType.String() && plugin.Name == expectedPlugin { | ||||
| 							found = true | ||||
| 							break | ||||
| 						} | ||||
| 					} | ||||
| 					if !found { | ||||
| 						t.Errorf("Expected to find %s plugin %s but not found in details: %#v", pluginType.String(), expectedPlugin, resp.Details) | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			for _, actual := range resp.Details { | ||||
| 				pluginType, err := consts.ParsePluginType(actual.Type) | ||||
| 				if err != nil { | ||||
| 					t.Fatal(err) | ||||
| 				} | ||||
| 				if !strutil.StrListContains(tc.expectedPlugins[pluginType], actual.Name) { | ||||
| 					t.Errorf("Did not expect to find %s in details", actual.Name) | ||||
| 				} | ||||
| 			} | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -90,6 +142,36 @@ const listUntypedResponse = `{ | ||||
|       { | ||||
|         "arbitraryData": 7 | ||||
|       } | ||||
|     ], | ||||
|     "detailed": [ | ||||
|       { | ||||
|         "type": "auth", | ||||
|         "name": "alicloud", | ||||
|         "version": "v0.13.0+builtin", | ||||
|         "builtin": true, | ||||
|         "deprecation_status": "supported" | ||||
|       }, | ||||
|       { | ||||
|         "type": "database", | ||||
|         "name": "cassandra-database-plugin", | ||||
|         "version": "v1.13.0+builtin.vault", | ||||
|         "builtin": true, | ||||
|         "deprecation_status": "supported" | ||||
|       }, | ||||
|       { | ||||
|         "type": "secret", | ||||
|         "name": "ad", | ||||
|         "version": "v0.14.0+builtin", | ||||
|         "builtin": true, | ||||
|         "deprecation_status": "supported" | ||||
|       }, | ||||
|       { | ||||
|         "type": "secret", | ||||
|         "name": "alicloud", | ||||
|         "version": "v0.13.0+builtin", | ||||
|         "builtin": true, | ||||
|         "deprecation_status": "supported" | ||||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   "wrap_info": null, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Tom Proctor
					Tom Proctor