From d7626e187cb488333c23c21b0b2626a3f6634133 Mon Sep 17 00:00:00 2001 From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Date: Thu, 17 Mar 2022 12:15:06 -0700 Subject: [PATCH] Integration Test: Create Service Account (#1725) Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> --- Makefile | 8 +- integration/admin_api_integration_test.go | 8 +- integration/buckets_test.go | 35 +----- integration/login_test.go | 4 +- integration/service_account_test.go | 116 +++++++++++++++++- integration/user_api_bucket_test.go | 143 +++++++++++----------- integration/users_test.go | 42 +++---- integration/version_test.go | 75 ++++++++++++ operator-integration/tenant_test.go | 13 +- 9 files changed, 295 insertions(+), 149 deletions(-) create mode 100644 integration/version_test.go diff --git a/Makefile b/Makefile index ab894a5f9..1f92b3b5d 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ test-integration: @(docker run -v /data1 -v /data2 -v /data3 -v /data4 --net=mynet123 -d --name minio --rm -p 9000:9000 -p 9001:9001 -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= $(MINIO_VERSION) server /data{1...4} --console-address ':9001' && 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) + @(cd integration && go test -coverpkg=../restapi -c -tags testrunmain . && mkdir -p coverage && ./integration.test -test.v -test.run "^Test*" -test.coverprofile=coverage/system.out) @(docker stop pgsqlcontainer) @(docker stop minio) @(docker network rm mynet123) @@ -83,7 +83,7 @@ test-integration: test-operator-integration: @(echo "Start cd operator-integration && go test:") @(pwd) - @(cd operator-integration && go test -coverpkg=../restapi -c -tags testrunmain . && mkdir -p coverage && ./operator-integration.test -test.run "^Test*" -test.coverprofile=coverage/operator-api.out) + @(cd operator-integration && go test -coverpkg=../restapi -c -tags testrunmain . && mkdir -p coverage && ./operator-integration.test -test.v -test.run "^Test*" -test.coverprofile=coverage/operator-api.out) test-operator: @(env bash $(PWD)/portal-ui/tests/scripts/operator.sh) @@ -112,11 +112,11 @@ cleanup-permissions: test: @echo "execute test and get coverage" - @(cd restapi && mkdir coverage && GO111MODULE=on go test -coverprofile=coverage/coverage.out) + @(cd restapi && mkdir coverage && GO111MODULE=on go test -test.v -coverprofile=coverage/coverage.out) test-pkg: @echo "execute test and get coverage" - @(cd pkg && mkdir coverage && GO111MODULE=on go test -coverprofile=coverage/coverage-pkg.out) + @(cd pkg && mkdir coverage && GO111MODULE=on go test -test.v -coverprofile=coverage/coverage-pkg.out) coverage: @(GO111MODULE=on go test -v -coverprofile=coverage.out github.com/minio/console/restapi/... && go tool cover -html=coverage.out && open coverage.html) diff --git a/integration/admin_api_integration_test.go b/integration/admin_api_integration_test.go index 2eed7f055..bf6770fa3 100644 --- a/integration/admin_api_integration_test.go +++ b/integration/admin_api_integration_test.go @@ -131,7 +131,7 @@ func NotifyPostgres() (*http.Response, error) { } func TestNotifyPostgres(t *testing.T) { - printStartFunc("TestNotifyPostgres") + // Variables assert := assert.New(t) @@ -147,11 +147,11 @@ func TestNotifyPostgres(t *testing.T) { if response != nil { assert.Equal(200, response.StatusCode, finalResponse) } - printEndFunc("TestNotifyPostgres") + } func TestRestartService(t *testing.T) { - printStartFunc("TestRestartService") + assert := assert.New(t) restartResponse, restartError := RestartService() assert.Nil(restartError) @@ -167,5 +167,5 @@ func TestRestartService(t *testing.T) { addObjRsp, ) } - printEndFunc("TestRestartService") + } diff --git a/integration/buckets_test.go b/integration/buckets_test.go index 090236a72..4c2d293bd 100644 --- a/integration/buckets_test.go +++ b/integration/buckets_test.go @@ -55,37 +55,6 @@ func inspectHTTPResponse(httpResponse *http.Response) string { return "Http Response: " + string(b) } -func printMessage(message string) { - /* - Helper function to print HTTP response. - */ - fmt.Println(message) -} - -func printLoggingMessage(message string, functionName string) { - /* - Helper function to have standard output across the tests. - */ - finalString := "......................." + functionName + "(): " + message - printMessage(finalString) -} - -func printStartFunc(functionName string) { - /* - Common function for all tests to tell that test has started - */ - printMessage("") - printLoggingMessage("started", functionName) -} - -func printEndFunc(functionName string) { - /* - Helper function for all tests to tell that test has ended, is completed - */ - printLoggingMessage("completed", functionName) - printMessage("") -} - func initConsoleServer() (*restapi.Server, error) { //os.Setenv("CONSOLE_MINIO_SERVER", "localhost:9000") @@ -123,7 +92,7 @@ func initConsoleServer() (*restapi.Server, error) { } func TestMain(m *testing.M) { - printStartFunc("TestMain") + // start console server go func() { fmt.Println("start server") @@ -212,6 +181,6 @@ func TestMain(m *testing.M) { if response != nil { fmt.Println("DELETE StatusCode:", response.StatusCode) } - printEndFunc("TestMain") + os.Exit(code) } diff --git a/integration/login_test.go b/integration/login_test.go index 6d0d0b993..5e570e9a5 100644 --- a/integration/login_test.go +++ b/integration/login_test.go @@ -30,7 +30,7 @@ import ( ) func TestLoginStrategy(t *testing.T) { - printStartFunc("TestLoginStrategy") + assert := assert.New(t) // image for now: @@ -68,5 +68,5 @@ func TestLoginStrategy(t *testing.T) { assert.Equal(models.LoginDetailsLoginStrategyForm, loginDetails.LoginStrategy, "Login Details don't match") } - printEndFunc("TestLoginStrategy") + } diff --git a/integration/service_account_test.go b/integration/service_account_test.go index c42d520b8..7324392d4 100644 --- a/integration/service_account_test.go +++ b/integration/service_account_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "github.com/go-openapi/swag" + iampolicy "github.com/minio/pkg/iam/policy" "github.com/stretchr/testify/assert" ) @@ -38,7 +40,7 @@ func TestAddServiceAccount(t *testing.T) { tests like users.ts can run over clean data and we don't collide against it. */ - printStartFunc("TestAddServiceAccount") + assert := assert.New(t) client := &http.Client{ @@ -159,5 +161,115 @@ func TestAddServiceAccount(t *testing.T) { fmt.Println("DELETE StatusCode:", response.StatusCode) assert.Equal(204, response.StatusCode, "has to be 204 when delete user") } - printEndFunc("TestAddServiceAccount") + +} + +func Test_ServiceAccountsAPI(t *testing.T) { + assert := assert.New(t) + + type args struct { + api string + policy *string + } + tests := []struct { + name string + args args + expectedStatus int + expectedError error + }{ + { + name: "Create Service Account - Default", + args: args{ + api: "/service-accounts", + policy: nil, + }, + expectedStatus: 201, + expectedError: nil, + }, + { + name: "Create Service Account - Valid Policy", + args: args{ + api: "/service-accounts", + policy: swag.String(` + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetBucketLocation", + "s3:GetObject" + ], + "Resource": [ + "arn:aws:s3:::*" + ] + } + ] +}`), + }, + expectedStatus: 201, + expectedError: nil, + }, + { + name: "Create Service Account - Invalid Policy", + args: args{ + api: "/service-accounts", + policy: swag.String(` + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetBucketLocation" + "s3:GetObject" + ], + "Resource": [ + "arn:aws:s3:::*" + ] + } + ] +}`), + }, + expectedStatus: 500, + expectedError: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + client := &http.Client{ + Timeout: 3 * time.Second, + } + + // Add service account + + requestDataPolicy := map[string]interface{}{} + if tt.args.policy != nil { + requestDataPolicy["policy"] = *tt.args.policy + } + + requestDataJSON, _ := json.Marshal(requestDataPolicy) + requestDataBody := bytes.NewReader(requestDataJSON) + request, err := http.NewRequest( + "POST", fmt.Sprintf("http://localhost:9090/api/v1%s", tt.args.api), requestDataBody) + if err != nil { + log.Println(err) + return + } + request.Header.Add("Cookie", fmt.Sprintf("token=%s", token)) + request.Header.Add("Content-Type", "application/json") + response, err := client.Do(request) + if err != nil { + log.Println(err) + return + } + if response != nil { + assert.Equal(tt.expectedStatus, response.StatusCode, "Status Code is incorrect") + } + + }) + } + } diff --git a/integration/user_api_bucket_test.go b/integration/user_api_bucket_test.go index b55bdfe81..41168f57a 100644 --- a/integration/user_api_bucket_test.go +++ b/integration/user_api_bucket_test.go @@ -654,7 +654,7 @@ func PutObjectsLegalholdStatus(bucketName string, prefix string, status string, } func TestPutObjectsLegalholdStatus(t *testing.T) { - printStartFunc("TestPutObjectsLegalholdStatus") + // Variables assert := assert.New(t) bucketName := "testputobjectslegalholdstatus" @@ -742,11 +742,11 @@ func TestPutObjectsLegalholdStatus(t *testing.T) { } }) } - printEndFunc("TestPutObjectsLegalholdStatus") + } func TestGetBucketQuota(t *testing.T) { - printStartFunc("TestGetBucketQuota") + // Variables assert := assert.New(t) validBucket := "testgetbucketquota" @@ -821,11 +821,11 @@ func TestGetBucketQuota(t *testing.T) { } }) } - printEndFunc("TestGetBucketQuota") + } func TestPutBucketQuota(t *testing.T) { - printStartFunc("TestPutBucketQuota") + // Variables assert := assert.New(t) validBucket := "testputbucketquota" @@ -882,11 +882,11 @@ func TestPutBucketQuota(t *testing.T) { } }) } - printEndFunc("TestPutBucketQuota") + } func TestListBucketEvents(t *testing.T) { - printStartFunc("TestListBucketEvents") + // Variables assert := assert.New(t) validBucket := "testlistbucketevents" @@ -942,11 +942,11 @@ func TestListBucketEvents(t *testing.T) { }) } - printEndFunc("TestListBucketEvents") + } func TestDeleteObjectsRetentionStatus(t *testing.T) { - printStartFunc("TestDeleteObjectsRetentionStatus") + // Variables assert := assert.New(t) bucketName := "testdeleteobjectslegalholdstatus" @@ -1053,11 +1053,11 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) { } }) } - printEndFunc("TestDeleteObjectsRetentionStatus") + } func TestBucketSetPolicy(t *testing.T) { - printStartFunc("TestBucketSetPolicy") + // Variables assert := assert.New(t) validBucketName := "testbucketsetpolicy" @@ -1116,11 +1116,11 @@ func TestBucketSetPolicy(t *testing.T) { }) } - printEndFunc("TestBucketSetPolicy") + } func TestRestoreObjectToASelectedVersion(t *testing.T) { - printStartFunc("TestRestoreObjectToASelectedVersion") + // Variables assert := assert.New(t) bucketName := "testrestoreobjectstoselectedversion" @@ -1208,11 +1208,11 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) { } }) } - printEndFunc("TestRestoreObjectToASelectedVersion") + } func TestPutBucketsTags(t *testing.T) { - printStartFunc("TestPutBucketsTags") + // Focused test for "Put Bucket's tags" endpoint // 1. Create the bucket @@ -1266,11 +1266,11 @@ func TestPutBucketsTags(t *testing.T) { }) } - printEndFunc("TestPutBucketsTags") + } func TestGetsTheMetadataOfAnObject(t *testing.T) { - printStartFunc("TestGetsTheMetadataOfAnObject") + // Vars assert := assert.New(t) bucketName := "testgetsthemetadataofanobject" @@ -1343,11 +1343,11 @@ func TestGetsTheMetadataOfAnObject(t *testing.T) { }) } - printEndFunc("TestGetsTheMetadataOfAnObject") + } func TestPutObjectsRetentionStatus(t *testing.T) { - printStartFunc("TestPutObjectsRetentionStatus") + // Variables assert := assert.New(t) bucketName := "testputobjectsretentionstatus" @@ -1436,14 +1436,14 @@ func TestPutObjectsRetentionStatus(t *testing.T) { } }) } - printEndFunc("TestPutObjectsRetentionStatus") + } func TestShareObjectOnURL(t *testing.T) { /* Test to share an object via URL */ - printStartFunc("TestShareObjectOnURL") + // Vars assert := assert.New(t) bucketName := "testshareobjectonurl" @@ -1517,14 +1517,14 @@ func TestShareObjectOnURL(t *testing.T) { }) } - printEndFunc("TestShareObjectOnURL") + } func TestListObjects(t *testing.T) { /* To test list objects end point. */ - printStartFunc("TestListObjects") + // Test's variables assert := assert.New(t) bucketName := "testlistobjecttobucket1" @@ -1564,14 +1564,14 @@ func TestListObjects(t *testing.T) { assert.True( strings.Contains(finalResponse, "testlistobjecttobucket1"), finalResponse) - printEndFunc("TestListObjects") + } func TestDeleteObject(t *testing.T) { /* Test to delete an object from a given bucket. */ - printStartFunc("TestDeleteObject") + // Variables assert := assert.New(t) bucketName := "testdeleteobjectbucket1" @@ -1633,14 +1633,14 @@ func TestDeleteObject(t *testing.T) { strings.Contains( finalResponse, "testdeleteobjectfile1.txt"), finalResponse) // Gone - printEndFunc("TestDeleteObject") + } func TestUploadObjectToBucket(t *testing.T) { /* Function to test the upload of an object to a bucket. */ - printStartFunc("TestUploadObjectToBucket") + // Test's variables assert := assert.New(t) bucketName := "testuploadobjecttobucket1" @@ -1664,14 +1664,14 @@ func TestUploadObjectToBucket(t *testing.T) { if uploadResponse != nil { assert.Equal(200, uploadResponse.StatusCode, finalResponse) } - printEndFunc("TestUploadObjectToBucket") + } func TestDownloadObject(t *testing.T) { /* Test to download an object from a given bucket. */ - printStartFunc("TestDownloadObject") + // Vars assert := assert.New(t) bucketName := "testdownloadobjbucketone" @@ -1731,14 +1731,14 @@ func TestDownloadObject(t *testing.T) { // path/to/whatever does not exist assert.Fail("File wasn't downloaded") } - printEndFunc("TestDownloadObject") + } func TestDeleteMultipleObjects(t *testing.T) { /* Function to test the deletion of multiple objects from a given bucket. */ - printStartFunc("TestDeleteMultipleObjects") + // Variables assert := assert.New(t) bucketName := "testdeletemultipleobjsbucket1" @@ -1806,14 +1806,14 @@ func TestDeleteMultipleObjects(t *testing.T) { // 5. Verify empty list is obtained as we deleted all the objects expected := "Http Response: {\"objects\":null}\n" assert.Equal(expected, finalResponse, finalResponse) - printEndFunc("TestDeleteMultipleObjects") + } func TestPutObjectTag(t *testing.T) { /* Test to put a tag to an object */ - printStartFunc("TestPutObjectTag") + // Vars assert := assert.New(t) bucketName := "testputobjecttagbucketone" @@ -1872,14 +1872,14 @@ func TestPutObjectTag(t *testing.T) { assert.True( strings.Contains(finalResponse, tags["tag"]), finalResponse) - printEndFunc("TestPutObjectTag") + } func TestBucketRetention(t *testing.T) { /* To test bucket retention feature */ - printStartFunc("TestBucketRetention") + // 1. Create the bucket with 2 years validity retention assert := assert.New(t) /* @@ -1941,14 +1941,14 @@ func TestBucketRetention(t *testing.T) { } expected := "Http Response: {\"mode\":\"compliance\",\"unit\":\"years\",\"validity\":3}\n" assert.Equal(expected, finalResponse, finalResponse) - printEndFunc("TestBucketRetention") + } func TestBucketInformationGenericErrorResponse(t *testing.T) { /* Test Bucket Info End Point with a Generic Error Response. */ - printStartFunc("TestBucketInformationGenericErrorResponse") + // 1. Create the bucket assert := assert.New(t) if !BucketGotAdded("bucketinformation2", false, false, nil, nil, assert, 201) { @@ -1987,14 +1987,14 @@ func TestBucketInformationGenericErrorResponse(t *testing.T) { // Since bucketinformation3 hasn't been created, then it is expected that // tag2 is not part of the response, this is why assert.False is used. assert.False(strings.Contains(finalResponse, "tag2"), finalResponse) - printEndFunc("TestBucketInformationGenericErrorResponse") + } func TestBucketInformationSuccessfulResponse(t *testing.T) { /* Test Bucket Info End Point with a Successful Response. */ - printStartFunc("TestBucketInformationSuccessfulResponse") + // 1. Create the bucket assert := assert.New(t) if !BucketGotAdded("bucketinformation1", false, false, nil, nil, assert, 201) { @@ -2029,7 +2029,7 @@ func TestBucketInformationSuccessfulResponse(t *testing.T) { assert.Equal(200, bucketInfoResponse.StatusCode, debugResponse) } - printMessage(debugResponse) + fmt.Println(debugResponse) // 4. Verify the information assert.True( @@ -2038,14 +2038,14 @@ func TestBucketInformationSuccessfulResponse(t *testing.T) { assert.True( strings.Contains(debugResponse, "tag1"), inspectHTTPResponse(bucketInfoResponse)) - printEndFunc("TestBucketInformationSuccessfulResponse") + } func TestDeleteBucket(t *testing.T) { /* Test to delete a bucket */ - printStartFunc("TestDeleteBucket") + // 1. Create the bucket assert := assert.New(t) if !BucketGotAdded("testdeletebucket1", false, false, nil, nil, assert, 201) { @@ -2082,14 +2082,14 @@ func TestDeleteBucket(t *testing.T) { } assert.True( strings.Contains(finalResponse, "The specified bucket does not exist")) - printEndFunc("TestDeleteBucket") + } func TestListBuckets(t *testing.T) { /* Test the list of buckets without query parameters. */ - printStartFunc("TestListBuckets") + assert := assert.New(t) // 1. Create buckets @@ -2122,11 +2122,11 @@ func TestListBuckets(t *testing.T) { assert.True(strings.Contains(string(b), "testlistbuckets"+strconv.Itoa(i))) } - printEndFunc("TestListBuckets") + } func TestBucketsGet(t *testing.T) { - printStartFunc("TestListBuckets") + assert := assert.New(t) client := &http.Client{ @@ -2164,11 +2164,11 @@ func TestBucketsGet(t *testing.T) { assert.Greater(listBuckets.Total, int64(0), "Total buckets is 0") } - printEndFunc("TestListBuckets") + } func TestBucketVersioning(t *testing.T) { - printStartFunc("TestBucketVersioning") + assert := assert.New(t) client := &http.Client{ @@ -2268,11 +2268,11 @@ func TestBucketVersioning(t *testing.T) { if response != nil { fmt.Println("DELETE StatusCode:", response.StatusCode) } - printEndFunc("TestBucketVersioning") + } func TestSetBucketTags(t *testing.T) { - printStartFunc("TestSetBucketTags") + assert := assert.New(t) client := &http.Client{ @@ -2338,11 +2338,11 @@ func TestSetBucketTags(t *testing.T) { } assert.Equal("TAG", bucket.Details.Tags["test"], "Failed to add tag") - printEndFunc("TestSetBucketTags") + } func TestGetBucket(t *testing.T) { - printStartFunc("TestGetBucket") + assert := assert.New(t) client := &http.Client{ @@ -2373,11 +2373,11 @@ func TestGetBucket(t *testing.T) { if response != nil { assert.Equal(200, response.StatusCode, "Status Code is incorrect") } - printEndFunc("TestGetBucket") + } func TestAddBucket(t *testing.T) { - printStartFunc("TestAddBucket") + assert := assert.New(t) type args struct { bucketName string @@ -2409,7 +2409,7 @@ func TestAddBucket(t *testing.T) { } }) } - printEndFunc("TestAddBucket") + } func CreateBucketEvent(bucketName string, ignoreExisting bool, arn string, prefix string, suffix string, events []string) (*http.Response, error) { @@ -2491,7 +2491,7 @@ func DeleteBucketEvent(bucketName string, arn string, events []string, prefix st } func TestDeleteBucketEvent(t *testing.T) { - printStartFunc("TestDeleteBucketEvent") + // Variables assert := assert.New(t) @@ -2571,7 +2571,7 @@ func TestDeleteBucketEvent(t *testing.T) { efinalResponseEvent, ) } - printEndFunc("TestDeleteBucketEvent") + } func SetMultiBucketReplication(accessKey string, secretKey string, targetURL string, region string, originBucket string, destinationBucket string, syncMode string, bandwidth int, healthCheckPeriod int, prefix string, tags string, replicateDeleteMarkers bool, replicateDeletes bool, priority int, storageClass string, replicateMetadata bool) (*http.Response, error) { @@ -2712,7 +2712,7 @@ func DeleteBucketReplicationRule(bucketName string, ruleID string) (*http.Respon } func TestReplication(t *testing.T) { - printStartFunc("TestReplication") + // Vars assert := assert.New(t) originBucket := "testputobjectslegalholdstatus" @@ -2770,6 +2770,10 @@ func TestReplication(t *testing.T) { assert.Nil(err) } + assert.Greater(len(structBucketRepl.Rules), 0, "Number of expected rules is 0") + if len(structBucketRepl.Rules) == 0 { + return + } // 4. Verify rules are enabled for index := 0; index < 2; index++ { Status := structBucketRepl.Rules[index].Status @@ -2807,7 +2811,7 @@ func TestReplication(t *testing.T) { if response != nil { assert.Equal(204, response.StatusCode, finalResponse) } - printEndFunc("TestReplication") + } func GetBucketVersioning(bucketName string) (*http.Response, error) { @@ -2846,7 +2850,7 @@ func BaseGetFunction(bucketName string, endPoint string) (*http.Response, error) func TestReturnsTheStatusOfObjectLockingSupportOnTheBucket(t *testing.T) { // Test for end point: /buckets/{bucket_name}/object-locking - printStartFunc("TestReturnsTheStatusOfObjectLockingSupportOnTheBucket") + // Vars assert := assert.New(t) bucketName := "testputobjectslegalholdstatus" @@ -2877,7 +2881,7 @@ func TestReturnsTheStatusOfObjectLockingSupportOnTheBucket(t *testing.T) { true, structBucketLocking, ) - printEndFunc("TestReturnsTheStatusOfObjectLockingSupportOnTheBucket") + } func SetBucketVersioning(bucketName string, versioning bool) (*http.Response, error) { @@ -2905,7 +2909,7 @@ func SetBucketVersioning(bucketName string, versioning bool) (*http.Response, er } func TestSetBucketVersioning(t *testing.T) { - printStartFunc("TestSetBucketVersioning") + // Variables assert := assert.New(t) bucket := "test-set-bucket-versioning" @@ -2948,7 +2952,7 @@ func TestSetBucketVersioning(t *testing.T) { assert.Nil(err) } assert.Equal(false, result.IsVersioned, result) - printEndFunc("TestSetBucketVersioning") + } func EnableBucketEncryption(bucketName string, encType string, kmsKeyID string) (*http.Response, error) { @@ -2985,7 +2989,7 @@ func EnableBucketEncryption(bucketName string, encType string, kmsKeyID string) } func TestEnableBucketEncryption(t *testing.T) { - printStartFunc("TestEnableBucketEncryption") + // Variables assert := assert.New(t) bucketName := "test-enable-bucket-encryption" @@ -3030,7 +3034,6 @@ func TestEnableBucketEncryption(t *testing.T) { assert.Nil(err) } assert.Equal("AES256", result.Algorithm, result) - printEndFunc("TestEnableBucketEncryption") // 4. Disable Bucket's Encryption resp, err = DisableBucketEncryption(bucketName) @@ -3064,7 +3067,7 @@ func TestEnableBucketEncryption(t *testing.T) { } dereferencedPointerDetailedMessage := *result2.DetailedMessage assert.Equal("error server side encryption configuration not found", dereferencedPointerDetailedMessage, dereferencedPointerDetailedMessage) - printEndFunc("TestEnableBucketEncryption") + } func GetBucketEncryptionInformation(bucketName string) (*http.Response, error) { @@ -3259,8 +3262,6 @@ func DeleteLifecycleRule(bucketName string, lifecycleID string) (*http.Response, func TestBucketLifeCycle(t *testing.T) { - printStartFunc("TestBucketLifeCycle") - // Variables assert := assert.New(t) bucketName := "test-bucket-life-cycle" @@ -3391,7 +3392,6 @@ func TestBucketLifeCycle(t *testing.T) { 404, resp.StatusCode, "Status Code is incorrect") } - printEndFunc("TestBucketLifeCycle") } func SetAccessRuleWithBucket(bucketName string, prefix string, access string) (*http.Response, error) { @@ -3480,8 +3480,6 @@ func DeleteAccessRuleWithBucket(bucketName string, prefix string) (*http.Respons func TestAccessRule(t *testing.T) { - printStartFunc("TestAccessRule") - // Variables assert := assert.New(t) bucketName := "test-access-rule-bucket" @@ -3569,10 +3567,9 @@ func TestAccessRule(t *testing.T) { } AccessRules := &result.AccessRules // The array has to be empty, no index accessible if len(*AccessRules) == 0 { - printMessage("Cool, access rules are gone from this bucket") + fmt.Println("Cool, access rules are gone from this bucket") } else { assert.Fail("Access Rule not deleted") } - printEndFunc("TestAccessRule") } diff --git a/integration/users_test.go b/integration/users_test.go index 826e90868..0f2ac449b 100644 --- a/integration/users_test.go +++ b/integration/users_test.go @@ -359,7 +359,7 @@ func TestAddUser(t *testing.T) { tests like users.ts can run over clean data and we don't collide against it. */ - printStartFunc("TestAddUser") + assert := assert.New(t) // With no groups & no policies @@ -384,7 +384,7 @@ func TestAddUser(t *testing.T) { fmt.Println("DELETE StatusCode:", response.StatusCode) assert.Equal(204, response.StatusCode, "has to be 204 when delete user") } - printEndFunc("TestAddUser") + } func TestListUsers(t *testing.T) { @@ -394,7 +394,7 @@ func TestListUsers(t *testing.T) { 2. Then, it lists the users <------ 200 is expected when listing them. 3. Finally, it deletes the users */ - printStartFunc("TestListUsers") + assert := assert.New(t) // With no groups & no policies @@ -454,14 +454,14 @@ func TestListUsers(t *testing.T) { response.StatusCode, "has to be 204 when delete user") } } - printEndFunc("TestListUsers") + } func TestGetUserInfo(t *testing.T) { /* Test to get the user information via API. */ - printStartFunc("TestGetUserInfo") + // 1. Create the user fmt.Println("TestGetUserInfo(): 1. Create the user") assert := assert.New(t) @@ -500,14 +500,14 @@ func TestGetUserInfo(t *testing.T) { expected := "{\"accessKey\":\"accessKey\",\"memberOf\":null,\"policy\":[],\"status\":\"enabled\"}\n" obtained := string(b) assert.Equal(expected, obtained, "User Information is wrong") - printEndFunc("TestGetUserInfo") + } func TestUpdateUserInfoSuccessfulResponse(t *testing.T) { /* Update User Information Test with Successful Response */ - printStartFunc("TestGetUserInfo") + assert := assert.New(t) // 1. Create an active user @@ -545,14 +545,14 @@ func TestUpdateUserInfoSuccessfulResponse(t *testing.T) { log.Fatalln(err) } assert.True(strings.Contains(string(b), "disabled")) - printEndFunc("TestGetUserInfo") + } func TestUpdateUserInfoGenericErrorResponse(t *testing.T) { /* Update User Information Test with Generic Error Response */ - printStartFunc("TestUpdateUserInfoGenericErrorResponse") + assert := assert.New(t) // 1. Create an active user @@ -590,14 +590,14 @@ func TestUpdateUserInfoGenericErrorResponse(t *testing.T) { log.Fatalln(err) } assert.True(strings.Contains(string(b), "status not valid")) - printEndFunc("TestUpdateUserInfoGenericErrorResponse") + } func TestRemoveUserSuccessfulResponse(t *testing.T) { /* To test removing a user from API */ - printStartFunc("TestRemoveUserSuccessfulResponse") + assert := assert.New(t) // 1. Create an active user @@ -641,17 +641,17 @@ func TestRemoveUserSuccessfulResponse(t *testing.T) { 404, getUserInfoResponse.StatusCode, "Status Code is incorrect") } finalResponse := inspectHTTPResponse(getUserInfoResponse) - printMessage(finalResponse) + fmt.Println(finalResponse) assert.True(strings.Contains( finalResponse, "The specified user does not exist"), finalResponse) - printEndFunc("TestRemoveUserSuccessfulResponse") + } func TestUpdateGroupsForAUser(t *testing.T) { /* To test Update Groups For a User End Point. */ - printStartFunc("TestUpdateGroupsForAUser") + // 1. Create the user numberOfGroups := 3 groupName := "updategroupforausergroup" @@ -701,14 +701,14 @@ func TestUpdateGroupsForAUser(t *testing.T) { assert.True(strings.Contains( finalResponse, groupName+strconv.Itoa(i)), finalResponse) } - printEndFunc("TestUpdateGroupsForAUser") + } func TestCreateServiceAccountForUser(t *testing.T) { /* To test creation of service account for a user. */ - printStartFunc("TestCreateServiceAccountForUser") + // Test's variables userName := "testcreateserviceaccountforuser1" assert := assert.New(t) @@ -762,14 +762,14 @@ func TestCreateServiceAccountForUser(t *testing.T) { ) } assert.Equal(len(finalResponse), serviceAccountLengthInBytes, finalResponse) - printEndFunc("TestCreateServiceAccountForUser") + } func TestCreateServiceAccountForUserWithCredentials(t *testing.T) { /* To test creation of service account for a user. */ - printStartFunc("TestCreateServiceAccountForUserWithCredentials") + // Test's variables userName := "testcreateserviceaccountforuserwithcredentials1" assert := assert.New(t) @@ -855,14 +855,14 @@ func TestCreateServiceAccountForUserWithCredentials(t *testing.T) { assert.Equal(len(finalResponse), serviceAccountLengthInBytes, finalResponse) }) } - printEndFunc("TestCreateServiceAccountForUserWithCredentials") + } func TestUsersGroupsBulk(t *testing.T) { /* To test UsersGroupsBulk End Point */ - printStartFunc("TestUsersGroupsBulk") + // Vars assert := assert.New(t) numberOfUsers := 5 @@ -945,5 +945,5 @@ func TestUsersGroupsBulk(t *testing.T) { // Make sure the user belongs to the created group assert.True(strings.Contains(string(finalResponse), groupName)) } - printEndFunc("TestUsersGroupsBulk") + } diff --git a/integration/version_test.go b/integration/version_test.go new file mode 100644 index 000000000..d76a369fb --- /dev/null +++ b/integration/version_test.go @@ -0,0 +1,75 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2022 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package integration + +import ( + "fmt" + "log" + "net/http" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func Test_VersionAPI(t *testing.T) { + assert := assert.New(t) + + type args struct { + api string + } + tests := []struct { + name string + args args + expectedStatus int + expectedError error + }{ + { + name: "Check Version", + args: args{ + api: "/check-version", + }, + expectedStatus: 200, + expectedError: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + client := &http.Client{ + Timeout: 3 * time.Second, + } + request, err := http.NewRequest( + "GET", fmt.Sprintf("http://localhost:9090/api/v1%s", tt.args.api), nil) + if err != nil { + log.Println(err) + return + } + request.Header.Add("Content-Type", "application/json") + response, err := client.Do(request) + if err != nil { + log.Println(err) + return + } + if response != nil { + assert.Equal(tt.expectedStatus, response.StatusCode, "Status Code is incorrect") + } + + }) + } + +} diff --git a/operator-integration/tenant_test.go b/operator-integration/tenant_test.go index e85e0f468..305d51eac 100644 --- a/operator-integration/tenant_test.go +++ b/operator-integration/tenant_test.go @@ -50,26 +50,19 @@ func decodeBase64(value string) string { return string(result) } -func printMessage(message string) { - /* - Helper function to print HTTP response. - */ - fmt.Println(message) -} - func printLoggingMessage(message string, functionName string) { /* Helper function to have standard output across the tests. */ finalString := "......................." + functionName + "(): " + message - printMessage(finalString) + fmt.Println(finalString) } func printStartFunc(functionName string) { /* Common function for all tests to tell that test has started */ - printMessage("") + fmt.Println("") printLoggingMessage("started", functionName) } @@ -78,7 +71,7 @@ func printEndFunc(functionName string) { Helper function for all tests to tell that test has ended, is completed */ printLoggingMessage("completed", functionName) - printMessage("") + fmt.Println("") } func initConsoleServer() (*restapi.Server, error) {