From 46d504cddc0a15da18514736fd44f71a838b38b0 Mon Sep 17 00:00:00 2001
From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
Date: Mon, 13 Sep 2021 12:45:54 -0700
Subject: [PATCH] Integration Test (#1012)
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
---
.github/workflows/integration.yml | 39 ++++
integration/buckets_test.go | 340 ++++++++++++++++++++++++++++++
integration/login_test.go | 71 +++++++
3 files changed, 450 insertions(+)
create mode 100644 .github/workflows/integration.yml
create mode 100644 integration/buckets_test.go
create mode 100644 integration/login_test.go
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml
new file mode 100644
index 000000000..1a4911f40
--- /dev/null
+++ b/.github/workflows/integration.yml
@@ -0,0 +1,39 @@
+name: Go
+
+on:
+ pull_request:
+ branches:
+ - master
+ push:
+ branches:
+ - master
+
+jobs:
+ build:
+ name: Integration Tests with Latest Distributed MinIO
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ go-version: [1.16.x]
+ os: [ubuntu-latest]
+ steps:
+ - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
+ uses: actions/setup-go@v2
+ with:
+ go-version: ${{ matrix.go-version }}
+ id: go
+
+ - name: Check out code into the Go module directory
+ uses: actions/checkout@v2
+
+ - name: Build on ${{ matrix.os }}
+ env:
+ GO111MODULE: on
+ GOOS: linux
+ CGO_ENABLED: 0
+ run: |
+ wget -O /tmp/minio https://dl.minio.io/server/minio/release/linux-amd64/minio
+ chmod +x /tmp/minio
+ mkdir -p /tmp/certs-dir
+ /tmp/minio server --quiet -S /tmp/certs-dir /tmp/fs{1...4} &
+ go test github.com/minio/console/integration/...
diff --git a/integration/buckets_test.go b/integration/buckets_test.go
new file mode 100644
index 000000000..e680c19dc
--- /dev/null
+++ b/integration/buckets_test.go
@@ -0,0 +1,340 @@
+// This file is part of MinIO Console Server
+// Copyright (c) 2021 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 (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+ "strconv"
+ "testing"
+ "time"
+
+ "github.com/go-openapi/loads"
+ "github.com/minio/console/restapi"
+ "github.com/minio/console/restapi/operations"
+
+ "github.com/minio/console/models"
+
+ "github.com/stretchr/testify/assert"
+)
+
+var token string
+
+func initConsoleServer() (*restapi.Server, error) {
+
+ //os.Setenv("CONSOLE_MINIO_SERVER", "localhost:9000")
+
+ swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
+ if err != nil {
+ return nil, err
+ }
+
+ noLog := func(string, ...interface{}) {
+ // nothing to log
+ }
+
+ // Initialize MinIO loggers
+ restapi.LogInfo = noLog
+ restapi.LogError = noLog
+
+ api := operations.NewConsoleAPI(swaggerSpec)
+ api.Logger = noLog
+
+ server := restapi.NewServer(api)
+ // register all APIs
+ server.ConfigureAPI()
+
+ //restapi.GlobalRootCAs, restapi.GlobalPublicCerts, restapi.GlobalTLSCertsManager = globalRootCAs, globalPublicCerts, globalTLSCerts
+
+ consolePort, _ := strconv.Atoi("9090")
+
+ server.Host = "0.0.0.0"
+ server.Port = consolePort
+ restapi.Port = "9090"
+ restapi.Hostname = "0.0.0.0"
+
+ return server, nil
+}
+
+func TestMain(m *testing.M) {
+
+ // start console server
+ go func() {
+ fmt.Println("start server")
+ srv, err := initConsoleServer()
+ if err != nil {
+ log.Println(err)
+ log.Println("init fail")
+ return
+ }
+ srv.Serve()
+
+ }()
+
+ fmt.Println("sleeping")
+ time.Sleep(2 * time.Second)
+
+ client := &http.Client{
+ Timeout: 2 * time.Second,
+ }
+ // get login credentials
+
+ requestData := map[string]string{
+ "accessKey": "minioadmin",
+ "secretKey": "minioadmin",
+ }
+
+ requestDataJSON, _ := json.Marshal(requestData)
+
+ requestDataBody := bytes.NewReader(requestDataJSON)
+
+ request, err := http.NewRequest("POST", "http://localhost:9090/api/v1/login", requestDataBody)
+ 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 {
+ bodyBytes, _ := ioutil.ReadAll(response.Body)
+
+ loginResponse := models.LoginResponse{}
+ err = json.Unmarshal(bodyBytes, &loginResponse)
+ if err != nil {
+ log.Println(err)
+ }
+
+ token = loginResponse.SessionID
+
+ }
+
+ code := m.Run()
+
+ requestDataAdd := map[string]interface{}{
+ "name": "test1",
+ }
+
+ requestDataJSON, _ = json.Marshal(requestDataAdd)
+
+ requestDataBody = bytes.NewReader(requestDataJSON)
+
+ // get list of buckets
+ request, err = http.NewRequest("DELETE", "http://localhost:9090/api/v1/buckets/test1", 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 {
+ fmt.Println("DELETE StatusCode:", response.StatusCode)
+ }
+
+ os.Exit(code)
+}
+
+func TestAddBucket(t *testing.T) {
+ assert := assert.New(t)
+
+ client := &http.Client{
+ Timeout: 2 * time.Second,
+ }
+
+ requestDataAdd := map[string]interface{}{
+ "name": "test1",
+ "versioning": false,
+ "locking": false,
+ }
+
+ requestDataJSON, _ := json.Marshal(requestDataAdd)
+
+ requestDataBody := bytes.NewReader(requestDataJSON)
+
+ // get list of buckets
+ request, err := http.NewRequest("POST", "http://localhost:9090/api/v1/buckets", 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)
+ assert.Nil(err)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ if response != nil {
+ assert.Equal(201, response.StatusCode, "Status Code is incorrect")
+ }
+}
+
+func TestBucketVersioning(t *testing.T) {
+ assert := assert.New(t)
+
+ client := &http.Client{
+ Timeout: 2 * time.Second,
+ }
+
+ request, err := http.NewRequest("GET", "http://localhost:9090/api/v1/session", nil)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
+
+ response, err := client.Do(request)
+ assert.Nil(err)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+ var distributedSystem bool
+
+ if response != nil {
+
+ bodyBytes, _ := ioutil.ReadAll(response.Body)
+
+ sessionResponse := models.SessionResponse{}
+ err = json.Unmarshal(bodyBytes, &sessionResponse)
+ if err != nil {
+ log.Println(err)
+ }
+
+ distributedSystem = sessionResponse.DistributedMode
+
+ }
+
+ requestDataVersioning := map[string]interface{}{
+ "name": "test2",
+ "versioning": true,
+ "locking": false,
+ }
+
+ requestDataJSON, _ := json.Marshal(requestDataVersioning)
+
+ requestDataBody := bytes.NewReader(requestDataJSON)
+
+ request, err = http.NewRequest("POST", "http://localhost:9090/api/v1/buckets", 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)
+ assert.Nil(err)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ fmt.Println("Versioned bucket creation test status:", response.Status)
+ if distributedSystem {
+ assert.Equal(201, response.StatusCode, "Versioning test Status Code is incorrect - bucket failed to create")
+ } else {
+ assert.NotEqual(201, response.StatusCode, "Versioning test Status Code is incorrect - versioned bucket created on non-distributed system")
+ }
+
+ request, err = http.NewRequest("DELETE", "http://localhost:9090/api/v1/buckets/test2", 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 {
+ fmt.Println("DELETE StatusCode:", response.StatusCode)
+ }
+
+}
+
+func TestBucketsGet(t *testing.T) {
+ assert := assert.New(t)
+
+ client := &http.Client{
+ Timeout: 2 * time.Second,
+ }
+
+ // get list of buckets
+ request, err := http.NewRequest("GET", "http://localhost:9090/api/v1/buckets", nil)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
+
+ response, err := client.Do(request)
+ assert.Nil(err)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ if response != nil {
+ assert.Equal(200, response.StatusCode, "Status Code is incorrect")
+ bodyBytes, _ := ioutil.ReadAll(response.Body)
+
+ listBuckets := models.ListBucketsResponse{}
+ err = json.Unmarshal(bodyBytes, &listBuckets)
+ if err != nil {
+ log.Println(err)
+ assert.Nil(err)
+ }
+
+ assert.Greater(len(listBuckets.Buckets), 0, "No bucket was returned")
+ assert.Greater(listBuckets.Total, int64(0), "Total buckets is 0")
+
+ }
+
+}
diff --git a/integration/login_test.go b/integration/login_test.go
new file mode 100644
index 000000000..d2968aa2d
--- /dev/null
+++ b/integration/login_test.go
@@ -0,0 +1,71 @@
+// This file is part of MinIO Console Server
+// Copyright (c) 2021 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 (
+ "encoding/json"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/minio/console/models"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestLoginStrategy(t *testing.T) {
+ assert := assert.New(t)
+
+ // image for now:
+ // minio: 9000
+ // console: 9090
+
+ client := &http.Client{
+ Timeout: 2 * time.Second,
+ }
+ // copy query params
+ request, err := http.NewRequest("GET", "http://localhost:9090/api/v1/login", nil)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ response, err := client.Do(request)
+ assert.Nil(err)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ if response != nil {
+ bodyBytes, _ := ioutil.ReadAll(response.Body)
+
+ loginDetails := models.LoginDetails{}
+
+ err = json.Unmarshal(bodyBytes, &loginDetails)
+ if err != nil {
+ log.Println(err)
+ }
+ assert.Nil(err)
+
+ assert.Equal(models.LoginDetailsLoginStrategyForm, loginDetails.LoginStrategy, "Login Details don't match")
+
+ }
+
+}