mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Plugins: Add -version flag to 'vault plugin info' (#17454)
* Add -version flag to 'vault plugin info' * Allow specifying a builtin tag when reading a single plugin from the catalog
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/sdk/helper/consts"
|
||||
@@ -115,6 +116,141 @@ func TestListPlugins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPlugin(t *testing.T) {
|
||||
for name, tc := range map[string]struct {
|
||||
version string
|
||||
body string
|
||||
expected GetPluginResponse
|
||||
}{
|
||||
"builtin": {
|
||||
body: getResponse,
|
||||
expected: GetPluginResponse{
|
||||
Args: nil,
|
||||
Builtin: true,
|
||||
Command: "",
|
||||
Name: "azure",
|
||||
SHA256: "",
|
||||
DeprecationStatus: "supported",
|
||||
Version: "v0.14.0+builtin",
|
||||
},
|
||||
},
|
||||
"external": {
|
||||
version: "v1.0.0",
|
||||
body: getResponseExternal,
|
||||
expected: GetPluginResponse{
|
||||
Args: []string{},
|
||||
Builtin: false,
|
||||
Command: "azure-plugin",
|
||||
Name: "azure",
|
||||
SHA256: "8ba442dba253803685b05e35ad29dcdebc48dec16774614aa7a4ebe53c1e90e1",
|
||||
DeprecationStatus: "",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
"old server": {
|
||||
body: getResponseOldServerVersion,
|
||||
expected: GetPluginResponse{
|
||||
Args: nil,
|
||||
Builtin: true,
|
||||
Command: "",
|
||||
Name: "azure",
|
||||
SHA256: "",
|
||||
DeprecationStatus: "",
|
||||
Version: "",
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mockVaultServer := httptest.NewServer(http.HandlerFunc(mockVaultHandlerInfo(tc.body)))
|
||||
defer mockVaultServer.Close()
|
||||
|
||||
cfg := DefaultConfig()
|
||||
cfg.Address = mockVaultServer.URL
|
||||
client, err := NewClient(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
input := GetPluginInput{
|
||||
Name: "azure",
|
||||
Type: consts.PluginTypeSecrets,
|
||||
}
|
||||
if tc.version != "" {
|
||||
input.Version = tc.version
|
||||
}
|
||||
|
||||
info, err := client.Sys().GetPluginWithContext(context.Background(), &input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tc.expected, *info) {
|
||||
t.Errorf("expected: %#v\ngot: %#v", tc.expected, info)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func mockVaultHandlerInfo(body string) func(w http.ResponseWriter, _ *http.Request) {
|
||||
return func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte(body))
|
||||
}
|
||||
}
|
||||
|
||||
const getResponse = `{
|
||||
"request_id": "e93d3f93-8e4f-8443-a803-f1c97c495241",
|
||||
"lease_id": "",
|
||||
"renewable": false,
|
||||
"lease_duration": 0,
|
||||
"data": {
|
||||
"args": null,
|
||||
"builtin": true,
|
||||
"command": "",
|
||||
"deprecation_status": "supported",
|
||||
"name": "azure",
|
||||
"sha256": "",
|
||||
"version": "v0.14.0+builtin"
|
||||
},
|
||||
"wrap_info": null,
|
||||
"warnings": null,
|
||||
"auth": null
|
||||
}`
|
||||
|
||||
const getResponseExternal = `{
|
||||
"request_id": "e93d3f93-8e4f-8443-a803-f1c97c495241",
|
||||
"lease_id": "",
|
||||
"renewable": false,
|
||||
"lease_duration": 0,
|
||||
"data": {
|
||||
"args": [],
|
||||
"builtin": false,
|
||||
"command": "azure-plugin",
|
||||
"name": "azure",
|
||||
"sha256": "8ba442dba253803685b05e35ad29dcdebc48dec16774614aa7a4ebe53c1e90e1",
|
||||
"version": "v1.0.0"
|
||||
},
|
||||
"wrap_info": null,
|
||||
"warnings": null,
|
||||
"auth": null
|
||||
}`
|
||||
|
||||
const getResponseOldServerVersion = `{
|
||||
"request_id": "e93d3f93-8e4f-8443-a803-f1c97c495241",
|
||||
"lease_id": "",
|
||||
"renewable": false,
|
||||
"lease_duration": 0,
|
||||
"data": {
|
||||
"args": null,
|
||||
"builtin": true,
|
||||
"command": "",
|
||||
"name": "azure",
|
||||
"sha256": ""
|
||||
},
|
||||
"wrap_info": null,
|
||||
"warnings": null,
|
||||
"auth": null
|
||||
}`
|
||||
|
||||
func mockVaultHandlerList(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte(listUntypedResponse))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user