Files
vault/physical/alicloudoss/alicloudoss_test.go
hashicorp-copywrite[bot] 0b12cdcfd1 [COMPLIANCE] License changes (#22290)
* 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>
2023-08-10 18:14:03 -07:00

85 lines
1.9 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package alicloudoss
import (
"fmt"
"math/rand"
"os"
"testing"
"time"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/sdk/helper/logging"
"github.com/hashicorp/vault/sdk/physical"
)
func TestAliCloudOSSBackend(t *testing.T) {
// ex. http://oss-us-east-1.aliyuncs.com
endpoint := os.Getenv(AlibabaCloudOSSEndpointEnv)
accessKeyID := os.Getenv(AlibabaCloudAccessKeyEnv)
accessKeySecret := os.Getenv(AlibabaCloudSecretKeyEnv)
if endpoint == "" || accessKeyID == "" || accessKeySecret == "" {
t.SkipNow()
}
conn, err := oss.New(endpoint, accessKeyID, accessKeySecret)
if err != nil {
t.Fatalf("unable to create test client: %s", err)
}
randInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
bucket := fmt.Sprintf("vault-alibaba-testacc-%d", randInt)
err = conn.CreateBucket(bucket)
if err != nil {
t.Fatalf("unable to create test bucket: %s", err)
}
defer func() {
// Gotta list all the objects and delete them
// before being able to delete the bucket
b, err := conn.Bucket(bucket)
if err != nil {
t.Fatalf("err: %s", err)
}
listResp, err := b.ListObjects()
if err != nil {
t.Fatalf("err: %s", err)
}
objects := []string{}
for _, object := range listResp.Objects {
objects = append(objects, object.Key)
}
_, err = b.DeleteObjects(objects)
if err != nil {
t.Fatalf("err: %s", err)
}
err = conn.DeleteBucket(bucket)
if err != nil {
t.Fatalf("err: %s", err)
}
}()
logger := logging.NewVaultLogger(log.Debug)
// This uses the same logic to find the Alibaba credentials as we did at the beginning of the test
b, err := NewAliCloudOSSBackend(
map[string]string{"bucket": bucket},
logger,
)
if err != nil {
t.Fatalf("err: %s", err)
}
physical.ExerciseBackend(t, b)
physical.ExerciseBackend_ListPrefix(t, b)
}