Adding bucket encryption test (#1687)
This commit is contained in:
committed by
GitHub
parent
3186c1a0d0
commit
414db326bb
2
Makefile
2
Makefile
@@ -72,7 +72,7 @@ test-integration:
|
||||
@(docker network create --subnet=173.18.0.0/29 mynet123)
|
||||
@echo "docker run with MinIO Version below:"
|
||||
@echo $(MINIO_VERSION)
|
||||
@(docker run -v /data1 -v /data2 -v /data3 -v /data4 --net=mynet123 -d --name minio --rm -p 9000:9000 $(MINIO_VERSION) server /data{1...4} && sleep 5)
|
||||
@(docker run -v /data1 -v /data2 -v /data3 -v /data4 --net=mynet123 -d --name minio --rm -p 9000:9000 -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= $(MINIO_VERSION) server /data{1...4} && sleep 5)
|
||||
@(docker run --net=mynet123 --ip=173.18.0.3 --name pgsqlcontainer --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres && sleep 5)
|
||||
@echo "execute test and get coverage"
|
||||
@(cd integration && go test -coverpkg=../restapi -c -tags testrunmain . && mkdir -p coverage && ./integration.test -test.run "^Test*" -test.coverprofile=coverage/system.out)
|
||||
|
||||
@@ -2941,3 +2941,65 @@ func TestSetBucketVersioning(t *testing.T) {
|
||||
}
|
||||
assert.Equal(false, result.IsVersioned, result)
|
||||
}
|
||||
|
||||
func EnableBucketEncryption(bucketName string, encType string, kmsKeyID string) (*http.Response, error) {
|
||||
/*
|
||||
Helper function to enable bucket encryption
|
||||
HTTP Verb: POST
|
||||
URL: /buckets/{bucket_name}/encryption/enable
|
||||
Body:
|
||||
{
|
||||
"encType":"sse-s3",
|
||||
"kmsKeyID":""
|
||||
}
|
||||
*/
|
||||
requestDataAdd := map[string]interface{}{
|
||||
"encType": encType,
|
||||
"kmsKeyID": kmsKeyID,
|
||||
}
|
||||
requestDataJSON, _ := json.Marshal(requestDataAdd)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"POST", "http://localhost:9090/api/v1/buckets/"+bucketName+"/encryption/enable", requestDataBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
// Performing the call
|
||||
client := &http.Client{
|
||||
Timeout: 2 * time.Second,
|
||||
}
|
||||
response, err := client.Do(request)
|
||||
return response, err
|
||||
}
|
||||
|
||||
func TestEnableBucketEncryption(t *testing.T) {
|
||||
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "test-enable-bucket-encryption"
|
||||
locking := false
|
||||
versioning := false
|
||||
encType := "sse-s3"
|
||||
kmsKeyID := ""
|
||||
|
||||
// 1. Add bucket
|
||||
if !BucketGotAdded(bucketName, locking, versioning, nil, nil, assert, 201) {
|
||||
return
|
||||
}
|
||||
|
||||
// 2. Enable Bucket's Encryption
|
||||
resp, err := EnableBucketEncryption(bucketName, encType, kmsKeyID)
|
||||
assert.Nil(err)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
if resp != nil {
|
||||
assert.Equal(
|
||||
200, resp.StatusCode, "Status Code is incorrect")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user