mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-06 14:47:01 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package command
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
)
|
|
|
|
// testPluginCreate creates a sample plugin in a tempdir and returns the shasum
|
|
// and filepath to the plugin.
|
|
func testPluginCreate(tb testing.TB, dir, name string) (string, string) {
|
|
tb.Helper()
|
|
|
|
pth := dir + "/" + name
|
|
if err := ioutil.WriteFile(pth, nil, 0o755); err != nil {
|
|
tb.Fatal(err)
|
|
}
|
|
|
|
f, err := os.Open(pth)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
h := sha256.New()
|
|
if _, err := io.Copy(h, f); err != nil {
|
|
tb.Fatal(err)
|
|
}
|
|
sha256Sum := fmt.Sprintf("%x", h.Sum(nil))
|
|
|
|
return pth, sha256Sum
|
|
}
|
|
|
|
// testPluginCreateAndRegister creates a plugin and registers it in the catalog.
|
|
func testPluginCreateAndRegister(tb testing.TB, client *api.Client, dir, name string, pluginType api.PluginType, version string) (string, string) {
|
|
tb.Helper()
|
|
|
|
pth, sha256Sum := testPluginCreate(tb, dir, name)
|
|
|
|
if err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{
|
|
Name: name,
|
|
Type: pluginType,
|
|
Command: name,
|
|
SHA256: sha256Sum,
|
|
Version: version,
|
|
}); err != nil {
|
|
tb.Fatal(err)
|
|
}
|
|
|
|
return pth, sha256Sum
|
|
}
|
|
|
|
// testPluginCreateAndRegisterVersioned creates a versioned plugin and registers it in the catalog.
|
|
func testPluginCreateAndRegisterVersioned(tb testing.TB, client *api.Client, dir, name string, pluginType api.PluginType) (string, string, string) {
|
|
tb.Helper()
|
|
|
|
pth, sha256Sum := testPluginCreate(tb, dir, name)
|
|
|
|
if err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{
|
|
Name: name,
|
|
Type: pluginType,
|
|
Command: name,
|
|
SHA256: sha256Sum,
|
|
Version: "v1.0.0",
|
|
}); err != nil {
|
|
tb.Fatal(err)
|
|
}
|
|
|
|
return pth, sha256Sum, "v1.0.0"
|
|
}
|