|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: BUSL-1.1 |
| 3 | + |
| 4 | +//go:build !enterprise |
| 5 | + |
| 6 | +package vault |
| 7 | + |
| 8 | +import ( |
| 9 | + "fmt" |
| 10 | + "os" |
| 11 | + "path/filepath" |
| 12 | + "testing" |
| 13 | + |
| 14 | + "github.com/hashicorp/vault/helper/namespace" |
| 15 | + "github.com/hashicorp/vault/sdk/helper/consts" |
| 16 | + "github.com/hashicorp/vault/sdk/logical" |
| 17 | +) |
| 18 | + |
| 19 | +// TestSystemBackend_PluginCatalog_Update_Download_Fails tests the update failure |
| 20 | +// case when download is true |
| 21 | +func TestSystemBackend_PluginCatalog_Update_Download_Should_Fail(t *testing.T) { |
| 22 | + sym, err := filepath.EvalSymlinks(os.TempDir()) |
| 23 | + if err != nil { |
| 24 | + t.Fatalf("error: %v", err) |
| 25 | + } |
| 26 | + c, _, _ := TestCoreUnsealedWithConfig(t, &CoreConfig{ |
| 27 | + PluginDirectory: sym, |
| 28 | + }) |
| 29 | + b := c.systemBackend |
| 30 | + |
| 31 | + tests := []struct { |
| 32 | + pluginType consts.PluginType |
| 33 | + pluginVersion string |
| 34 | + pluginName string |
| 35 | + }{ |
| 36 | + { |
| 37 | + pluginName: "vault-plugin-database-redis", |
| 38 | + pluginVersion: "v0.6.0", |
| 39 | + pluginType: consts.PluginTypeDatabase, |
| 40 | + }, |
| 41 | + { |
| 42 | + pluginName: "vault-plugin-secrets-kv", |
| 43 | + pluginVersion: "v0.24.0", |
| 44 | + pluginType: consts.PluginTypeSecrets, |
| 45 | + }, |
| 46 | + { |
| 47 | + pluginName: "vault-plugin-auth-jwt", |
| 48 | + pluginVersion: "v0.24.1", |
| 49 | + pluginType: consts.PluginTypeCredential, |
| 50 | + }, |
| 51 | + } |
| 52 | + |
| 53 | + for _, tt := range tests { |
| 54 | + t.Run(fmt.Sprintf("%s %s", tt.pluginName, tt.pluginVersion), func(t *testing.T) { |
| 55 | + req := logical.TestRequest(t, logical.UpdateOperation, |
| 56 | + "plugins/catalog/"+tt.pluginType.String()+"/"+tt.pluginName) |
| 57 | + req.Data["version"] = tt.pluginVersion |
| 58 | + req.Data["download"] = true |
| 59 | + resp, err := b.HandleRequest(namespace.RootContext(nil), req) |
| 60 | + if err != nil || resp.Error() == nil { |
| 61 | + t.Fatalf("expected error when download is true, got resp: %v, err: %v", resp, err) |
| 62 | + } |
| 63 | + }) |
| 64 | + } |
| 65 | +} |
0 commit comments