From f4f2cc2bc6384a97c371eb222fa747263f7d7267 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 29 Oct 2020 17:38:28 -0300 Subject: [PATCH 01/34] Adding more e2e tests --- e2e/TESTBOOK.md | 6 +- e2e/server/http_test.go | 38 ++++++++++-- e2e/server/requests.go | 131 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 163 insertions(+), 12 deletions(-) diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 73f4b5dc5..f2fa6cc32 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -22,8 +22,8 @@ - [ ] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type -- [ ] Create, Read, and Delete company token -- [ ] Create, Read, and Delete repositories +- [X] Create, Read, and Delete company token +- [X] Create, Read, and Delete repositories - [ ] Invite, Read, Update and Remove users in company - [ ] Horusec auth type - [ ] Ldap auth type @@ -32,7 +32,7 @@ - [ ] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type -- [ ] Create, Read, and Delete repository token +- [X] Create, Read, and Delete repository token - [ ] Get Dashboard content - [ ] Company view - [ ] Repository view diff --git a/e2e/server/http_test.go b/e2e/server/http_test.go index 06da23499..76df39f76 100644 --- a/e2e/server/http_test.go +++ b/e2e/server/http_test.go @@ -62,6 +62,7 @@ func TestServer(t *testing.T) { }, repositoryToken) RunDashboardByCompany(t, bearerToken, companyID) RunDashboardByRepository(t, bearerToken, companyID, repositoryID) + RunCompanyTokenCRUD(t, bearerToken, companyID) Logout(t, bearerToken) }) fmt.Println("All tests was finished in server test") @@ -139,13 +140,13 @@ func RunCompanyCRUD(t *testing.T, bearerToken string) string { companyID := CreateCompany(t, bearerToken, &accountentities.Company{ Name: "zup", }) - _ = ReadAllCompanies(t, bearerToken) + allCompanies := ReadAllCompanies(t, bearerToken) + assert.Contains(t, allCompanies, "zup") UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ Name: "zup-1", }) allCompaniesUpdated := ReadAllCompanies(t, bearerToken) - allCompaniesBytes, _ := json.Marshal(allCompaniesUpdated) - assert.Contains(t, string(allCompaniesBytes), "zup-1") + assert.Contains(t, allCompaniesUpdated, "zup-1") DeleteCompany(t, bearerToken, companyID) return CreateCompany(t, bearerToken, &accountentities.Company{ Name: "zup", @@ -156,9 +157,36 @@ func RunRepositoryCRUD(t *testing.T, bearerToken, companyID string) string { repositoryID := CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ Name: "horusec", }) - return repositoryID + allRepositories := ReadAllRepositories(t, bearerToken, companyID) + assert.Contains(t, allRepositories, "horusec") + UpdateRepository(t, bearerToken, companyID, repositoryID, &accountentities.Repository{ + Name: "horusec-1", + }) + allRepositoriesUpdated := ReadAllRepositories(t, bearerToken, companyID) + assert.Contains(t, allRepositoriesUpdated, "horusec-1") + DeleteRepository(t, bearerToken, companyID, repositoryID) + return CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ + Name: "horusec", + }) } func RunRepositoryTokenCRUD(t *testing.T, bearerToken, companyID, repositoryID string) string { + _ = GenerateRepositoryToken(t, bearerToken, companyID, repositoryID, api.Token{Description: "access_token"}) + allTokens := ReadAllRepositoryToken(t, bearerToken, companyID, repositoryID) + assert.Contains(t, allTokens, "access_token") + allTokensStruct := []api.Token{} + assert.NoError(t, json.Unmarshal([]byte(allTokens), &allTokensStruct)) + assert.NotEmpty(t, allTokensStruct) + RevokeRepositoryToken(t, bearerToken, companyID, repositoryID, allTokensStruct[0].TokenID.String()) return GenerateRepositoryToken(t, bearerToken, companyID, repositoryID, api.Token{Description: "access_token"}) -} \ No newline at end of file +} + +func RunCompanyTokenCRUD(t *testing.T, bearerToken string, companyID string) { + _ = GenerateCompanyToken(t, bearerToken, companyID, api.Token{Description: "access_token"}) + allTokens := ReadAllCompanyToken(t, bearerToken, companyID) + assert.Contains(t, allTokens, "access_token") + allTokensStruct := []api.Token{} + assert.NoError(t, json.Unmarshal([]byte(allTokens), &allTokensStruct)) + assert.NotEmpty(t, allTokensStruct) + RevokeCompanyToken(t, bearerToken, companyID, allTokensStruct[0].TokenID.String()) +} diff --git a/e2e/server/requests.go b/e2e/server/requests.go index bd9cf7435..efe78d3f1 100644 --- a/e2e/server/requests.go +++ b/e2e/server/requests.go @@ -100,7 +100,7 @@ func UpdateCompany(t *testing.T, bearerToken string, companyID string, company * assert.NotEmpty(t, body["content"]) } -func ReadAllCompanies(t *testing.T, bearerToken string) interface{} { +func ReadAllCompanies(t *testing.T, bearerToken string) string { fmt.Println("Running test for ReadAllCompanies") req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) req.Header.Add("Authorization", bearerToken) @@ -112,7 +112,8 @@ func ReadAllCompanies(t *testing.T, bearerToken string) interface{} { _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) assert.NotEmpty(t, body["content"]) - return body["content"] + content, _ := json.Marshal(body["content"]) + return string(content) } func DeleteCompany(t *testing.T, bearerToken, companyID string) { @@ -144,6 +145,50 @@ func CreateRepository(t *testing.T, bearerToken, companyID string, repository *a return body["content"]["repositoryID"] } +func UpdateRepository(t *testing.T, bearerToken, companyID, repositoryID string, repository *accountentities.Repository) { + fmt.Println("Running test for UpdateRepository") + repositoryBytes, _ := json.Marshal(repository) + fmt.Println("Running test for UpdateRepository") + req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID, bytes.NewReader(repositoryBytes)) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update repository error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "update repository error check response") + var body map[string]map[string]string + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} + +func ReadAllRepositories(t *testing.T, bearerToken, companyID string) string { + fmt.Println("Running test for ReadAllRepositories") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies/"+companyID+"/repositories", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all repositories error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all repositories error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func DeleteRepository(t *testing.T, bearerToken, companyID, repositoryID string) { + fmt.Println("Running test for DeleteRepository") + req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete repository error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete repository error check response") + var body map[string]map[string]string + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} + func GenerateRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID string, token api.Token) string { fmt.Println("Running test for GenerateRepositoryToken") req, _ := http.NewRequest( @@ -154,8 +199,57 @@ func GenerateRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} apiTokenResp, err := httpClient.Do(req) - assert.NoError(t, err, "API token error send response") - assert.Equal(t, http.StatusCreated, apiTokenResp.StatusCode, "API token error check response") + assert.NoError(t, err, "generate repository token error send response") + assert.Equal(t, http.StatusCreated, apiTokenResp.StatusCode, "generate repository token error check response") + + var apiToken map[string]string + _ = json.NewDecoder(apiTokenResp.Body).Decode(&apiToken) + assert.NoError(t, apiTokenResp.Body.Close()) + assert.NotEmpty(t, apiToken["content"]) + return apiToken["content"] +} + +func ReadAllRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID string) string { + fmt.Println("Running test for ReadAllRepositoryToken") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all repositories tokens error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all repositories tokens error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func RevokeRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID, tokenID string) { + fmt.Println("Running test for RevokeRepositoryToken") + req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens/"+tokenID, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete repository token error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete repository token error check response") + var body map[string]map[string]string + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} + +func GenerateCompanyToken(t *testing.T, bearerToken, companyID string, token api.Token) string { + fmt.Println("Running test for GenerateCompanyToken") + req, _ := http.NewRequest( + http.MethodPost, + "http://localhost:8000/api/companies/"+companyID+"/tokens", + bytes.NewReader(token.ToBytes()), + ) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + apiTokenResp, err := httpClient.Do(req) + assert.NoError(t, err, "generate company token error send response") + assert.Equal(t, http.StatusCreated, apiTokenResp.StatusCode, "generate company token error check response") var apiToken map[string]string _ = json.NewDecoder(apiTokenResp.Body).Decode(&apiToken) @@ -164,6 +258,35 @@ func GenerateRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID return apiToken["content"] } +func ReadAllCompanyToken(t *testing.T, bearerToken, companyID string) string { + fmt.Println("Running test for ReadAllCompanyToken") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/tokens", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all companies tokens error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all companies tokens error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func RevokeCompanyToken(t *testing.T, bearerToken, companyID, tokenID string) { + fmt.Println("Running test for RevokeCompanyToken") + req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8000/api/companies/"+companyID+"/tokens/"+tokenID, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete company token error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete company token error check response") + var body map[string]map[string]string + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} + func InsertAnalysisWithRepositoryToken(t *testing.T, analysisData *api.AnalysisData, repositoryToken string) string { fmt.Println("Running test for InsertAnalysisWithRepositoryToken") req, _ := http.NewRequest( From 2e9b6964f973846dafe620bafbadcd3a560ad83c Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 10:26:56 -0300 Subject: [PATCH 02/34] Adding more e2e tests --- .github/workflows/e2e.yml | 2 - Makefile | 2 + .../pkg/entities/account/invite_user.go | 6 + .../pkg/entities/account/invite_user_test.go | 10 + .../entities/account/roles/account_company.go | 6 + .../account/roles/account_company_test.go | 14 +- .../pkg/entities/api/dto/update_vuln_type.go | 6 + .../entities/api/dto/update_vuln_type_test.go | 7 + e2e/TESTBOOK.md | 21 +- e2e/server/http_test.go | 320 ++++++++++++------ e2e/server/requests.go | 140 ++++++++ 11 files changed, 416 insertions(+), 118 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c7a2fa059..6b63929a7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -19,7 +19,5 @@ jobs: id: go - name: Check out code uses: actions/checkout@v2 - - name: Setup External Dependences - run: make compose-e2e - name: e2e run: make test-e2e diff --git a/Makefile b/Makefile index 8b7d8795c..9f1abc754 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ test: $(GO) clean -testcache && $(GO) test -v ./... -timeout=2m -parallel=1 -failfast -short test-e2e: + make compose-e2e go get -v ./e2e/... go get -v ./horusec-cli/... $(GO) clean -testcache @@ -96,6 +97,7 @@ compose-horusec-analytic: compose-horusec-auth: docker-compose -f horusec-auth/deployments/docker-compose.yaml up -d --build --force-recreate compose-e2e: + docker-compose -f e2e/deployments/docker-compose.yaml down -v docker-compose -f e2e/deployments/docker-compose.yaml up -d --build --force-recreate # ========================================================================================= # diff --git a/development-kit/pkg/entities/account/invite_user.go b/development-kit/pkg/entities/account/invite_user.go index 175e31052..1c9fab3d6 100644 --- a/development-kit/pkg/entities/account/invite_user.go +++ b/development-kit/pkg/entities/account/invite_user.go @@ -15,6 +15,7 @@ package account import ( + "encoding/json" "github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles" accountEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/account" validation "github.com/go-ozzo/ozzo-validation/v4" @@ -60,3 +61,8 @@ func (i *InviteUser) SetInviteUserRepositoryAndCompanyID(companyID, repositoryID i.RepositoryID = repositoryID return i } + +func (i *InviteUser) ToBytes() []byte { + content, _ := json.Marshal(i) + return content +} \ No newline at end of file diff --git a/development-kit/pkg/entities/account/invite_user_test.go b/development-kit/pkg/entities/account/invite_user_test.go index 84611aa3e..aaa7796d9 100644 --- a/development-kit/pkg/entities/account/invite_user_test.go +++ b/development-kit/pkg/entities/account/invite_user_test.go @@ -61,3 +61,13 @@ func TestSetInviteUserCompanyID(t *testing.T) { assert.NotEmpty(t, inviteUser.CompanyID) }) } + +func TestInviteUserToBytes(t *testing.T) { + t.Run("Should return content in bytes not empty", func(t *testing.T) { + inviteUser := InviteUser{ + Role: account.Admin, + Email: "test@test.com", + } + assert.NotEmpty(t, inviteUser.ToBytes()) + }) +} \ No newline at end of file diff --git a/development-kit/pkg/entities/account/roles/account_company.go b/development-kit/pkg/entities/account/roles/account_company.go index 6ef6f6be1..d31e78a45 100644 --- a/development-kit/pkg/entities/account/roles/account_company.go +++ b/development-kit/pkg/entities/account/roles/account_company.go @@ -15,6 +15,7 @@ package roles import ( + "encoding/json" "time" "github.com/go-ozzo/ozzo-validation/v4/is" @@ -65,3 +66,8 @@ func (a *AccountCompany) SetCompanyAndAccountID(companyID, accountID uuid.UUID) func (a *AccountCompany) IsNotAdmin() bool { return a.Role != accountEnums.Admin } + +func (a *AccountCompany) ToBytes() []byte { + content, _ := json.Marshal(a) + return content +} diff --git a/development-kit/pkg/entities/account/roles/account_company_test.go b/development-kit/pkg/entities/account/roles/account_company_test.go index 9c5a8f080..8ca588be6 100644 --- a/development-kit/pkg/entities/account/roles/account_company_test.go +++ b/development-kit/pkg/entities/account/roles/account_company_test.go @@ -15,11 +15,10 @@ package roles import ( - "testing" - rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account" "github.com/google/uuid" "github.com/stretchr/testify/assert" + "testing" ) func TestValidate(t *testing.T) { @@ -83,3 +82,14 @@ func TestIsNotAdmin(t *testing.T) { assert.False(t, accountCompany.IsNotAdmin()) }) } + +func TestAccountCompanyToBytes(t *testing.T) { + t.Run("Should return content in bytes not empty", func(t *testing.T) { + inviteUser := AccountCompany{ + CompanyID: uuid.New(), + AccountID: uuid.New(), + Role: rolesEnum.Member, + } + assert.NotEmpty(t, inviteUser.ToBytes()) + }) +} \ No newline at end of file diff --git a/development-kit/pkg/entities/api/dto/update_vuln_type.go b/development-kit/pkg/entities/api/dto/update_vuln_type.go index ce1175f3b..ea4e1fab4 100644 --- a/development-kit/pkg/entities/api/dto/update_vuln_type.go +++ b/development-kit/pkg/entities/api/dto/update_vuln_type.go @@ -15,6 +15,7 @@ package dto import ( + "encoding/json" horusecEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/horusec" validation "github.com/go-ozzo/ozzo-validation/v4" ) @@ -29,6 +30,11 @@ func (u *UpdateVulnType) Validate() error { ) } +func (u *UpdateVulnType) ToBytes() []byte { + content, _ := json.Marshal(u) + return content +} + func (u UpdateVulnType) TypeValues() []interface{} { return []interface{}{ horusecEnums.FalsePositive, diff --git a/development-kit/pkg/entities/api/dto/update_vuln_type_test.go b/development-kit/pkg/entities/api/dto/update_vuln_type_test.go index c261c931d..19fd30a99 100644 --- a/development-kit/pkg/entities/api/dto/update_vuln_type_test.go +++ b/development-kit/pkg/entities/api/dto/update_vuln_type_test.go @@ -39,4 +39,11 @@ func TestValidateUpdateVulnType(t *testing.T) { assert.Error(t, err) assert.Equal(t, "type: must be a valid value.", err.Error()) }) + t.Run("Should not return empty content and parse to bytes", func(t *testing.T) { + updateManagementData := &UpdateVulnType{ + Type: "test", + } + + assert.NotEmpty(t, updateManagementData.ToBytes()) + }) } diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index f2fa6cc32..0b3e18b80 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -5,6 +5,10 @@ - [X] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type +- [ ] Login + - [X] Horusec auth type + - [ ] Ldap auth type + - [ ] Keycloak auth type - [ ] Logout - [X] Horusec auth type - [ ] Ldap auth type @@ -23,20 +27,23 @@ - [ ] Ldap auth type - [ ] Keycloak auth type - [X] Create, Read, and Delete company token -- [X] Create, Read, and Delete repositories +- [X] Create, Read, Update, and Delete repositories +- [X] Create, Read, and Delete repository token - [ ] Invite, Read, Update and Remove users in company - [ ] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type + - [ ] Keycloak auth +- [X] Create and Read analysis + - [X] Repository Token + - [X] Company Token + repository name - [ ] Invite, Read, Update and Remove users in repository - [ ] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type -- [X] Create, Read, and Delete repository token -- [ ] Get Dashboard content - - [ ] Company view - - [ ] Repository view -- [ ] Manager vulnerabilities found and change type into: False Positive, Risk accept, Corrected, Vulnerability +- [X] Get Dashboard content + - [X] Company view + - [X] Repository view +- [X] Manager vulnerabilities found and change type into: False Positive, Risk accept, Corrected, Vulnerability ## Horusec CLI - [ ] Setup log level diff --git a/e2e/server/http_test.go b/e2e/server/http_test.go index 76df39f76..9f018164c 100644 --- a/e2e/server/http_test.go +++ b/e2e/server/http_test.go @@ -4,6 +4,9 @@ import ( "encoding/json" "fmt" "github.com/ZupIT/horusec/development-kit/pkg/entities/api" + "github.com/ZupIT/horusec/development-kit/pkg/entities/api/dto" + "github.com/ZupIT/horusec/development-kit/pkg/entities/horusec" + horusecEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/horusec" "github.com/ZupIT/horusec/development-kit/pkg/utils/test" "github.com/stretchr/testify/assert" "os" @@ -23,17 +26,28 @@ func TestMain(m *testing.M) { env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable"), ) if err != nil { - logger.LogPanic("Error in create instance migration: ", err) + logger.LogPanic("Error in create first instance migration: ", err) } - - if err := migration.Down(); err != nil { - if err.Error() != "no change" { - logger.LogPanic("Error in down migration: ", err) - } + if err := migration.Drop(); err != nil { + logger.LogPanic("Error in drop migration: ", err) + } + sourceErr, dbErr := migration.Close() + if sourceErr != nil { + logger.LogPanic("Error in source err to close connection: ", sourceErr) + } + if dbErr != nil { + logger.LogPanic("Error in database err to close connection: ", dbErr) + } + migration, err = migrate.New( + "file://../../development-kit/pkg/databases/relational/migration", + env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable"), + ) + if err != nil { + logger.LogPanic("Error in create second instance migration: ", err) } if err := migration.Up(); err != nil { if err.Error() != "no change" { - logger.LogPanic("Error in down migration: ", err) + logger.LogPanic("Error in up migration: ", err) } } code := m.Run() @@ -45,148 +59,240 @@ func TestServer(t *testing.T) { t.Skip("skipping integration test") } t.Run("Should tests default auth-type (horusec) http requests", func(t *testing.T) { + // TESTBOOK: Create account - Horusec auth type CreateAccount(t, &accountentities.Account{ Email: "e2e@example.com", Password: "Ch@ng3m3", Username: "e2e_user", }) + // TESTBOOK: Login - Horusec auth type bearerToken, _ := Login(t, &accountentities.LoginData{ Email: "e2e@example.com", Password: "Ch@ng3m3", }) + // TESTBOOK: Authorize + // TESTBOOK: Create, Read, Update and Delete company - Horusec auth type companyID := RunCompanyCRUD(t, bearerToken) + // TESTBOOK: Authorize + // TESTBOOK: Create, Read, Update, and Delete repositories repositoryID := RunRepositoryCRUD(t, bearerToken, companyID) + // TESTBOOK: Authorize + // TESTBOOK: Create, Read, and Delete repository token repositoryToken := RunRepositoryTokenCRUD(t, bearerToken, companyID, repositoryID) - _ = InsertAnalysisWithRepositoryToken(t, &api.AnalysisData{ - Analysis: test.CreateAnalysisMock(), - }, repositoryToken) + // TESTBOOK: Authorize + // TESTBOOK: Create, Read, and Delete company token + companyToken := RunCompanyTokenCRUD(t, bearerToken, companyID) + // TESTBOOK: Create and Read analysis - Repository Token + // TESTBOOK: Create and Read analysis - Company Token + repository name + RunAnalysisRoutes(t, repositoryToken, companyToken) + // TESTBOOK: Get Dashboard content - Company view RunDashboardByCompany(t, bearerToken, companyID) + // TESTBOOK: Get Dashboard content - Repository view RunDashboardByRepository(t, bearerToken, companyID, repositoryID) - RunCompanyTokenCRUD(t, bearerToken, companyID) + // TESTBOOK: Get Dashboard content - Repository view + RunManagerVulnerabilities(t, bearerToken, companyID, repositoryID) + // TESTBOOK: Logout - Horusec auth type Logout(t, bearerToken) }) fmt.Println("All tests was finished in server test") } +func RunCompanyCRUD(t *testing.T, bearerToken string) string { + t.Run("Should create an company, check if it exists, update your name check if name was updated delete a company and return new company to manager in other steps", func(t *testing.T) { + companyID := CreateCompany(t, bearerToken, &accountentities.Company{ + Name: "zup", + }) + allCompanies := ReadAllCompanies(t, bearerToken) + assert.Contains(t, allCompanies, "zup") + UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ + Name: "zup-1", + }) + allCompaniesUpdated := ReadAllCompanies(t, bearerToken) + assert.Contains(t, allCompaniesUpdated, "zup-1") + DeleteCompany(t, bearerToken, companyID) + }) + return CreateCompany(t, bearerToken, &accountentities.Company{ + Name: "zup", + }) +} + +func RunRepositoryCRUD(t *testing.T, bearerToken, companyID string) string { + t.Run("Should create an repository, check if it exists, update your name check if name was updated delete a repository and return new repository to manager in other steps", func(t *testing.T) { + repositoryID := CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ + Name: "horusec", + }) + allRepositories := ReadAllRepositories(t, bearerToken, companyID) + assert.Contains(t, allRepositories, "horusec") + UpdateRepository(t, bearerToken, companyID, repositoryID, &accountentities.Repository{ + Name: "horusec-1", + }) + allRepositoriesUpdated := ReadAllRepositories(t, bearerToken, companyID) + assert.Contains(t, allRepositoriesUpdated, "horusec-1") + DeleteRepository(t, bearerToken, companyID, repositoryID) + }) + return CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ + Name: "horusec", + }) +} + +func RunRepositoryTokenCRUD(t *testing.T, bearerToken, companyID, repositoryID string) string { + t.Run("Should create an repository token, check if return your content correctly and delete a repository token and return new repository token to manager in other steps", func(t *testing.T) { + _ = GenerateRepositoryToken(t, bearerToken, companyID, repositoryID, api.Token{Description: "access_token"}) + allTokens := ReadAllRepositoryToken(t, bearerToken, companyID, repositoryID) + assert.Contains(t, allTokens, "access_token") + allTokensStruct := []api.Token{} + assert.NoError(t, json.Unmarshal([]byte(allTokens), &allTokensStruct)) + assert.NotEmpty(t, allTokensStruct) + RevokeRepositoryToken(t, bearerToken, companyID, repositoryID, allTokensStruct[0].TokenID.String()) + }) + return GenerateRepositoryToken(t, bearerToken, companyID, repositoryID, api.Token{Description: "access_token"}) +} + +func RunCompanyTokenCRUD(t *testing.T, bearerToken string, companyID string) string { + t.Run("Should create an company token, check if return your content correctly and delete a company token and return new company token to manager in other steps", func(t *testing.T) { + _ = GenerateCompanyToken(t, bearerToken, companyID, api.Token{Description: "access_token"}) + allTokens := ReadAllCompanyToken(t, bearerToken, companyID) + assert.Contains(t, allTokens, "access_token") + allTokensStruct := []api.Token{} + assert.NoError(t, json.Unmarshal([]byte(allTokens), &allTokensStruct)) + assert.NotEmpty(t, allTokensStruct) + RevokeCompanyToken(t, bearerToken, companyID, allTokensStruct[0].TokenID.String()) + }) + return GenerateCompanyToken(t, bearerToken, companyID, api.Token{Description: "access_token"}) +} + +func RunAnalysisRoutes(t *testing.T, repositoryToken, companyToken string) { + t.Run("Should create an analysis using repository token and check if exists your content in system", func(t *testing.T) { + analysisIDInsertedWithRepositoryToken := InsertAnalysisWithRepositoryToken(t, &api.AnalysisData{ + Analysis: test.CreateAnalysisMock(), + }, repositoryToken) + contentInsertedWithRepositoryToken := GetAnalysisByID(t, analysisIDInsertedWithRepositoryToken, repositoryToken) + analysisInsertedWithRepositoryToken := horusec.Analysis{} + assert.NoError(t, json.Unmarshal([]byte(contentInsertedWithRepositoryToken), &analysisInsertedWithRepositoryToken)) + assert.NotEmpty(t, analysisInsertedWithRepositoryToken) + assert.Greater(t, len(analysisInsertedWithRepositoryToken.AnalysisVulnerabilities), 0) + }) + t.Run("Should create an analysis using company token and check if exists your content in system", func(t *testing.T) { + analysisIDInsertedWithCompanyToken := InsertAnalysisWithCompanyToken(t, &api.AnalysisData{ + Analysis: test.CreateAnalysisMock(), + RepositoryName: "new-repository", + }, companyToken) + contentInsertedWithCompanyToken := GetAnalysisByID(t, analysisIDInsertedWithCompanyToken, repositoryToken) + analysisInsertedWithCompanyToken := horusec.Analysis{} + assert.NoError(t, json.Unmarshal([]byte(contentInsertedWithCompanyToken), &analysisInsertedWithCompanyToken)) + assert.NotEmpty(t, analysisInsertedWithCompanyToken) + assert.Greater(t, len(analysisInsertedWithCompanyToken.AnalysisVulnerabilities), 0) + }) +} + func RunDashboardByCompany(t *testing.T, bearerToken, companyID string) { - bodyAllVulnerabilities := GetChartContent(t, "all-vulnerabilities", bearerToken, companyID, "") - bodyAllVulnerabilitiesString := string(bodyAllVulnerabilities) - assert.NotEmpty(t, bodyAllVulnerabilitiesString) + t.Run("Check if all graphs routes return content in view by company", func(t *testing.T) { + bodyAllVulnerabilities := GetChartContent(t, "all-vulnerabilities", bearerToken, companyID, "") + bodyAllVulnerabilitiesString := string(bodyAllVulnerabilities) + assert.NotEmpty(t, bodyAllVulnerabilitiesString) - bodyVulnerabilitiesByAuthor := GetChartContent(t, "vulnerabilities-by-author", bearerToken, companyID, "") - bodyVulnerabilitiesByAuthorString := string(bodyVulnerabilitiesByAuthor) - assert.NotEmpty(t, bodyVulnerabilitiesByAuthorString) + bodyVulnerabilitiesByAuthor := GetChartContent(t, "vulnerabilities-by-author", bearerToken, companyID, "") + bodyVulnerabilitiesByAuthorString := string(bodyVulnerabilitiesByAuthor) + assert.NotEmpty(t, bodyVulnerabilitiesByAuthorString) - bodyVulnerabilitiesByLanguage := GetChartContent(t, "vulnerabilities-by-language", bearerToken, companyID, "") - bodyVulnerabilitiesByLanguageString := string(bodyVulnerabilitiesByLanguage) - assert.NotEmpty(t, bodyVulnerabilitiesByLanguageString) + bodyVulnerabilitiesByLanguage := GetChartContent(t, "vulnerabilities-by-language", bearerToken, companyID, "") + bodyVulnerabilitiesByLanguageString := string(bodyVulnerabilitiesByLanguage) + assert.NotEmpty(t, bodyVulnerabilitiesByLanguageString) - bodyVulnerabilitiesByRepository := GetChartContent(t, "vulnerabilities-by-repository", bearerToken, companyID, "") - bodyVulnerabilitiesByRepositoryString := string(bodyVulnerabilitiesByRepository) - assert.NotEmpty(t, bodyVulnerabilitiesByRepositoryString) + bodyVulnerabilitiesByRepository := GetChartContent(t, "vulnerabilities-by-repository", bearerToken, companyID, "") + bodyVulnerabilitiesByRepositoryString := string(bodyVulnerabilitiesByRepository) + assert.NotEmpty(t, bodyVulnerabilitiesByRepositoryString) - bodyVulnerabilitiesByTime := GetChartContent(t, "vulnerabilities-by-time", bearerToken, companyID, "") - bodyVulnerabilitiesByTimeString := string(bodyVulnerabilitiesByTime) - assert.NotEmpty(t, bodyVulnerabilitiesByTimeString) + bodyVulnerabilitiesByTime := GetChartContent(t, "vulnerabilities-by-time", bearerToken, companyID, "") + bodyVulnerabilitiesByTimeString := string(bodyVulnerabilitiesByTime) + assert.NotEmpty(t, bodyVulnerabilitiesByTimeString) - bodyTotalDevelopers := GetChartContent(t, "total-developers", bearerToken, companyID, "") - bodyTotalDevelopersString := string(bodyTotalDevelopers) - assert.NotEmpty(t, bodyTotalDevelopersString) + bodyTotalDevelopers := GetChartContent(t, "total-developers", bearerToken, companyID, "") + bodyTotalDevelopersString := string(bodyTotalDevelopers) + assert.NotEmpty(t, bodyTotalDevelopersString) - bodyTotalRepositories := GetChartContent(t, "total-repositories", bearerToken, companyID, "") - bodyTotalRepositoriesString := string(bodyTotalRepositories) - assert.NotEmpty(t, bodyTotalRepositoriesString) + bodyTotalRepositories := GetChartContent(t, "total-repositories", bearerToken, companyID, "") + bodyTotalRepositoriesString := string(bodyTotalRepositories) + assert.NotEmpty(t, bodyTotalRepositoriesString) - bodyDetailsChart := GetChartDetailsUsingGraphQLAndReturnBody(t, bearerToken, companyID, "") - bodyDetailsChartString := string(bodyDetailsChart) - assert.NotEmpty(t, bodyDetailsChartString) + bodyDetailsChart := GetChartDetailsUsingGraphQLAndReturnBody(t, bearerToken, companyID, "") + bodyDetailsChartString := string(bodyDetailsChart) + assert.NotEmpty(t, bodyDetailsChartString) + }) } func RunDashboardByRepository(t *testing.T, bearerToken, companyID, repositoryID string) { - bodyAllVulnerabilities := GetChartContent(t, "all-vulnerabilities", bearerToken, companyID, repositoryID) - bodyAllVulnerabilitiesString := string(bodyAllVulnerabilities) - assert.NotEmpty(t, bodyAllVulnerabilitiesString) + t.Run("Check if all graphs routes return content in view by repository", func(t *testing.T) { + bodyAllVulnerabilities := GetChartContent(t, "all-vulnerabilities", bearerToken, companyID, repositoryID) + bodyAllVulnerabilitiesString := string(bodyAllVulnerabilities) + assert.NotEmpty(t, bodyAllVulnerabilitiesString) - bodyVulnerabilitiesByAuthor := GetChartContent(t, "vulnerabilities-by-author", bearerToken, companyID, repositoryID) - bodyVulnerabilitiesByAuthorString := string(bodyVulnerabilitiesByAuthor) - assert.NotEmpty(t, bodyVulnerabilitiesByAuthorString) + bodyVulnerabilitiesByAuthor := GetChartContent(t, "vulnerabilities-by-author", bearerToken, companyID, repositoryID) + bodyVulnerabilitiesByAuthorString := string(bodyVulnerabilitiesByAuthor) + assert.NotEmpty(t, bodyVulnerabilitiesByAuthorString) - bodyVulnerabilitiesByLanguage := GetChartContent(t, "vulnerabilities-by-language", bearerToken, companyID, repositoryID) - bodyVulnerabilitiesByLanguageString := string(bodyVulnerabilitiesByLanguage) - assert.NotEmpty(t, bodyVulnerabilitiesByLanguageString) + bodyVulnerabilitiesByLanguage := GetChartContent(t, "vulnerabilities-by-language", bearerToken, companyID, repositoryID) + bodyVulnerabilitiesByLanguageString := string(bodyVulnerabilitiesByLanguage) + assert.NotEmpty(t, bodyVulnerabilitiesByLanguageString) - bodyVulnerabilitiesByRepository := GetChartContent(t, "vulnerabilities-by-repository", bearerToken, companyID, repositoryID) - bodyVulnerabilitiesByRepositoryString := string(bodyVulnerabilitiesByRepository) - assert.NotEmpty(t, bodyVulnerabilitiesByRepositoryString) + bodyVulnerabilitiesByRepository := GetChartContent(t, "vulnerabilities-by-repository", bearerToken, companyID, repositoryID) + bodyVulnerabilitiesByRepositoryString := string(bodyVulnerabilitiesByRepository) + assert.NotEmpty(t, bodyVulnerabilitiesByRepositoryString) - bodyVulnerabilitiesByTime := GetChartContent(t, "vulnerabilities-by-time", bearerToken, companyID, repositoryID) - bodyVulnerabilitiesByTimeString := string(bodyVulnerabilitiesByTime) - assert.NotEmpty(t, bodyVulnerabilitiesByTimeString) + bodyVulnerabilitiesByTime := GetChartContent(t, "vulnerabilities-by-time", bearerToken, companyID, repositoryID) + bodyVulnerabilitiesByTimeString := string(bodyVulnerabilitiesByTime) + assert.NotEmpty(t, bodyVulnerabilitiesByTimeString) - bodyTotalDevelopers := GetChartContent(t, "total-developers", bearerToken, companyID, repositoryID) - bodyTotalDevelopersString := string(bodyTotalDevelopers) - assert.NotEmpty(t, bodyTotalDevelopersString) + bodyTotalDevelopers := GetChartContent(t, "total-developers", bearerToken, companyID, repositoryID) + bodyTotalDevelopersString := string(bodyTotalDevelopers) + assert.NotEmpty(t, bodyTotalDevelopersString) - bodyTotalRepositories := GetChartContent(t, "total-repositories", bearerToken, companyID, repositoryID) - bodyTotalRepositoriesString := string(bodyTotalRepositories) - assert.NotEmpty(t, bodyTotalRepositoriesString) + bodyTotalRepositories := GetChartContent(t, "total-repositories", bearerToken, companyID, repositoryID) + bodyTotalRepositoriesString := string(bodyTotalRepositories) + assert.NotEmpty(t, bodyTotalRepositoriesString) - bodyDetailsChart := GetChartDetailsUsingGraphQLAndReturnBody(t, bearerToken, companyID, repositoryID) - bodyDetailsChartString := string(bodyDetailsChart) - assert.NotEmpty(t, bodyDetailsChartString) -} - -func RunCompanyCRUD(t *testing.T, bearerToken string) string { - companyID := CreateCompany(t, bearerToken, &accountentities.Company{ - Name: "zup", - }) - allCompanies := ReadAllCompanies(t, bearerToken) - assert.Contains(t, allCompanies, "zup") - UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ - Name: "zup-1", - }) - allCompaniesUpdated := ReadAllCompanies(t, bearerToken) - assert.Contains(t, allCompaniesUpdated, "zup-1") - DeleteCompany(t, bearerToken, companyID) - return CreateCompany(t, bearerToken, &accountentities.Company{ - Name: "zup", + bodyDetailsChart := GetChartDetailsUsingGraphQLAndReturnBody(t, bearerToken, companyID, repositoryID) + bodyDetailsChartString := string(bodyDetailsChart) + assert.NotEmpty(t, bodyDetailsChartString) }) } -func RunRepositoryCRUD(t *testing.T, bearerToken, companyID string) string { - repositoryID := CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ - Name: "horusec", - }) - allRepositories := ReadAllRepositories(t, bearerToken, companyID) - assert.Contains(t, allRepositories, "horusec") - UpdateRepository(t, bearerToken, companyID, repositoryID, &accountentities.Repository{ - Name: "horusec-1", - }) - allRepositoriesUpdated := ReadAllRepositories(t, bearerToken, companyID) - assert.Contains(t, allRepositoriesUpdated, "horusec-1") - DeleteRepository(t, bearerToken, companyID, repositoryID) - return CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ - Name: "horusec", +func RunManagerVulnerabilities(t *testing.T, bearerToken, companyID, repositoryID string) { + t.Run("Should get all vulnerabilities in system and check if all are vulnerabilities after we need update one item to false positive and check if exists how false positive in list", func(t *testing.T) { + allVulnerabilitiesString := GetAllVulnerabilitiesToManager(t, bearerToken, companyID, repositoryID, "page=1&size=10") + allVulnerabilities := dto.VulnManagement{} + assert.NoError(t, json.Unmarshal([]byte(allVulnerabilitiesString), &allVulnerabilities)) + assert.NotEmpty(t, allVulnerabilities) + assert.Equal(t, allVulnerabilities.TotalItems, 11) + assert.Equal(t, len(allVulnerabilities.Data), 10) + for _, vuln := range allVulnerabilities.Data { + assert.Equal(t, vuln.Type, horusecEnums.Vulnerability) + } + vulnIDToUpdate := allVulnerabilities.Data[0].VulnerabilityID.String() + _ = UpdateVulnerabilitiesType(t, bearerToken, companyID, repositoryID, vulnIDToUpdate, dto.UpdateVulnType{Type: horusecEnums.FalsePositive}) + allVulnerabilitiesUpdatedString := GetAllVulnerabilitiesToManager(t, bearerToken, companyID, repositoryID, "page=1&size=11") + allVulnerabilitiesUpdated := dto.VulnManagement{} + assert.NoError(t, json.Unmarshal([]byte(allVulnerabilitiesUpdatedString), &allVulnerabilitiesUpdated)) + assert.NotEmpty(t, allVulnerabilitiesUpdated) + assert.Equal(t, allVulnerabilitiesUpdated.TotalItems, 11) + assert.Equal(t, len(allVulnerabilitiesUpdated.Data), 11) + for _, vuln := range allVulnerabilitiesUpdated.Data { + if vuln.VulnerabilityID.String() == vulnIDToUpdate { + assert.Equal(t, vuln.Type, horusecEnums.FalsePositive) + } else { + assert.Equal(t, vuln.Type, horusecEnums.Vulnerability) + } + } }) } -func RunRepositoryTokenCRUD(t *testing.T, bearerToken, companyID, repositoryID string) string { - _ = GenerateRepositoryToken(t, bearerToken, companyID, repositoryID, api.Token{Description: "access_token"}) - allTokens := ReadAllRepositoryToken(t, bearerToken, companyID, repositoryID) - assert.Contains(t, allTokens, "access_token") - allTokensStruct := []api.Token{} - assert.NoError(t, json.Unmarshal([]byte(allTokens), &allTokensStruct)) - assert.NotEmpty(t, allTokensStruct) - RevokeRepositoryToken(t, bearerToken, companyID, repositoryID, allTokensStruct[0].TokenID.String()) - return GenerateRepositoryToken(t, bearerToken, companyID, repositoryID, api.Token{Description: "access_token"}) +func RunCRUDUserInCompany(t *testing.T, bearerToken, companyID string) { + t.Run("Should create new user and invite to existing company with permission of the member after update your permission to admin and check if is enable view dashboard by company and remove user from company", func(t *testing.T) { + //CreateAccount(t, &accountentities.Account{ + // Email: "e2e_test1@example.com", + // Password: "Ch@ng3m3", + // Username: "e2e_user_test1", + //}) + }) } -func RunCompanyTokenCRUD(t *testing.T, bearerToken string, companyID string) { - _ = GenerateCompanyToken(t, bearerToken, companyID, api.Token{Description: "access_token"}) - allTokens := ReadAllCompanyToken(t, bearerToken, companyID) - assert.Contains(t, allTokens, "access_token") - allTokensStruct := []api.Token{} - assert.NoError(t, json.Unmarshal([]byte(allTokens), &allTokensStruct)) - assert.NotEmpty(t, allTokensStruct) - RevokeCompanyToken(t, bearerToken, companyID, allTokensStruct[0].TokenID.String()) -} diff --git a/e2e/server/requests.go b/e2e/server/requests.go index efe78d3f1..f3d2d2008 100644 --- a/e2e/server/requests.go +++ b/e2e/server/requests.go @@ -6,7 +6,9 @@ import ( "encoding/json" "fmt" accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles" "github.com/ZupIT/horusec/development-kit/pkg/entities/api" + "github.com/ZupIT/horusec/development-kit/pkg/entities/api/dto" "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/client" "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/request" "github.com/stretchr/testify/assert" @@ -307,6 +309,42 @@ func InsertAnalysisWithRepositoryToken(t *testing.T, analysisData *api.AnalysisD return body["content"] } +func InsertAnalysisWithCompanyToken(t *testing.T, analysisData *api.AnalysisData, companyToken string) string { + fmt.Println("Running test for InsertAnalysisWithRepositoryToken") + req, _ := http.NewRequest( + http.MethodPost, + "http://localhost:8000/api/analysis", + bytes.NewReader(analysisData.ToBytes()), + ) + req.Header.Add("Authorization", companyToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "InsertAnalysisWithRepositoryToken error send response") + assert.Equal(t, http.StatusCreated, resp.StatusCode, "InsertAnalysisWithRepositoryToken error check response") + + var body map[string]string + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + return body["content"] +} + +func GetAnalysisByID(t *testing.T, analysisID, authorization string) string { + fmt.Println("Running test for GetAnalysisByID") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/analysis/"+analysisID, nil) + req.Header.Add("Authorization", authorization) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read analysis by ID error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read analysis by ID error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} + func GetChartContent(t *testing.T, route, bearerToken, companyID, repositoryID string) []byte { fmt.Println("Running test for GetChartContent in route: "+ route) fmt.Println("Running test for GetChartRESTContentAndReturnBody") @@ -376,4 +414,106 @@ func GetChartDetailsUsingGraphQLAndReturnBody(t *testing.T, bearerToken, company body, err := res.GetBody() assert.NoError(t, err) return body +} + +func GetAllVulnerabilitiesToManager(t *testing.T, bearerToken, companyID, repositoryID string, queryString string) string { + fmt.Println("Running test for GetAllVulnerabilitiesToManager") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management?" + queryString, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read vulnerabilities error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read vulnerabilities error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func UpdateVulnerabilitiesType(t *testing.T, bearerToken, companyID, repositoryID, vulnerabilityID string, vulnType dto.UpdateVulnType) string { + fmt.Println("Running test for UpdateVulnerabilitiesType") + req, _ := http.NewRequest( + http.MethodPut, + "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management/"+vulnerabilityID+"/type", + bytes.NewReader(vulnType.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update vulnerabilities error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "update vulnerabilities error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *accountentities.InviteUser) { + fmt.Println("Running test for InviteUserToCompany") + req, _ := http.NewRequest( + http.MethodPost, + "http://localhost:8000/api/companies/"+companyID+"/roles", + bytes.NewReader(user.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "invite user error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "invite user error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} +func ReadAllUserInCompany(t *testing.T, bearerToken, companyID string) string { + fmt.Println("Running test for InviteUserToCompany") + req, _ := http.NewRequest( + http.MethodGet, + "http://localhost:8000/api/companies/"+companyID+"/roles", + nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all user in company error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all user in company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} +func UpdateUserInCompany(t *testing.T, bearerToken, companyID, accountID string, account *roles.AccountCompany) string { + fmt.Println("Running test for UpdateUserInCompany") + req, _ := http.NewRequest( + http.MethodPut, + "http://localhost:8000/api/companies/"+companyID+"/roles/"+accountID, + bytes.NewReader(account.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update user in company error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "update user in company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} +func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) { + fmt.Println("Running test for RemoveUserInCompany") + req, _ := http.NewRequest( + http.MethodDelete, + "http://localhost:8000/api/companies/"+companyID+"/roles/"+accountID, + nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete user in company error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete user in company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) } \ No newline at end of file From 14ea86b4ef5d5ab739760ebb60c5742e76346069 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 13:46:35 -0300 Subject: [PATCH 03/34] Adding more tests e2e --- e2e/TESTBOOK.md | 5 +- e2e/server/http_test.go | 164 +++++++++++++++++++++++++++++++++++++--- e2e/server/requests.go | 119 +++++++++++++++++++++++++---- 3 files changed, 259 insertions(+), 29 deletions(-) diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 0b3e18b80..5512267f2 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -30,14 +30,13 @@ - [X] Create, Read, Update, and Delete repositories - [X] Create, Read, and Delete repository token - [ ] Invite, Read, Update and Remove users in company - - [ ] Horusec auth type - - [ ] Ldap auth type + - [X] Horusec auth type - [ ] Keycloak auth - [X] Create and Read analysis - [X] Repository Token - [X] Company Token + repository name - [ ] Invite, Read, Update and Remove users in repository - - [ ] Horusec auth type + - [X] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type - [X] Get Dashboard content diff --git a/e2e/server/http_test.go b/e2e/server/http_test.go index 9f018164c..9493e8250 100644 --- a/e2e/server/http_test.go +++ b/e2e/server/http_test.go @@ -3,12 +3,16 @@ package server import ( "encoding/json" "fmt" + "github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles" "github.com/ZupIT/horusec/development-kit/pkg/entities/api" "github.com/ZupIT/horusec/development-kit/pkg/entities/api/dto" "github.com/ZupIT/horusec/development-kit/pkg/entities/horusec" + rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account" horusecEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/horusec" "github.com/ZupIT/horusec/development-kit/pkg/utils/test" + "github.com/google/uuid" "github.com/stretchr/testify/assert" + "net/http" "os" "testing" @@ -66,10 +70,11 @@ func TestServer(t *testing.T) { Username: "e2e_user", }) // TESTBOOK: Login - Horusec auth type - bearerToken, _ := Login(t, &accountentities.LoginData{ + contentLogin := Login(t, &accountentities.LoginData{ Email: "e2e@example.com", Password: "Ch@ng3m3", }) + bearerToken := contentLogin["accessToken"] // TESTBOOK: Authorize // TESTBOOK: Create, Read, Update and Delete company - Horusec auth type companyID := RunCompanyCRUD(t, bearerToken) @@ -91,6 +96,10 @@ func TestServer(t *testing.T) { RunDashboardByRepository(t, bearerToken, companyID, repositoryID) // TESTBOOK: Get Dashboard content - Repository view RunManagerVulnerabilities(t, bearerToken, companyID, repositoryID) + // TESTBOOK: Invite, Read, Update and Remove users in company - Horusec auth type + RunCRUDUserInCompany(t, bearerToken, companyID) + // TESTBOOK: Invite, Read, Update and Remove users in repository - Horusec auth type + RunCRUDUserInRepository(t, bearerToken, companyID, repositoryID) // TESTBOOK: Logout - Horusec auth type Logout(t, bearerToken) }) @@ -102,12 +111,12 @@ func RunCompanyCRUD(t *testing.T, bearerToken string) string { companyID := CreateCompany(t, bearerToken, &accountentities.Company{ Name: "zup", }) - allCompanies := ReadAllCompanies(t, bearerToken) + allCompanies := ReadAllCompanies(t, bearerToken, true) assert.Contains(t, allCompanies, "zup") UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ Name: "zup-1", }) - allCompaniesUpdated := ReadAllCompanies(t, bearerToken) + allCompaniesUpdated := ReadAllCompanies(t, bearerToken, true) assert.Contains(t, allCompaniesUpdated, "zup-1") DeleteCompany(t, bearerToken, companyID) }) @@ -121,12 +130,12 @@ func RunRepositoryCRUD(t *testing.T, bearerToken, companyID string) string { repositoryID := CreateRepository(t, bearerToken, companyID, &accountentities.Repository{ Name: "horusec", }) - allRepositories := ReadAllRepositories(t, bearerToken, companyID) + allRepositories := ReadAllRepositories(t, bearerToken, companyID, true) assert.Contains(t, allRepositories, "horusec") UpdateRepository(t, bearerToken, companyID, repositoryID, &accountentities.Repository{ Name: "horusec-1", }) - allRepositoriesUpdated := ReadAllRepositories(t, bearerToken, companyID) + allRepositoriesUpdated := ReadAllRepositories(t, bearerToken, companyID, true) assert.Contains(t, allRepositoriesUpdated, "horusec-1") DeleteRepository(t, bearerToken, companyID, repositoryID) }) @@ -286,13 +295,146 @@ func RunManagerVulnerabilities(t *testing.T, bearerToken, companyID, repositoryI }) } -func RunCRUDUserInCompany(t *testing.T, bearerToken, companyID string) { +func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { t.Run("Should create new user and invite to existing company with permission of the member after update your permission to admin and check if is enable view dashboard by company and remove user from company", func(t *testing.T) { - //CreateAccount(t, &accountentities.Account{ - // Email: "e2e_test1@example.com", - // Password: "Ch@ng3m3", - // Username: "e2e_user_test1", - //}) + account2 := &accountentities.Account{ + Email: "e2e_test2@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user_test2", + } + companyIDParsed, _ := uuid.Parse(companyID) + + // Add new user to invite + CreateAccount(t, account2) + + // Invite user to existing company + InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ + Role: rolesEnum.Member, + Email: account2.Email, + CompanyID: companyIDParsed, + }) + + // Check if exist two users in company + allUsersInCompany := ReadAllUserInCompany(t, bearerTokenAccount1, companyID) + accountRoles := []roles.AccountRole{} + assert.NoError(t, json.Unmarshal([]byte(allUsersInCompany), &accountRoles)) + assert.NotEmpty(t, accountRoles) + assert.Equal(t,2, len(accountRoles)) + accountID := "" + for _, user := range accountRoles { + if user.Email == account2.Email { + accountID = user.AccountID.String() + } + } + assert.NotEmpty(t, accountID) + // Login with new user + contentLoginAccount2 := Login(t, &accountentities.LoginData{ + Email: account2.Email, + Password: account2.Password, + }) + bearerTokenAccount2 := contentLoginAccount2["accessToken"] + + // Check if company exists to new user + allCompanies := ReadAllCompanies(t, bearerTokenAccount2, true) + assert.Contains(t, allCompanies, "zup") + + // Expected return unauthorized because user is not admin of company to see dashboard in company view + responseChart := GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") + assert.Equal(t, http.StatusUnauthorized, responseChart.GetStatusCode()) + + // Update permission of new user to admin + UpdateUserInCompany(t, bearerTokenAccount1, companyID, accountID, &roles.AccountCompany{ + Role: rolesEnum.Admin, + }) + + // Expected return OK because user is authorized view dashboard in company view + responseChart = GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") + assert.Equal(t, http.StatusOK, responseChart.GetStatusCode()) + + // Expected remove user from company + RemoveUserInCompany(t, bearerTokenAccount1, companyID, accountID) + + // Not show company for user when get all companies + allCompanies = ReadAllCompanies(t, bearerTokenAccount2, false) + assert.NotContains(t, allCompanies, "zup") + + // Logout session new user + Logout(t, bearerTokenAccount2) + }) +} + +func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repositoryID string) { + t.Run("Should create new user and invite to existing company and invite to existing repository, with permission of the member in repository after update your permission to admin of repository and check if is enable show all tokens in repository and remove user from repository", func(t *testing.T) { + account2 := &accountentities.Account{ + Email: "e2e_test3@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user_test3", + } + companyIDParsed, _ := uuid.Parse(companyID) + + // Add new user to invite + CreateAccount(t, account2) + + // Invite new user to existing company + InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ + Role: rolesEnum.Member, + Email: account2.Email, + CompanyID: companyIDParsed, + }) + // Invite new user to existing repository + InviteUserToRepository(t, bearerTokenAccount1, companyID, repositoryID, &accountentities.InviteUser{ + Role: rolesEnum.Member, + Email: account2.Email, + CompanyID: companyIDParsed, + }) + + // Check if exist two users in repository + allUsersInRepository := ReadAllUserInRepository(t, bearerTokenAccount1, companyID, repositoryID) + accountRoles := []roles.AccountRole{} + assert.NoError(t, json.Unmarshal([]byte(allUsersInRepository), &accountRoles)) + assert.NotEmpty(t, accountRoles) + assert.Equal(t,2, len(accountRoles)) + accountID := "" + for _, user := range accountRoles { + if user.Email == account2.Email { + accountID = user.AccountID.String() + } + } + assert.NotEmpty(t, accountID) + + // Login with new user + contentLoginAccount2 := Login(t, &accountentities.LoginData{ + Email: account2.Email, + Password: account2.Password, + }) + bearerTokenAccount2 := contentLoginAccount2["accessToken"] + + // Check if repository exists to new user + allRepositories := ReadAllRepositories(t, bearerTokenAccount2, companyID, true) + assert.Contains(t, allRepositories, "horusec") + + // Expected return unauthorized because user is not admin of repository to see tokens of repository + responseRepositoryToken := ReadAllRepositoryTokenWithoutTreatment(t, bearerTokenAccount2, companyID, repositoryID) + assert.Equal(t, http.StatusUnauthorized, responseRepositoryToken.GetStatusCode()) + + // Update permission of new user to admin in repository + UpdateUserInRepository(t, bearerTokenAccount1, companyID, repositoryID, accountID, &roles.AccountCompany{ + Role: rolesEnum.Admin, + }) + + // Expected return OK because user is authorized to see tokens of repository + responseRepositoryToken = ReadAllRepositoryTokenWithoutTreatment(t, bearerTokenAccount2, companyID, repositoryID) + assert.Equal(t, http.StatusOK, responseRepositoryToken.GetStatusCode()) + + // Expected remove user from company + RemoveUserInRepository(t, bearerTokenAccount1, companyID, repositoryID, accountID) + + // Not show repository for user when get all repositories + allRepositories = ReadAllRepositories(t, bearerTokenAccount2, companyID, false) + assert.NotContains(t, allRepositories, "horusec") + + // Logout session new user + Logout(t, bearerTokenAccount2) }) } diff --git a/e2e/server/requests.go b/e2e/server/requests.go index f3d2d2008..547d8e4d1 100644 --- a/e2e/server/requests.go +++ b/e2e/server/requests.go @@ -11,6 +11,7 @@ import ( "github.com/ZupIT/horusec/development-kit/pkg/entities/api/dto" "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/client" "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/request" + httpResponse "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/response" "github.com/stretchr/testify/assert" "net/http" "strings" @@ -41,7 +42,7 @@ func ValidateAccount(t *testing.T, accountID string) { } } -func Login(t *testing.T, credentials *accountentities.LoginData) (bearerToken string, refreshToken string) { +func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string { fmt.Println("Running test for Login") loginResp, err := http.Post( "http://localhost:8003/api/account/login", @@ -54,9 +55,7 @@ func Login(t *testing.T, credentials *accountentities.LoginData) (bearerToken st var loginResponse map[string]map[string]string _ = json.NewDecoder(loginResp.Body).Decode(&loginResponse) assert.NoError(t, loginResp.Body.Close()) - bearerToken = "Bearer " + loginResponse["content"]["accessToken"] - refreshToken = loginResponse["content"]["refreshToken"] - return bearerToken, refreshToken + return loginResponse["content"] } func Logout(t *testing.T, bearerToken string) { @@ -102,7 +101,7 @@ func UpdateCompany(t *testing.T, bearerToken string, companyID string, company * assert.NotEmpty(t, body["content"]) } -func ReadAllCompanies(t *testing.T, bearerToken string) string { +func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) string { fmt.Println("Running test for ReadAllCompanies") req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) req.Header.Add("Authorization", bearerToken) @@ -113,7 +112,9 @@ func ReadAllCompanies(t *testing.T, bearerToken string) string { var body map[string]interface{} _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) - assert.NotEmpty(t, body["content"]) + if isCheckBodyEmpty { + assert.NotEmpty(t, body["content"]) + } content, _ := json.Marshal(body["content"]) return string(content) } @@ -162,7 +163,7 @@ func UpdateRepository(t *testing.T, bearerToken, companyID, repositoryID string, assert.NoError(t, resp.Body.Close()) } -func ReadAllRepositories(t *testing.T, bearerToken, companyID string) string { +func ReadAllRepositories(t *testing.T, bearerToken, companyID string, isCheckBodyEmpty bool) string { fmt.Println("Running test for ReadAllRepositories") req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies/"+companyID+"/repositories", nil) req.Header.Add("Authorization", bearerToken) @@ -173,7 +174,9 @@ func ReadAllRepositories(t *testing.T, bearerToken, companyID string) string { var body map[string]interface{} _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) - assert.NotEmpty(t, body["content"]) + if isCheckBodyEmpty { + assert.NotEmpty(t, body["content"]) + } content, _ := json.Marshal(body["content"]) return string(content) } @@ -226,7 +229,14 @@ func ReadAllRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID s content, _ := json.Marshal(body["content"]) return string(content) } - +func ReadAllRepositoryTokenWithoutTreatment(t *testing.T, bearerToken, companyID, repositoryID string) httpResponse.Interface { + fmt.Println("Running test for ReadAllRepositoryToken") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", nil) + req.Header.Add("Authorization", bearerToken) + res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) + assert.NoError(t, err) + return res +} func RevokeRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID, tokenID string) { fmt.Println("Running test for RevokeRepositoryToken") req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens/"+tokenID, nil) @@ -450,12 +460,11 @@ func UpdateVulnerabilitiesType(t *testing.T, bearerToken, companyID, repositoryI content, _ := json.Marshal(body["content"]) return string(content) } - func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *accountentities.InviteUser) { fmt.Println("Running test for InviteUserToCompany") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8000/api/companies/"+companyID+"/roles", + "http://localhost:8003/api/companies/"+companyID+"/roles", bytes.NewReader(user.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -470,7 +479,7 @@ func ReadAllUserInCompany(t *testing.T, bearerToken, companyID string) string { fmt.Println("Running test for InviteUserToCompany") req, _ := http.NewRequest( http.MethodGet, - "http://localhost:8000/api/companies/"+companyID+"/roles", + "http://localhost:8003/api/companies/"+companyID+"/roles", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -487,8 +496,8 @@ func ReadAllUserInCompany(t *testing.T, bearerToken, companyID string) string { func UpdateUserInCompany(t *testing.T, bearerToken, companyID, accountID string, account *roles.AccountCompany) string { fmt.Println("Running test for UpdateUserInCompany") req, _ := http.NewRequest( - http.MethodPut, - "http://localhost:8000/api/companies/"+companyID+"/roles/"+accountID, + http.MethodPatch, + "http://localhost:8003/api/companies/"+companyID+"/roles/"+accountID, bytes.NewReader(account.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -506,7 +515,7 @@ func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) fmt.Println("Running test for RemoveUserInCompany") req, _ := http.NewRequest( http.MethodDelete, - "http://localhost:8000/api/companies/"+companyID+"/roles/"+accountID, + "http://localhost:8003/api/companies/"+companyID+"/roles/"+accountID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -516,4 +525,84 @@ func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) var body map[string]interface{} _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) +} +func GetChartContentWithoutTreatment(t *testing.T, route, bearerToken, companyID, repositoryID string) httpResponse.Interface { + fmt.Println("Running test for GetChartContent in route: "+ route) + fmt.Println("Running test for GetChartRESTContentAndReturnBody") + now := time.Now() + initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" + finalDateStr := now.Format("2006-01-02") + "T23:59:59Z" + URL := fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/%s?initialDate=%s&finalDate=%s", companyID, route, initialDateStr, finalDateStr) + if repositoryID != "" { + URL = fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/repositories/%s/%s?initialDate=%s&finalDate=%s", companyID, repositoryID, route, initialDateStr, finalDateStr) + } + req, err := request.NewHTTPRequest().Request(http.MethodGet, URL, nil, map[string]string{"Authorization": bearerToken, "Content-type": "application/json"}) + assert.NoError(t, err) + res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) + assert.NoError(t, err) + return res +} + +func InviteUserToRepository(t *testing.T, bearerToken, companyID, repositoryID string, user *accountentities.InviteUser) { + fmt.Println("Running test for InviteUserToRepository") + req, _ := http.NewRequest( + http.MethodPost, + "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles", + bytes.NewReader(user.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "invite user in repository error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "invite user in repository error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} +func ReadAllUserInRepository(t *testing.T, bearerToken, companyID, repositoryID string) string { + fmt.Println("Running test for InviteUserToCompany") + req, _ := http.NewRequest( + http.MethodGet, + "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles", + nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all user in repository error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all user in repository error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} +func UpdateUserInRepository(t *testing.T, bearerToken, companyID, repositoryID, accountID string, account *roles.AccountCompany) { + fmt.Println("Running test for UpdateUserInRepository") + req, _ := http.NewRequest( + http.MethodPatch, + "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles/"+accountID, + bytes.NewReader(account.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update user in repository error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "update user in repository error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} +func RemoveUserInRepository(t *testing.T, bearerToken, companyID, repositoryID, accountID string) { + fmt.Println("Running test for RemoveUserInRepository") + req, _ := http.NewRequest( + http.MethodDelete, + "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles/"+accountID, + nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete user in repository error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete user in repository error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) } \ No newline at end of file From 335d923cd2531c9a8df9145361be6f96ce87e4d1 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 13:49:50 -0300 Subject: [PATCH 04/34] Fixing fmt lint --- .../pkg/entities/account/invite_user.go | 2 +- .../pkg/entities/account/invite_user_test.go | 2 +- .../account/roles/account_company_test.go | 2 +- e2e/server/http_test.go | 51 +++++++++---------- e2e/server/requests.go | 8 +-- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/development-kit/pkg/entities/account/invite_user.go b/development-kit/pkg/entities/account/invite_user.go index 1c9fab3d6..746428630 100644 --- a/development-kit/pkg/entities/account/invite_user.go +++ b/development-kit/pkg/entities/account/invite_user.go @@ -65,4 +65,4 @@ func (i *InviteUser) SetInviteUserRepositoryAndCompanyID(companyID, repositoryID func (i *InviteUser) ToBytes() []byte { content, _ := json.Marshal(i) return content -} \ No newline at end of file +} diff --git a/development-kit/pkg/entities/account/invite_user_test.go b/development-kit/pkg/entities/account/invite_user_test.go index aaa7796d9..1e8b8c31c 100644 --- a/development-kit/pkg/entities/account/invite_user_test.go +++ b/development-kit/pkg/entities/account/invite_user_test.go @@ -70,4 +70,4 @@ func TestInviteUserToBytes(t *testing.T) { } assert.NotEmpty(t, inviteUser.ToBytes()) }) -} \ No newline at end of file +} diff --git a/development-kit/pkg/entities/account/roles/account_company_test.go b/development-kit/pkg/entities/account/roles/account_company_test.go index 8ca588be6..e97a452c5 100644 --- a/development-kit/pkg/entities/account/roles/account_company_test.go +++ b/development-kit/pkg/entities/account/roles/account_company_test.go @@ -92,4 +92,4 @@ func TestAccountCompanyToBytes(t *testing.T) { } assert.NotEmpty(t, inviteUser.ToBytes()) }) -} \ No newline at end of file +} diff --git a/e2e/server/http_test.go b/e2e/server/http_test.go index 9493e8250..14ece38f4 100644 --- a/e2e/server/http_test.go +++ b/e2e/server/http_test.go @@ -65,9 +65,9 @@ func TestServer(t *testing.T) { t.Run("Should tests default auth-type (horusec) http requests", func(t *testing.T) { // TESTBOOK: Create account - Horusec auth type CreateAccount(t, &accountentities.Account{ - Email: "e2e@example.com", - Password: "Ch@ng3m3", - Username: "e2e_user", + Email: "e2e@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user", }) // TESTBOOK: Login - Horusec auth type contentLogin := Login(t, &accountentities.LoginData{ @@ -109,19 +109,19 @@ func TestServer(t *testing.T) { func RunCompanyCRUD(t *testing.T, bearerToken string) string { t.Run("Should create an company, check if it exists, update your name check if name was updated delete a company and return new company to manager in other steps", func(t *testing.T) { companyID := CreateCompany(t, bearerToken, &accountentities.Company{ - Name: "zup", + Name: "zup", }) allCompanies := ReadAllCompanies(t, bearerToken, true) assert.Contains(t, allCompanies, "zup") UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ - Name: "zup-1", + Name: "zup-1", }) allCompaniesUpdated := ReadAllCompanies(t, bearerToken, true) assert.Contains(t, allCompaniesUpdated, "zup-1") DeleteCompany(t, bearerToken, companyID) }) return CreateCompany(t, bearerToken, &accountentities.Company{ - Name: "zup", + Name: "zup", }) } @@ -133,7 +133,7 @@ func RunRepositoryCRUD(t *testing.T, bearerToken, companyID string) string { allRepositories := ReadAllRepositories(t, bearerToken, companyID, true) assert.Contains(t, allRepositories, "horusec") UpdateRepository(t, bearerToken, companyID, repositoryID, &accountentities.Repository{ - Name: "horusec-1", + Name: "horusec-1", }) allRepositoriesUpdated := ReadAllRepositories(t, bearerToken, companyID, true) assert.Contains(t, allRepositoriesUpdated, "horusec-1") @@ -183,7 +183,7 @@ func RunAnalysisRoutes(t *testing.T, repositoryToken, companyToken string) { }) t.Run("Should create an analysis using company token and check if exists your content in system", func(t *testing.T) { analysisIDInsertedWithCompanyToken := InsertAnalysisWithCompanyToken(t, &api.AnalysisData{ - Analysis: test.CreateAnalysisMock(), + Analysis: test.CreateAnalysisMock(), RepositoryName: "new-repository", }, companyToken) contentInsertedWithCompanyToken := GetAnalysisByID(t, analysisIDInsertedWithCompanyToken, repositoryToken) @@ -298,9 +298,9 @@ func RunManagerVulnerabilities(t *testing.T, bearerToken, companyID, repositoryI func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { t.Run("Should create new user and invite to existing company with permission of the member after update your permission to admin and check if is enable view dashboard by company and remove user from company", func(t *testing.T) { account2 := &accountentities.Account{ - Email: "e2e_test2@example.com", - Password: "Ch@ng3m3", - Username: "e2e_user_test2", + Email: "e2e_test2@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user_test2", } companyIDParsed, _ := uuid.Parse(companyID) @@ -309,9 +309,9 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { // Invite user to existing company InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ - Role: rolesEnum.Member, - Email: account2.Email, - CompanyID: companyIDParsed, + Role: rolesEnum.Member, + Email: account2.Email, + CompanyID: companyIDParsed, }) // Check if exist two users in company @@ -319,7 +319,7 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { accountRoles := []roles.AccountRole{} assert.NoError(t, json.Unmarshal([]byte(allUsersInCompany), &accountRoles)) assert.NotEmpty(t, accountRoles) - assert.Equal(t,2, len(accountRoles)) + assert.Equal(t, 2, len(accountRoles)) accountID := "" for _, user := range accountRoles { if user.Email == account2.Email { @@ -366,9 +366,9 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repositoryID string) { t.Run("Should create new user and invite to existing company and invite to existing repository, with permission of the member in repository after update your permission to admin of repository and check if is enable show all tokens in repository and remove user from repository", func(t *testing.T) { account2 := &accountentities.Account{ - Email: "e2e_test3@example.com", - Password: "Ch@ng3m3", - Username: "e2e_user_test3", + Email: "e2e_test3@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user_test3", } companyIDParsed, _ := uuid.Parse(companyID) @@ -377,15 +377,15 @@ func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repos // Invite new user to existing company InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ - Role: rolesEnum.Member, - Email: account2.Email, - CompanyID: companyIDParsed, + Role: rolesEnum.Member, + Email: account2.Email, + CompanyID: companyIDParsed, }) // Invite new user to existing repository InviteUserToRepository(t, bearerTokenAccount1, companyID, repositoryID, &accountentities.InviteUser{ - Role: rolesEnum.Member, - Email: account2.Email, - CompanyID: companyIDParsed, + Role: rolesEnum.Member, + Email: account2.Email, + CompanyID: companyIDParsed, }) // Check if exist two users in repository @@ -393,7 +393,7 @@ func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repos accountRoles := []roles.AccountRole{} assert.NoError(t, json.Unmarshal([]byte(allUsersInRepository), &accountRoles)) assert.NotEmpty(t, accountRoles) - assert.Equal(t,2, len(accountRoles)) + assert.Equal(t, 2, len(accountRoles)) accountID := "" for _, user := range accountRoles { if user.Email == account2.Email { @@ -437,4 +437,3 @@ func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repos Logout(t, bearerTokenAccount2) }) } - diff --git a/e2e/server/requests.go b/e2e/server/requests.go index 547d8e4d1..696522ddb 100644 --- a/e2e/server/requests.go +++ b/e2e/server/requests.go @@ -356,7 +356,7 @@ func GetAnalysisByID(t *testing.T, analysisID, authorization string) string { } func GetChartContent(t *testing.T, route, bearerToken, companyID, repositoryID string) []byte { - fmt.Println("Running test for GetChartContent in route: "+ route) + fmt.Println("Running test for GetChartContent in route: " + route) fmt.Println("Running test for GetChartRESTContentAndReturnBody") now := time.Now() initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" @@ -428,7 +428,7 @@ func GetChartDetailsUsingGraphQLAndReturnBody(t *testing.T, bearerToken, company func GetAllVulnerabilitiesToManager(t *testing.T, bearerToken, companyID, repositoryID string, queryString string) string { fmt.Println("Running test for GetAllVulnerabilitiesToManager") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management?" + queryString, nil) + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management?"+queryString, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -527,7 +527,7 @@ func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) assert.NoError(t, resp.Body.Close()) } func GetChartContentWithoutTreatment(t *testing.T, route, bearerToken, companyID, repositoryID string) httpResponse.Interface { - fmt.Println("Running test for GetChartContent in route: "+ route) + fmt.Println("Running test for GetChartContent in route: " + route) fmt.Println("Running test for GetChartRESTContentAndReturnBody") now := time.Now() initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" @@ -605,4 +605,4 @@ func RemoveUserInRepository(t *testing.T, bearerToken, companyID, repositoryID, var body map[string]interface{} _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) -} \ No newline at end of file +} From c5394ecfc99ee66d7aeab2cdf12daf047bc17b47 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 14:35:25 -0300 Subject: [PATCH 05/34] Update test e2e --- Makefile | 8 ++--- ...aml => docker-compose.server.horusec.yaml} | 32 ------------------- e2e/server/{ => horusec}/http_test.go | 26 +++++++-------- e2e/server/{ => horusec}/requests.go | 2 +- e2e/server/keycloak/http_test.go | 1 + e2e/server/ldap/http_test.go | 1 + 6 files changed, 17 insertions(+), 53 deletions(-) rename e2e/deployments/{docker-compose.yaml => docker-compose.server.horusec.yaml} (73%) rename e2e/server/{ => horusec}/http_test.go (96%) rename e2e/server/{ => horusec}/requests.go (99%) create mode 100644 e2e/server/keycloak/http_test.go create mode 100644 e2e/server/ldap/http_test.go diff --git a/Makefile b/Makefile index 9f1abc754..aede64ff6 100644 --- a/Makefile +++ b/Makefile @@ -46,12 +46,13 @@ test: $(GO) clean -testcache && $(GO) test -v ./... -timeout=2m -parallel=1 -failfast -short test-e2e: - make compose-e2e + docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v go get -v ./e2e/... go get -v ./horusec-cli/... $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast - $(GO) test -v ./e2e/server/... -timeout=5m -parallel=1 -failfast + docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate + $(GO) test -v ./e2e/server/horusec/... -timeout=5m -parallel=1 -failfast # Run all steps required to pass on pipeline pipeline: fmt lint test coverage build install-manager lint-manager build-manager @@ -96,9 +97,6 @@ compose-horusec-analytic: docker-compose -f horusec-analytic/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-auth: docker-compose -f horusec-auth/deployments/docker-compose.yaml up -d --build --force-recreate -compose-e2e: - docker-compose -f e2e/deployments/docker-compose.yaml down -v - docker-compose -f e2e/deployments/docker-compose.yaml up -d --build --force-recreate # ========================================================================================= # diff --git a/e2e/deployments/docker-compose.yaml b/e2e/deployments/docker-compose.server.horusec.yaml similarity index 73% rename from e2e/deployments/docker-compose.yaml rename to e2e/deployments/docker-compose.server.horusec.yaml index 2cada0643..06251bfc4 100644 --- a/e2e/deployments/docker-compose.yaml +++ b/e2e/deployments/docker-compose.server.horusec.yaml @@ -1,11 +1,5 @@ version: '3' services: -# rabbit: -# container_name: rabbit -# image: rabbitmq:3-management -# ports: -# - "5672:5672" -# - "15672:15672" postgresql: container_name: postgresql image: postgres:12 @@ -22,33 +16,11 @@ services: driver: json-file options: max-size: 10m -# horusec-messages: -# build: -# context: ../../ -# dockerfile: ./horusec-messages/deployments/Dockerfile.dev -# depends_on: -# - "rabbit" -# restart: always -# container_name: horusec-messages -# ports: -# - "8004:8004" -# environment: -# HORUSEC_BROKER_HOST: rabbit -# HORUSEC_BROKER_PORT: "5672" -# HORUSEC_BROKER_USERNAME: "guest" -# HORUSEC_BROKER_PASSWORD: "guest" -# HORUSEC_SMTP_ADDRESS: "smtp.mailtrap.io" -# HORUSEC_SMTP_USERNAME: ${HORUSEC_SMTP_USERNAME} -# HORUSEC_SMTP_PASSWORD: ${HORUSEC_SMTP_PASSWORD} -# HORUSEC_SMTP_HOST: "smtp.mailtrap.io" -# HORUSEC_SMTP_PORT: "2525" -# HORUSEC_EMAIL_FROM: "horusec@zup.com.br" horusec-account: build: context: ../../ dockerfile: ./horusec-account/deployments/Dockerfile.dev depends_on: -# - "rabbit" - postgresql restart: always container_name: horusec-account @@ -56,10 +28,6 @@ services: - "8003:8003" environment: HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" -# HORUSEC_BROKER_HOST: rabbit -# HORUSEC_BROKER_PORT: "5672" -# HORUSEC_BROKER_USERNAME: "guest" -# HORUSEC_BROKER_PASSWORD: "guest" HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" diff --git a/e2e/server/http_test.go b/e2e/server/horusec/http_test.go similarity index 96% rename from e2e/server/http_test.go rename to e2e/server/horusec/http_test.go index 14ece38f4..dc2048fe9 100644 --- a/e2e/server/http_test.go +++ b/e2e/server/horusec/http_test.go @@ -1,4 +1,4 @@ -package server +package horusec import ( "encoding/json" @@ -25,10 +25,9 @@ import ( ) func TestMain(m *testing.M) { - migration, err := migrate.New( - "file://../../development-kit/pkg/databases/relational/migration", - env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable"), - ) + folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" + connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + migration, err := migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create first instance migration: ", err) } @@ -42,10 +41,7 @@ func TestMain(m *testing.M) { if dbErr != nil { logger.LogPanic("Error in database err to close connection: ", dbErr) } - migration, err = migrate.New( - "file://../../development-kit/pkg/databases/relational/migration", - env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable"), - ) + migration, err = migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create second instance migration: ", err) } @@ -63,20 +59,20 @@ func TestServer(t *testing.T) { t.Skip("skipping integration test") } t.Run("Should tests default auth-type (horusec) http requests", func(t *testing.T) { - // TESTBOOK: Create account - Horusec auth type + // TESTBOOK: Create account CreateAccount(t, &accountentities.Account{ Email: "e2e@example.com", Password: "Ch@ng3m3", Username: "e2e_user", }) - // TESTBOOK: Login - Horusec auth type + // TESTBOOK: Login contentLogin := Login(t, &accountentities.LoginData{ Email: "e2e@example.com", Password: "Ch@ng3m3", }) bearerToken := contentLogin["accessToken"] // TESTBOOK: Authorize - // TESTBOOK: Create, Read, Update and Delete company - Horusec auth type + // TESTBOOK: Create, Read, Update and Delete company companyID := RunCompanyCRUD(t, bearerToken) // TESTBOOK: Authorize // TESTBOOK: Create, Read, Update, and Delete repositories @@ -96,11 +92,11 @@ func TestServer(t *testing.T) { RunDashboardByRepository(t, bearerToken, companyID, repositoryID) // TESTBOOK: Get Dashboard content - Repository view RunManagerVulnerabilities(t, bearerToken, companyID, repositoryID) - // TESTBOOK: Invite, Read, Update and Remove users in company - Horusec auth type + // TESTBOOK: Invite, Read, Update and Remove users in company RunCRUDUserInCompany(t, bearerToken, companyID) - // TESTBOOK: Invite, Read, Update and Remove users in repository - Horusec auth type + // TESTBOOK: Invite, Read, Update and Remove users in repository RunCRUDUserInRepository(t, bearerToken, companyID, repositoryID) - // TESTBOOK: Logout - Horusec auth type + // TESTBOOK: Logout Logout(t, bearerToken) }) fmt.Println("All tests was finished in server test") diff --git a/e2e/server/requests.go b/e2e/server/horusec/requests.go similarity index 99% rename from e2e/server/requests.go rename to e2e/server/horusec/requests.go index 696522ddb..ba001759f 100644 --- a/e2e/server/requests.go +++ b/e2e/server/horusec/requests.go @@ -1,4 +1,4 @@ -package server +package horusec import ( "bytes" diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go new file mode 100644 index 000000000..c9405cca8 --- /dev/null +++ b/e2e/server/keycloak/http_test.go @@ -0,0 +1 @@ +package ldap diff --git a/e2e/server/ldap/http_test.go b/e2e/server/ldap/http_test.go new file mode 100644 index 000000000..c9405cca8 --- /dev/null +++ b/e2e/server/ldap/http_test.go @@ -0,0 +1 @@ +package ldap From 375daa069269531372f4cced9e1c0e0397d6af82 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 14:36:49 -0300 Subject: [PATCH 06/34] Update test e2e --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index aede64ff6..fbc909a1e 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,8 @@ test: test-e2e: docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v - go get -v ./e2e/... - go get -v ./horusec-cli/... + $(GO) get -v ./e2e/... + $(GO) get -v ./horusec-cli/... $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate From 3a9c762263e04cc963e02d662ff571fee60ecc35 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 15:09:04 -0300 Subject: [PATCH 07/34] Fixing workflow e2e --- .github/workflows/e2e.yml | 18 +++++++++--------- Makefile | 6 +++--- e2e/server/broker/broker_test.go | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 e2e/server/broker/broker_test.go diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6b63929a7..ca36a9ca2 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -12,12 +12,12 @@ jobs: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" steps: - - name: Set up Go 1.14 - uses: actions/setup-go@v1 - with: - go-version: 1.14 - id: go - - name: Check out code - uses: actions/checkout@v2 - - name: e2e - run: make test-e2e + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Check out code + uses: actions/checkout@v2 + - name: e2e + run: make test-e2e \ No newline at end of file diff --git a/Makefile b/Makefile index fbc909a1e..83aa06f35 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,8 @@ test: test-e2e: docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v - $(GO) get -v ./e2e/... - $(GO) get -v ./horusec-cli/... + go get -v ./e2e/... + go get -v ./horusec-cli/... $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate @@ -149,4 +149,4 @@ build-install-java-cli: update-cli: chmod +x ./horusec-cli/deployments/scripts/update-image.sh - ./horusec-cli/deployments/scripts/update-image.sh $UPDATE_TYPE $SEND_NEW_VERSION_TO_S3 $IS_TO_UPDATE_LATEST + ./horusec-cli/deployments/scripts/update-image.sh $UPDATE_TYPE $SEND_NEW_VERSION_TO_S3 $IS_TO_UPDATE_LATEST \ No newline at end of file diff --git a/e2e/server/broker/broker_test.go b/e2e/server/broker/broker_test.go new file mode 100644 index 000000000..d749cad13 --- /dev/null +++ b/e2e/server/broker/broker_test.go @@ -0,0 +1 @@ +package broker From 3b727ddb3277b93bef6f86772bc66363266a52f4 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 15:14:24 -0300 Subject: [PATCH 08/34] Fixing e2e running --- .github/workflows/e2e.yml | 20 +++++++++++++++++--- Makefile | 9 +++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ca36a9ca2..3548abe0a 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -7,8 +7,8 @@ on: branches: [ "**" ] jobs: - install-build-test-fmt-lint: - name: install-build-test-fmt-lint + e2e-cli: + name: e2e-cli runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" steps: @@ -20,4 +20,18 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: e2e - run: make test-e2e \ No newline at end of file + run: make test-e2e-cli + e2e-server-horusec: + name: e2e-server-horusec + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Check out code + uses: actions/checkout@v2 + - name: e2e + run: make test-e2e-server-horusec \ No newline at end of file diff --git a/Makefile b/Makefile index 83aa06f35..2f3d52033 100644 --- a/Makefile +++ b/Makefile @@ -45,15 +45,20 @@ lint: test: $(GO) clean -testcache && $(GO) test -v ./... -timeout=2m -parallel=1 -failfast -short -test-e2e: - docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v +test-e2e-cli: go get -v ./e2e/... go get -v ./horusec-cli/... $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast +test-e2e-server-horusec: + docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate + go get -v ./e2e/... + $(GO) clean -testcache $(GO) test -v ./e2e/server/horusec/... -timeout=5m -parallel=1 -failfast +# ========================================================================================= # + # Run all steps required to pass on pipeline pipeline: fmt lint test coverage build install-manager lint-manager build-manager From 8309dfdce1261f66b72e2853dc61bc9a9b906717 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 16:25:20 -0300 Subject: [PATCH 09/34] Adding validation to restart service with up migratin --- .github/workflows/e2e.yml | 16 ++- Makefile | 16 ++- e2e/TESTBOOK.md | 2 +- e2e/application_admin/horusec/http_test.go | 112 +++++++++++++++++ e2e/application_admin/horusec/requests.go | 114 ++++++++++++++++++ e2e/application_admin/keycloak/http_test.go | 1 + e2e/application_admin/ldap/http_test.go | 1 + ...ker-compose.application-admin.horusec.yaml | 51 ++++++++ .../docker-compose.server.broker.yaml | 83 +++++++++++++ .../docker-compose.server.horusec.yaml | 4 - e2e/server/horusec/requests.go | 11 -- 11 files changed, 391 insertions(+), 20 deletions(-) create mode 100644 e2e/application_admin/horusec/http_test.go create mode 100644 e2e/application_admin/horusec/requests.go create mode 100644 e2e/application_admin/keycloak/http_test.go create mode 100644 e2e/application_admin/ldap/http_test.go create mode 100644 e2e/deployments/docker-compose.application-admin.horusec.yaml create mode 100644 e2e/deployments/docker-compose.server.broker.yaml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 3548abe0a..53d8e7f35 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -34,4 +34,18 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: e2e - run: make test-e2e-server-horusec \ No newline at end of file + run: make test-e2e-server-horusec + e2e-application-admin-horusec: + name: e2e-application-admin-horusec + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Check out code + uses: actions/checkout@v2 + - name: e2e + run: test-e2e-application-admin-horusec \ No newline at end of file diff --git a/Makefile b/Makefile index 2f3d52033..aaa2e1612 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ lint: # Run all tests of project but stop the execution on the first test fail test: - $(GO) clean -testcache && $(GO) test -v ./... -timeout=2m -parallel=1 -failfast -short + $(GO) clean -testcache && $(GO) test -v ./... -timeout=20m -parallel=1 -failfast -short test-e2e-cli: go get -v ./e2e/... @@ -51,11 +51,15 @@ test-e2e-cli: $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast test-e2e-server-horusec: - docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v - docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate + make compose-e2e-server-horusec go get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/server/horusec/... -timeout=5m -parallel=1 -failfast +test-e2e-application-admin-horusec: + make compose-e2e-application-admin-horusec + go get -v ./e2e/... + $(GO) clean -testcache + $(GO) test -v ./e2e/application_admin/horusec/... -timeout=5m -parallel=1 -failfast # ========================================================================================= # @@ -102,6 +106,12 @@ compose-horusec-analytic: docker-compose -f horusec-analytic/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-auth: docker-compose -f horusec-auth/deployments/docker-compose.yaml up -d --build --force-recreate +compose-e2e-server-horusec: + docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v + docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate +compose-e2e-application-admin-horusec: + docker-compose -f e2e/deployments/docker-compose.application-admin.horusec.yaml down -v + docker-compose -f e2e/deployments/docker-compose.application-admin.horusec.yaml up -d --build --force-recreate # ========================================================================================= # diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 5512267f2..0126792cb 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -23,7 +23,7 @@ - [ ] Ldap auth type - [ ] Keycloak auth type - [ ] Create, Read, Update and Delete company with application admin enable - - [ ] Horusec auth type + - [X] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type - [X] Create, Read, and Delete company token diff --git a/e2e/application_admin/horusec/http_test.go b/e2e/application_admin/horusec/http_test.go new file mode 100644 index 000000000..07292fa57 --- /dev/null +++ b/e2e/application_admin/horusec/http_test.go @@ -0,0 +1,112 @@ +package horusec + +import ( + "fmt" + accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/utils/env" + "github.com/ZupIT/horusec/development-kit/pkg/utils/logger" + "github.com/golang-migrate/migrate/v4" + _ "github.com/golang-migrate/migrate/v4/database/postgres" + _ "github.com/golang-migrate/migrate/v4/source/file" + "github.com/stretchr/testify/assert" + "os" + "os/exec" + "testing" + "time" +) + +func TestMain(m *testing.M) { + folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" + connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + migration, err := migrate.New(folderOfMigration, connectionStringDB) + if err != nil { + logger.LogPanic("Error in create first instance migration: ", err) + } + if err := migration.Drop(); err != nil { + logger.LogPanic("Error in drop migration: ", err) + } + sourceErr, dbErr := migration.Close() + if sourceErr != nil { + logger.LogPanic("Error in source err to close connection: ", sourceErr) + } + if dbErr != nil { + logger.LogPanic("Error in database err to close connection: ", dbErr) + } + migration, err = migrate.New(folderOfMigration, connectionStringDB) + if err != nil { + logger.LogPanic("Error in create second instance migration: ", err) + } + if err := migration.Up(); err != nil { + if err.Error() != "no change" { + logger.LogPanic("Error in up migration: ", err) + } + } + output, err := exec.Command("docker", "restart", "horusec-auth").Output() + if err != nil { + logger.LogPanic("Error restart auth service: " + string(output), err) + } + time.Sleep(2 * time.Second) + code := m.Run() + os.Exit(code) +} + +func TestServer(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + t.Run("Should tests default auth-type (horusec) http requests in application admin enable", func(t *testing.T) { + // Login with default application admin + contentLogin := Login(t, &accountentities.LoginData{ + Email: "horusec-admin@example.com", + Password: "Devpass0*", + }) + bearerToken := contentLogin["accessToken"] + + // create company and add to logged user + companyID := CreateCompanyApplicationAdmin(t, bearerToken, &accountentities.CompanyApplicationAdmin{ + Name: "zup", + AdminEmail: "horusec-admin@example.com", + }) + // check if company show to logged user + allCompanies := ReadAllCompanies(t, bearerToken, true) + assert.Contains(t, allCompanies, "zup") + // Update company name + UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ + Name: "zup-1", + }) + // Check if company was updated + allCompaniesUpdated := ReadAllCompanies(t, bearerToken, true) + assert.Contains(t, allCompaniesUpdated, "zup-1") + // Delete company + DeleteCompany(t, bearerToken, companyID) + + // Create new user + CreateAccount(t, &accountentities.Account{ + Email: "e2e@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user", + }) + // Create new company to new user in system + _ = CreateCompanyApplicationAdmin(t, bearerToken, &accountentities.CompanyApplicationAdmin{ + Name: "zup", + AdminEmail: "e2e@example.com", + }) + // Not can possible show company to first user + allCompanies = ReadAllCompanies(t, bearerToken, false) + assert.NotContains(t, allCompanies, "zup") + + // Login with new user + contentLoginNewUser := Login(t, &accountentities.LoginData{ + Email: "e2e@example.com", + Password: "Ch@ng3m3", + }) + bearerTokenNewUser := contentLoginNewUser["accessToken"] + // Check if exists an company for new user + allCompanies = ReadAllCompanies(t, bearerTokenNewUser, true) + assert.Contains(t, allCompanies, "zup") + // Logout both users + Logout(t, bearerToken) + Logout(t, bearerTokenNewUser) + }) + fmt.Println("All tests was finished in server test") +} diff --git a/e2e/application_admin/horusec/requests.go b/e2e/application_admin/horusec/requests.go new file mode 100644 index 000000000..d795df9c5 --- /dev/null +++ b/e2e/application_admin/horusec/requests.go @@ -0,0 +1,114 @@ +package horusec + +import ( + "bytes" + "encoding/json" + "fmt" + accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +func CreateAccount(t *testing.T, account *accountentities.Account) { + fmt.Println("Running test for CreateAccount") + createAccountResp, err := http.Post("http://localhost:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) + assert.NoError(t, err, "create account error mount request") + assert.Equal(t, http.StatusCreated, createAccountResp.StatusCode, "create account error send request") + + var createAccountResponse map[string]interface{} + _ = json.NewDecoder(createAccountResp.Body).Decode(&createAccountResponse) + assert.NoError(t, createAccountResp.Body.Close()) + assert.NotEmpty(t, createAccountResponse["content"]) +} + +func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string { + fmt.Println("Running test for Login") + loginResp, err := http.Post( + "http://localhost:8003/api/account/login", + "text/json", + bytes.NewReader(credentials.ToBytes()), + ) + assert.NoError(t, err, "login, error mount request") + assert.Equal(t, http.StatusOK, loginResp.StatusCode, "login error send request") + + var loginResponse map[string]map[string]string + _ = json.NewDecoder(loginResp.Body).Decode(&loginResponse) + assert.NoError(t, loginResp.Body.Close()) + return loginResponse["content"] +} + +func Logout(t *testing.T, bearerToken string) { + fmt.Println("Running test for Logout") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/account/logout", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "logout error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "logout error send request") + + var logoutResponse map[string]map[string]string + _ = json.NewDecoder(resp.Body).Decode(&logoutResponse) + assert.NoError(t, resp.Body.Close()) +} + +func CreateCompanyApplicationAdmin(t *testing.T, bearerToken string, company *accountentities.CompanyApplicationAdmin) (CompanyID string) { + companyBytes, _ := json.Marshal(company) + fmt.Println("Running test for CreateCompany") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(companyBytes)) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + createCompanyResp, err := httpClient.Do(req) + assert.NoError(t, err, "create company error send request") + assert.Equal(t, http.StatusCreated, createCompanyResp.StatusCode, "create company error check response") + var createdCompany map[string]map[string]string + _ = json.NewDecoder(createCompanyResp.Body).Decode(&createdCompany) + assert.NoError(t, createCompanyResp.Body.Close()) + assert.NotEmpty(t, createdCompany["content"]["companyID"]) + return createdCompany["content"]["companyID"] +} + +func UpdateCompany(t *testing.T, bearerToken string, companyID string, company *accountentities.Company) { + fmt.Println("Running test for UpdateCompany") + req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update company error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "update company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) +} + +func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) string { + fmt.Println("Running test for ReadAllCompanies") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all companies error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all companies error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + if isCheckBodyEmpty { + assert.NotEmpty(t, body["content"]) + } + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func DeleteCompany(t *testing.T, bearerToken, companyID string) { + fmt.Println("Running test for DeleteCompany") + req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete company error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} diff --git a/e2e/application_admin/keycloak/http_test.go b/e2e/application_admin/keycloak/http_test.go new file mode 100644 index 000000000..c9405cca8 --- /dev/null +++ b/e2e/application_admin/keycloak/http_test.go @@ -0,0 +1 @@ +package ldap diff --git a/e2e/application_admin/ldap/http_test.go b/e2e/application_admin/ldap/http_test.go new file mode 100644 index 000000000..c9405cca8 --- /dev/null +++ b/e2e/application_admin/ldap/http_test.go @@ -0,0 +1 @@ +package ldap diff --git a/e2e/deployments/docker-compose.application-admin.horusec.yaml b/e2e/deployments/docker-compose.application-admin.horusec.yaml new file mode 100644 index 000000000..7727526af --- /dev/null +++ b/e2e/deployments/docker-compose.application-admin.horusec.yaml @@ -0,0 +1,51 @@ +version: '3' +services: + postgresql: + container_name: postgresql + image: postgres:12 + ports: + - "5432:5432" + environment: + POSTGRES_PASSWORD: root + POSTGRES_USER: root + POSTGRES_DB: horusec_db + volumes: + - /var/lib/postgres/db/data:/var/lib/postgresql/data + tty: true + logging: + driver: json-file + options: + max-size: 10m + horusec-account: + build: + context: ../../ + dockerfile: ./horusec-account/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-account + ports: + - "8003:8003" + environment: + HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_AUTH_URL: "http://horusec-auth:8006" + horusec-auth: + build: + context: ../../ + dockerfile: ./horusec-auth/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-auth + ports: + - "8006:8006" + environment: + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_ENABLE_APPLICATION_ADMIN: "true" + HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}" + HORUSEC_AUTH_TYPE: "horusec" diff --git a/e2e/deployments/docker-compose.server.broker.yaml b/e2e/deployments/docker-compose.server.broker.yaml new file mode 100644 index 000000000..a308adca4 --- /dev/null +++ b/e2e/deployments/docker-compose.server.broker.yaml @@ -0,0 +1,83 @@ +version: '3' +services: + postgresql: + container_name: postgresql + image: postgres:12 + ports: + - "5432:5432" + environment: + POSTGRES_PASSWORD: root + POSTGRES_USER: root + POSTGRES_DB: horusec_db + volumes: + - /var/lib/postgres/db/data:/var/lib/postgresql/data + tty: true + logging: + driver: json-file + options: + max-size: 10m + rabbit: + container_name: rabbit + image: rabbitmq:3-management + ports: + - "5672:5672" + - "15672:15672" + horusec-messages: + build: + context: ../../ + dockerfile: ./horusec-messages/deployments/Dockerfile.dev + depends_on: + - "rabbit" + restart: always + container_name: horusec-messages + ports: + - "8004:8004" + environment: + HORUSEC_BROKER_HOST: rabbit + HORUSEC_BROKER_PORT: "5672" + HORUSEC_BROKER_USERNAME: "guest" + HORUSEC_BROKER_PASSWORD: "guest" + HORUSEC_SMTP_ADDRESS: "smtp.mailtrap.io" + HORUSEC_SMTP_USERNAME: ${HORUSEC_SMTP_USERNAME} + HORUSEC_SMTP_PASSWORD: ${HORUSEC_SMTP_PASSWORD} + HORUSEC_SMTP_HOST: "smtp.mailtrap.io" + HORUSEC_SMTP_PORT: "2525" + HORUSEC_EMAIL_FROM: "horusec@zup.com.br" + horusec-account: + build: + context: ../../ + dockerfile: ./horusec-account/deployments/Dockerfile.dev + depends_on: + - "rabbit" + - postgresql + restart: always + container_name: horusec-account + ports: + - "8003:8003" + environment: + HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "false" + HORUSEC_BROKER_HOST: rabbit + HORUSEC_BROKER_PORT: "5672" + HORUSEC_BROKER_USERNAME: "guest" + HORUSEC_BROKER_PASSWORD: "guest" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_AUTH_URL: "http://horusec-auth:8006" + horusec-auth: + build: + context: ../../ + dockerfile: ./horusec-auth/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-auth + ports: + - "8006:8006" + environment: + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_ENABLE_APPLICATION_ADMIN: "false" + HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}" + HORUSEC_AUTH_TYPE: "horusec" \ No newline at end of file diff --git a/e2e/deployments/docker-compose.server.horusec.yaml b/e2e/deployments/docker-compose.server.horusec.yaml index 06251bfc4..b32095a2d 100644 --- a/e2e/deployments/docker-compose.server.horusec.yaml +++ b/e2e/deployments/docker-compose.server.horusec.yaml @@ -46,10 +46,6 @@ services: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" - HORUSEC_KEYCLOAK_BASE_PATH: ${HORUSEC_KEYCLOAK_BASE_PATH} - HORUSEC_KEYCLOAK_CLIENT_ID: ${HORUSEC_KEYCLOAK_CLIENT_ID} - HORUSEC_KEYCLOAK_CLIENT_SECRET: ${HORUSEC_KEYCLOAK_CLIENT_SECRET} - HORUSEC_KEYCLOAK_REALM: ${HORUSEC_KEYCLOAK_REALM} HORUSEC_ENABLE_APPLICATION_ADMIN: "false" HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}" HORUSEC_AUTH_TYPE: "horusec" diff --git a/e2e/server/horusec/requests.go b/e2e/server/horusec/requests.go index ba001759f..dee61357b 100644 --- a/e2e/server/horusec/requests.go +++ b/e2e/server/horusec/requests.go @@ -31,17 +31,6 @@ func CreateAccount(t *testing.T, account *accountentities.Account) { assert.NotEmpty(t, createAccountResponse["content"]) } -func ValidateAccount(t *testing.T, accountID string) { - validateAccountResp, err := http.Get("http://localhost:8003/api/account/validate/" + accountID) - if err != nil { - assert.Contains(t, err.Error(), "Get \"http://localhost:8043\": ") - } else { - assert.NoError(t, err, "validate account, error mount request") - assert.Equal(t, http.StatusOK, validateAccountResp.StatusCode, "validate account, error send request") - assert.NoError(t, validateAccountResp.Body.Close()) - } -} - func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string { fmt.Println("Running test for Login") loginResp, err := http.Post( From 95c876e733073315287ebcefe4353a36890b0eeb Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 16:27:04 -0300 Subject: [PATCH 10/34] Fixing tests e2e --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 53d8e7f35..64a0dc1b1 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -48,4 +48,4 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: e2e - run: test-e2e-application-admin-horusec \ No newline at end of file + run: make test-e2e-application-admin-horusec \ No newline at end of file From 7c01ca447b7d8c1f204e75dc67e83a492ffdea7b Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 16:29:53 -0300 Subject: [PATCH 11/34] Fixing tests e2e --- .github/workflows/e2e.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 64a0dc1b1..62cd9e9d7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -48,4 +48,4 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: e2e - run: make test-e2e-application-admin-horusec \ No newline at end of file + run: make test-e2e-application-admin-horusec From 019946a8c7cf69f7df1beea0100bb7e8331085cb Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 16:39:46 -0300 Subject: [PATCH 12/34] Fixing e2e --- e2e/application_admin/horusec/http_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/application_admin/horusec/http_test.go b/e2e/application_admin/horusec/http_test.go index 07292fa57..ddd8c22c9 100644 --- a/e2e/application_admin/horusec/http_test.go +++ b/e2e/application_admin/horusec/http_test.go @@ -45,7 +45,7 @@ func TestMain(m *testing.M) { if err != nil { logger.LogPanic("Error restart auth service: " + string(output), err) } - time.Sleep(2 * time.Second) + time.Sleep(3 * time.Second) code := m.Run() os.Exit(code) } From 56462ff9e999f9426a00e82340d283d42e14ffd1 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 17:16:35 -0300 Subject: [PATCH 13/34] Adding e2e to check if send messages correctly --- .github/workflows/e2e.yml | 14 +++ Makefile | 8 ++ ...ml => docker-compose.server.messages.yaml} | 0 e2e/server/broker/broker_test.go | 1 - e2e/server/messages/messages_test.go | 92 ++++++++++++++ e2e/server/messages/requests.go | 113 ++++++++++++++++++ 6 files changed, 227 insertions(+), 1 deletion(-) rename e2e/deployments/{docker-compose.server.broker.yaml => docker-compose.server.messages.yaml} (100%) delete mode 100644 e2e/server/broker/broker_test.go create mode 100644 e2e/server/messages/messages_test.go create mode 100644 e2e/server/messages/requests.go diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 62cd9e9d7..ad6700f25 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -49,3 +49,17 @@ jobs: uses: actions/checkout@v2 - name: e2e run: make test-e2e-application-admin-horusec + e2e-messages: + name: e2e-messages + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Check out code + uses: actions/checkout@v2 + - name: e2e + run: make test-e2e-messages diff --git a/Makefile b/Makefile index aaa2e1612..0a29af638 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,11 @@ test-e2e-application-admin-horusec: go get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/application_admin/horusec/... -timeout=5m -parallel=1 -failfast +test-e2e-messages: + make compose-e2e-messages + go get -v ./e2e/... + $(GO) clean -testcache + $(GO) test -v ./e2e/server/messages/... -timeout=5m -parallel=1 -failfast # ========================================================================================= # @@ -112,6 +117,9 @@ compose-e2e-server-horusec: compose-e2e-application-admin-horusec: docker-compose -f e2e/deployments/docker-compose.application-admin.horusec.yaml down -v docker-compose -f e2e/deployments/docker-compose.application-admin.horusec.yaml up -d --build --force-recreate +compose-e2e-messages: + docker-compose -f e2e/deployments/docker-compose.server.messages.yaml down -v + docker-compose -f e2e/deployments/docker-compose.server.messages.yaml up -d --build --force-recreate # ========================================================================================= # diff --git a/e2e/deployments/docker-compose.server.broker.yaml b/e2e/deployments/docker-compose.server.messages.yaml similarity index 100% rename from e2e/deployments/docker-compose.server.broker.yaml rename to e2e/deployments/docker-compose.server.messages.yaml diff --git a/e2e/server/broker/broker_test.go b/e2e/server/broker/broker_test.go deleted file mode 100644 index d749cad13..000000000 --- a/e2e/server/broker/broker_test.go +++ /dev/null @@ -1 +0,0 @@ -package broker diff --git a/e2e/server/messages/messages_test.go b/e2e/server/messages/messages_test.go new file mode 100644 index 000000000..c6f2a3f6e --- /dev/null +++ b/e2e/server/messages/messages_test.go @@ -0,0 +1,92 @@ +package messages + +import ( + "github.com/ZupIT/horusec/development-kit/pkg/databases/relational/adapter" + "github.com/ZupIT/horusec/development-kit/pkg/utils/test" + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "net/http" + "os" + "testing" + + accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/utils/env" + "github.com/ZupIT/horusec/development-kit/pkg/utils/logger" + "github.com/golang-migrate/migrate/v4" + _ "github.com/golang-migrate/migrate/v4/database/postgres" + _ "github.com/golang-migrate/migrate/v4/source/file" +) + +func TestMain(m *testing.M) { + folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" + connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + migration, err := migrate.New(folderOfMigration, connectionStringDB) + if err != nil { + logger.LogPanic("Error in create first instance migration: ", err) + } + if err := migration.Drop(); err != nil { + logger.LogPanic("Error in drop migration: ", err) + } + sourceErr, dbErr := migration.Close() + if sourceErr != nil { + logger.LogPanic("Error in source err to close connection: ", sourceErr) + } + if dbErr != nil { + logger.LogPanic("Error in database err to close connection: ", dbErr) + } + migration, err = migrate.New(folderOfMigration, connectionStringDB) + if err != nil { + logger.LogPanic("Error in create second instance migration: ", err) + } + if err := migration.Up(); err != nil { + if err.Error() != "no change" { + logger.LogPanic("Error in up migration: ", err) + } + } + code := m.Run() + os.Exit(code) +} + +func TestMessages(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + t.Run("Should run analysis and check if messages are dispatch correctly", func(t *testing.T) { + accountToCreate := &accountentities.Account{ + Email: "e2e@example.com", + Password: "Ch@ng3m3", + Username: "e2e_user", + } + // Create account + CreateAccount(t, accountToCreate) + + // When try login without confirm account return unauthorized + loginResp := Login(t, &accountentities.LoginData{ + Email: "e2e@example.com", + Password: "Ch@ng3m3", + }) + assert.Equal(t, http.StatusForbidden, loginResp.GetStatusCode()) + + // Get Last account created in database + accountCreated := GetLastAccountCreated(t) + + // Confirm account in database + ValidateAccount(t, accountCreated.AccountID.String()) + + // Check if is possible login now + bearerToken := LoginAndReturnAccessToken(t, &accountentities.LoginData{ + Email: "e2e@example.com", + Password: "Ch@ng3m3", + }) + Logout(t, bearerToken) + }) +} + +func GetLastAccountCreated(t *testing.T) (accountCreated accountentities.Account) { + dbRead := adapter.NewRepositoryRead() + sqlUtil := test.NewSQLUtil(dbRead) + sqlUtil.GetLast(&accountCreated) + assert.NotEmpty(t, accountCreated) + assert.NotEqual(t, accountCreated.AccountID, uuid.Nil) + return accountCreated +} \ No newline at end of file diff --git a/e2e/server/messages/requests.go b/e2e/server/messages/requests.go new file mode 100644 index 000000000..796a3cf92 --- /dev/null +++ b/e2e/server/messages/requests.go @@ -0,0 +1,113 @@ +package messages + +import ( + "bytes" + "crypto/tls" + "encoding/json" + "fmt" + accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/client" + httpResponse "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/response" + "github.com/stretchr/testify/assert" + "net/http" + "strings" + "testing" +) + +func CreateAccount(t *testing.T, account *accountentities.Account) { + fmt.Println("Running test for CreateAccount") + createAccountResp, err := http.Post("http://localhost:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) + assert.NoError(t, err, "create account error mount request") + assert.Equal(t, http.StatusCreated, createAccountResp.StatusCode, "create account error send request") + + var createAccountResponse map[string]interface{} + _ = json.NewDecoder(createAccountResp.Body).Decode(&createAccountResponse) + assert.NoError(t, createAccountResp.Body.Close()) + assert.NotEmpty(t, createAccountResponse["content"]) +} + +func Login(t *testing.T, credentials *accountentities.LoginData) httpResponse.Interface { + fmt.Println("Running test for Login") + req, _ := http.NewRequest( + http.MethodPost, + "http://localhost:8003/api/account/login", + bytes.NewReader(credentials.ToBytes())) + res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) + assert.NoError(t, err) + return res +} +func LoginAndReturnAccessToken(t *testing.T, credentials *accountentities.LoginData) string { + fmt.Println("Running test for Login") + loginResp, err := http.Post( + "http://localhost:8003/api/account/login", + "text/json", + bytes.NewReader(credentials.ToBytes()), + ) + assert.NoError(t, err, "login, error mount request") + assert.Equal(t, http.StatusOK, loginResp.StatusCode, "login error send request") + + var loginResponse map[string]map[string]string + _ = json.NewDecoder(loginResp.Body).Decode(&loginResponse) + assert.NoError(t, loginResp.Body.Close()) + return loginResponse["content"]["accessToken"] +} +func ValidateAccount(t *testing.T, accountID string) { + fmt.Println("Running test for ValidateAccount") + req, _ := http.NewRequest( + http.MethodGet, + "http://localhost:8003/api/account/validate/"+accountID, + nil) + res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) + if err != nil { + if !strings.Contains(err.Error(), "Get \"http://localhost:8043\": ") { + assert.NoError(t, err) + } + } else { + assert.Equal(t, http.StatusSeeOther, res.GetStatusCode()) + } +} + +func Logout(t *testing.T, bearerToken string) { + fmt.Println("Running test for Logout") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/account/logout", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "logout error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "logout error send request") + + var logoutResponse map[string]map[string]string + _ = json.NewDecoder(resp.Body).Decode(&logoutResponse) + assert.NoError(t, resp.Body.Close()) +} + +func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { + fmt.Println("Running test for CreateCompany") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(company.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + createCompanyResp, err := httpClient.Do(req) + assert.NoError(t, err, "create company error send request") + assert.Equal(t, http.StatusCreated, createCompanyResp.StatusCode, "create company error check response") + var createdCompany map[string]map[string]string + _ = json.NewDecoder(createCompanyResp.Body).Decode(&createdCompany) + assert.NoError(t, createCompanyResp.Body.Close()) + assert.NotEmpty(t, createdCompany["content"]["companyID"]) + return createdCompany["content"]["companyID"] +} + +func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *accountentities.InviteUser) { + fmt.Println("Running test for InviteUserToCompany") + req, _ := http.NewRequest( + http.MethodPost, + "http://localhost:8003/api/companies/"+companyID+"/roles", + bytes.NewReader(user.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "invite user error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "invite user error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} \ No newline at end of file From 033487a20126aea1a504b7bda1ff641a8e42ef6b Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 30 Oct 2020 17:26:31 -0300 Subject: [PATCH 14/34] Update testbook --- e2e/TESTBOOK.md | 62 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 0126792cb..9e70db67e 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -1,5 +1,13 @@ # Test book +# Table of Contents + + * [Horusec server](#horusec-server) + * [Horusec messages](#horusec-messages) + * [Horusec application admin](#horusec-application-admin) + * [Horusec CLI](#horusec-cli) + + ## Horusec server - [ ] Create account - [X] Horusec auth type @@ -17,15 +25,10 @@ - [X] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type -- [ ] Reset account password - [ ] Create, Read, Update and Delete company - [X] Horusec auth type - [ ] Ldap auth type - [ ] Keycloak auth type -- [ ] Create, Read, Update and Delete company with application admin enable - - [X] Horusec auth type - - [ ] Ldap auth type - - [ ] Keycloak auth type - [X] Create, Read, and Delete company token - [X] Create, Read, Update, and Delete repositories - [X] Create, Read, and Delete repository token @@ -44,6 +47,35 @@ - [X] Repository view - [X] Manager vulnerabilities found and change type into: False Positive, Risk accept, Corrected, Vulnerability +## Horusec messages +- [X] Create account +- [X] Validate account +- [X] Login +- [X] Logout +- [ ] Reset account password + +## Horusec application admin +- [ ] Create account + - [X] Horusec auth type + - [ ] Ldap auth type + - [ ] Keycloak auth type +- [ ] Login + - [X] Horusec auth type + - [ ] Ldap auth type + - [ ] Keycloak auth type +- [ ] Logout + - [X] Horusec auth type + - [ ] Ldap auth type + - [ ] Keycloak auth type +- [ ] Authorize + - [X] Horusec auth type + - [ ] Ldap auth type + - [ ] Keycloak auth type +- [ ] Create, Read, Update and Delete company + - [X] Horusec auth type + - [ ] Ldap auth type + - [ ] Keycloak auth type + ## Horusec CLI - [ ] Setup log level - [ ] Output TEXT @@ -78,17 +110,15 @@ - [ ] javaScript - [ ] leaks - [ ] hlc - -### Run analysis examples - - [X] GoLang - - [X] C# - - [X] Ruby - - [X] Python - - [X] Java - - [X] Kotlin - - [X] Javascript - - [X] Leaks - - [X] Terraform +- [X] Scan languages GoLang +- [X] Scan languages C# +- [X] Scan languages Ruby +- [X] Scan languages Python +- [X] Scan languages Java +- [X] Scan languages Kotlin +- [X] Scan languages Javascript +- [X] Scan languages Leaks +- [X] Scan languages Terraform ### Generics repositories to test - [ ] Kubernetes alone From d28089335e5ad23b3afdec21aaf80fc07f0eec45 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Tue, 3 Nov 2020 08:48:09 -0300 Subject: [PATCH 15/34] Fixing gomod --- .../docker-compose.server.keycloak.yaml | 80 +++++++ e2e/server/shared_requests.go | 26 +++ go.mod | 40 +--- go.sum | 219 +++--------------- 4 files changed, 137 insertions(+), 228 deletions(-) create mode 100644 e2e/deployments/docker-compose.server.keycloak.yaml create mode 100644 e2e/server/shared_requests.go diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml new file mode 100644 index 000000000..b32095a2d --- /dev/null +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -0,0 +1,80 @@ +version: '3' +services: + postgresql: + container_name: postgresql + image: postgres:12 + ports: + - "5432:5432" + environment: + POSTGRES_PASSWORD: root + POSTGRES_USER: root + POSTGRES_DB: horusec_db + volumes: + - /var/lib/postgres/db/data:/var/lib/postgresql/data + tty: true + logging: + driver: json-file + options: + max-size: 10m + horusec-account: + build: + context: ../../ + dockerfile: ./horusec-account/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-account + ports: + - "8003:8003" + environment: + HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_AUTH_URL: "http://horusec-auth:8006" + horusec-auth: + build: + context: ../../ + dockerfile: ./horusec-auth/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-auth + ports: + - "8006:8006" + environment: + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_ENABLE_APPLICATION_ADMIN: "false" + HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}" + HORUSEC_AUTH_TYPE: "horusec" + horusec-analytic: + build: + context: ../../ + dockerfile: ./horusec-analytic/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-analytic + ports: + - "8005:8005" + environment: + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_AUTH_URL: "http://horusec-auth:8006" + horusec-api: + build: + context: ../../ + dockerfile: ./horusec-api/deployments/Dockerfile.dev + depends_on: + - postgresql + restart: always + container_name: horusec-api + ports: + - "8000:8000" + environment: + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_DIALECT: "postgres" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" + HORUSEC_AUTH_URL: "http://horusec-auth:8006" \ No newline at end of file diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go new file mode 100644 index 000000000..f4a849e9f --- /dev/null +++ b/e2e/server/shared_requests.go @@ -0,0 +1,26 @@ +package server + +import ( + "bytes" + "encoding/json" + "fmt" + accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { + fmt.Println("Running test for CreateCompany") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(company.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + createCompanyResp, err := httpClient.Do(req) + assert.NoError(t, err, "create company error send request") + assert.Equal(t, http.StatusCreated, createCompanyResp.StatusCode, "create company error check response") + var createdCompany map[string]map[string]string + _ = json.NewDecoder(createCompanyResp.Body).Decode(&createdCompany) + assert.NoError(t, createCompanyResp.Body.Close()) + assert.NotEmpty(t, createdCompany["content"]["companyID"]) + return createdCompany["content"]["companyID"] +} diff --git a/go.mod b/go.mod index 8dd6e49a5..dfe4b1103 100644 --- a/go.mod +++ b/go.mod @@ -6,69 +6,33 @@ require ( github.com/Nerzal/gocloak/v7 v7.5.0 github.com/ZupIT/horusec-engine v0.2.7 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 - github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect - github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect - github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1 - github.com/bmatcuk/doublestar v1.3.2 // indirect + github.com/auth0/go-jwt-middleware v0.0.0-20201030150249-d783b5c46b39 github.com/bmatcuk/doublestar/v2 v2.0.3 - github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect github.com/davecgh/go-spew v1.1.1 - github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 github.com/docker/docker v1.13.1 - github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/go-chi/chi v4.1.2+incompatible github.com/go-chi/cors v1.1.1 github.com/go-enry/go-enry/v2 v2.5.2 - github.com/go-openapi/spec v0.19.11 // indirect - github.com/go-openapi/swag v0.19.11 // indirect github.com/go-ozzo/ozzo-validation/v4 v4.3.0 github.com/golang-migrate/migrate/v4 v4.13.0 github.com/google/uuid v1.1.2 github.com/graphql-go/graphql v0.7.9 - github.com/hashicorp/errwrap v1.1.0 // indirect github.com/iancoleman/strcase v0.1.2 github.com/jinzhu/gorm v1.9.16 - github.com/labstack/echo v3.3.10+incompatible - github.com/labstack/gommon v0.3.0 // indirect - github.com/lib/pq v1.8.0 // indirect - github.com/lunixbochs/vtclean v1.0.0 // indirect github.com/magiconair/properties v1.8.4 - github.com/mailru/easyjson v0.7.6 // indirect github.com/manifoldco/promptui v0.8.0 - github.com/mattn/go-colorable v0.1.8 // indirect - github.com/mattn/go-sqlite3 v1.14.4 // indirect - github.com/mitchellh/mapstructure v1.3.3 // indirect - github.com/onsi/ginkgo v1.12.0 - github.com/onsi/gomega v1.9.0 - github.com/opencontainers/go-digest v1.0.0 // indirect github.com/otiai10/copy v1.2.0 - github.com/pelletier/go-toml v1.8.1 // indirect github.com/prometheus/client_golang v1.8.0 - github.com/prometheus/common v0.14.0 // indirect - github.com/prometheus/procfs v0.2.0 // indirect github.com/sirupsen/logrus v1.7.0 - github.com/spf13/afero v1.4.1 // indirect - github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cobra v1.1.1 - github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.7.1 github.com/streadway/amqp v1.0.0 - github.com/stretchr/objx v0.3.0 // indirect github.com/stretchr/testify v1.6.1 github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba github.com/swaggo/swag v1.6.9 - github.com/valyala/fasttemplate v1.2.1 // indirect - github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 - golang.org/x/net v0.0.0-20201029055024-942e2f445f3c - golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 // indirect - golang.org/x/text v0.3.4 // indirect - golang.org/x/tools v0.0.0-20201029182919-e7a17c4c1366 // indirect + golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df - gopkg.in/ini.v1 v1.62.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect ) diff --git a/go.sum b/go.sum index 2b0c628d9..66f4f1e95 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,6 @@ cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6 cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.60.0/go.mod h1:yw2G51M9IfRboUH61Us8GqCeF1PzPblB823Mn2q2eAU= -cloud.google.com/go v0.61.0/go.mod h1:XukKJg4Y7QsUu0Hxg3qQKUWR4VuWivmyMK2+rUyxAqw= cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= cloud.google.com/go v0.63.0/go.mod h1:GmezbQc7T2snqkEXWfZ0sy0VfkB/ivI2DdtJL2DEmlg= cloud.google.com/go v0.64.0/go.mod h1:xfORb36jGvE+6EexW71nMEtL025s3x6xvuYUKM4JLv4= @@ -29,7 +27,6 @@ cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2k cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/spanner v1.8.0/go.mod h1:mdAPDiFUbE9vCmhHHlxyDUtaPPsIK+pUdf5KmHaUfT8= cloud.google.com/go/spanner v1.9.0/go.mod h1:xvlEn0NZ5v1iJPYsBnUVRDNvccDxsBTEi16pJRKQVws= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= @@ -48,7 +45,6 @@ github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcy github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Nerzal/gocloak v1.0.0 h1:WllsbIu1dYvdvka1/BbY7khZBJSTjSkGwyDsHHLQmIw= -github.com/Nerzal/gocloak v1.0.0/go.mod h1:daDihnZuvvt0J5neHCn1e/5lu+vXMF/MUZsCWVj5V5s= github.com/Nerzal/gocloak/v7 v7.5.0 h1:C43CStKw14gZatPLBdjKIrz1a6UrjaxP7OQTXYQ+RHc= github.com/Nerzal/gocloak/v7 v7.5.0/go.mod h1:tJ0yV6jds2dm1a5eYW7km/bt+2F3mqlU0e8Xis+diDQ= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -61,8 +57,6 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= -github.com/ZupIT/horusec-engine v0.2.5 h1:11FECfTpF8qd/UbusWd+WgKMylJ+TzSTyiLOOuwWerk= -github.com/ZupIT/horusec-engine v0.2.5/go.mod h1:pJ5IoEOdX6mT4pYG/ZM15XzapKA/KUQgs/ok0Un1Xhk= github.com/ZupIT/horusec-engine v0.2.7 h1:1LNxKhMYK4OJd//awCEjyBUVi1iDX5fnKUaI5ax5GXU= github.com/ZupIT/horusec-engine v0.2.7/go.mod h1:YUvzG1NJ5BXQ/vKJv2i4KbiwF2z5vHwcCVvjtf4fIkE= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= @@ -77,15 +71,13 @@ github.com/apache/arrow/go/arrow v0.0.0-20200601151325-b2287a20f230/go.mod h1:QN github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= +github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 h1:zV3ejI06GQ59hwDQAvmK1qxOQGB3WuVTRoY0okPTAv0= github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= -github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef h1:46PFijGLmAjMPwCCCo7Jf0W6f9slllCkkv7vyc1yOSg= -github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1 h1:lnVadil6o8krZE47ms2PCxhXcki/UwoqiB0axOIV3mk= -github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1/go.mod h1:mF0ip7kTEFtnhBJbd/gJe62US3jykNN+dcZoZakJCCA= +github.com/auth0/go-jwt-middleware v0.0.0-20201030150249-d783b5c46b39 h1:FXGfTw25KQECao75qgpoCttPz8VTwKkQTi2L0iGh9Vk= +github.com/auth0/go-jwt-middleware v0.0.0-20201030150249-d783b5c46b39/go.mod h1:mF0ip7kTEFtnhBJbd/gJe62US3jykNN+dcZoZakJCCA= github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= @@ -98,10 +90,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= -github.com/bmatcuk/doublestar v1.3.2 h1:mzUncgFmpzNUhIITFqGdZ8nUU0O7JTJzRO8VdkeLCSo= -github.com/bmatcuk/doublestar v1.3.2/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE= -github.com/bmatcuk/doublestar/v2 v2.0.1 h1:EFT91DmIMRcrUEcYUW7AqSAwKvNzP5+CoDmNVBbcQOU= -github.com/bmatcuk/doublestar/v2 v2.0.1/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw= +github.com/bmatcuk/doublestar v1.3.3 h1:pVP1d49CcQQaNOl+PI6sPybIrIOD/6sux31PFdmhTH0= github.com/bmatcuk/doublestar/v2 v2.0.3 h1:D6SI8MzWzXXBXZFS87cFL6s/n307lEU+thM2SUnge3g= github.com/bmatcuk/doublestar/v2 v2.0.3/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= @@ -128,7 +117,6 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/containerd/containerd v1.3.3/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -141,21 +129,18 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM= -github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= -github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +github.com/denisenkom/go-mssqldb v0.0.0-20200620013148-b91950f658ec h1:NfhRXXFDPxcF5Cwo06DzeIaE7uuJtAUhsDwH3LNsjos= github.com/denisenkom/go-mssqldb v0.0.0-20200620013148-b91950f658ec/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= -github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204 h1:tI48fqaIkxxYuIylVv1tdDfBp6836GKSfmmzgSyP1CY= -github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU= github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/dhui/dktest v0.3.2 h1:nZSDcnkpbotzT/nEHNsO+JCKY8i1Qoki1AYOpeLRb6M= github.com/dhui/dktest v0.3.2/go.mod h1:l1/ib23a/CmxAe7yixtrYPc8Iy90Zy2udyaHINM5p58= github.com/docker/distribution v2.7.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= @@ -183,9 +168,8 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsouza/fake-gcs-server v1.17.0/go.mod h1:D1rTE4YCyHFNa99oyJJ5HyclvN/0uQR+pM/VdlL83bw= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= @@ -195,11 +179,13 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/go-chi/chi v1.0.0 h1:s/kv1cTXfivYjdKJdyUzNGyAWZ/2t7duW1gKn5ivu+c= github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-chi/cors v1.1.1 h1:eHuqxsIw89iXcWnWUN8R72JMibABJTN/4IOYI5WERvw= github.com/go-chi/cors v1.1.1/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I= +github.com/go-enry/go-enry v1.7.3 h1:MbViVjoR80+AWFY8GmhEdtGY7WYAPxb0A74kLc8X5c0= github.com/go-enry/go-enry/v2 v2.5.2 h1:3f3PFAO6JitWkPi1GQ5/m6Xu4gNL1U5soJ8QaYqJ0YQ= github.com/go-enry/go-enry/v2 v2.5.2/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ= github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo= @@ -215,34 +201,18 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= -github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= github.com/go-openapi/jsonreference v0.19.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= -github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= github.com/go-openapi/jsonreference v0.19.4 h1:3Vw+rh13uq2JFNxgnMTGE1rnoieU9FmyE1gvnyylsYg= github.com/go-openapi/jsonreference v0.19.4/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= -github.com/go-openapi/spec v0.19.4/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= github.com/go-openapi/spec v0.19.9 h1:9z9cbFuZJ7AcvOHKIY+f6Aevb4vObNDkTEyoMfO7rAc= github.com/go-openapi/spec v0.19.9/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28= -github.com/go-openapi/spec v0.19.10 h1:pcNevfYytLaOQuTju0wm6OqcqU/E/pRwuSGigrLTI28= -github.com/go-openapi/spec v0.19.10/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28= -github.com/go-openapi/spec v0.19.11 h1:ogU5q8dtp3MMPn59a9VRrPKVxvJHEs5P7yNMR5sNnis= -github.com/go-openapi/spec v0.19.11/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28= github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= -github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.9 h1:1IxuqvBUU3S2Bi4YC7tlP9SJF1gVpCvqN0T2Qof4azE= -github.com/go-openapi/swag v0.19.9/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= -github.com/go-openapi/swag v0.19.10 h1:A1SWXruroGP15P1sOiegIPbaKio+G9N5TwWTFaVPmAU= -github.com/go-openapi/swag v0.19.10/go.mod h1:Uc0gKkdR+ojzsEpjh39QChyu92vPgIr72POcgHMAgSY= -github.com/go-openapi/swag v0.19.11 h1:RFTu/dlFySpyVvJDfp/7674JY4SDglYWKztbiIGFpmc= -github.com/go-openapi/swag v0.19.11/go.mod h1:Uc0gKkdR+ojzsEpjh39QChyu92vPgIr72POcgHMAgSY= -github.com/go-ozzo/ozzo-validation/v4 v4.2.2 h1:5uhbQAuRK6taB9orHJXA5GtOCuQbsHktskg8aWciC68= -github.com/go-ozzo/ozzo-validation/v4 v4.2.2/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew= github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es= github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -263,8 +233,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/golang-migrate/migrate/v4 v4.12.2 h1:QI43Tlouiwpp2dK5Y767OouX0snJNRP/NubsVaArzDU= -github.com/golang-migrate/migrate/v4 v4.12.2/go.mod h1:HQ1DaC8uLHkg4afY8ZQ8D/P5SG+YW9X5INZBVvm+d2k= +github.com/golang-migrate/migrate v1.3.2 h1:QAlFV1QF9zdkzy/jujlBVkVu+L/+k18cg8tuY1/4JDY= +github.com/golang-migrate/migrate v3.5.4+incompatible h1:R7OzwvCJTCgwapPCiX6DyBiu2czIUMDCB118gFTKTUA= github.com/golang-migrate/migrate/v4 v4.13.0 h1:5S7HMjiq9u50X3+WXpzXPbUj1qUFuZRm8NCsX989Tn4= github.com/golang-migrate/migrate/v4 v4.13.0/go.mod h1:RUEXGkgYXTOdBY9Rbs9izc/SOalUK+dDi7YphFV/CUI= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= @@ -294,7 +264,6 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= @@ -322,7 +291,6 @@ github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200507031123-427632fa3b1c/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -339,7 +307,6 @@ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graphql-go/graphql v0.7.9 h1:5Va/Rt4l5g3YjwDnid3vFfn43faaQBq7rMcIZ0VnV34= github.com/graphql-go/graphql v0.7.9/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI= @@ -355,8 +322,6 @@ github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= @@ -378,7 +343,6 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/iancoleman/strcase v0.1.2 h1:gnomlvw9tnV3ITTAxzKSgTF+8kFWcU/f+TgttpXGz1U= @@ -419,8 +383,6 @@ github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -441,73 +403,49 @@ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQL github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/labstack/echo v1.4.4 h1:1bEiBNeGSUKxcPDGfZ/7IgdhJJZx8wV/pICJh4W2NJI= -github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= -github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= -github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= -github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg= -github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= +github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw= github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= -github.com/lunixbochs/vtclean v1.0.0 h1:xu2sLAri4lGiovBDQKxl5mrXyESr3gUr5m5SM5+LVb8= -github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/magiconair/properties v1.8.3 h1:kJSsc6EXkBLgr3SphHk9w5mtjn0bjlR4JYEXKrJ45rQ= -github.com/magiconair/properties v1.8.3/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= -github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= -github.com/manifoldco/promptui v0.7.0 h1:3l11YT8tm9MnwGFQ4kETwkzpAwY2Jt9lCrumCUW4+z4= -github.com/manifoldco/promptui v0.7.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ= github.com/manifoldco/promptui v0.8.0 h1:R95mMF+McvXZQ7j1g8ucVZE1gLP3Sv6j9vlF9kyRqQo= github.com/manifoldco/promptui v0.8.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ= github.com/markbates/pkger v0.15.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= -github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= -github.com/mattn/go-sqlite3 v1.14.3 h1:j7a/xn1U6TKA/PHHxqZuzh64CdtRc7rU9M+AvkOl5bA= -github.com/mattn/go-sqlite3 v1.14.3/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= -github.com/mattn/go-sqlite3 v1.14.4 h1:4rQjbDxdu9fSgI/r3KN72G3c2goxknAqHHgPWWs8UlI= -github.com/mattn/go-sqlite3 v1.14.4/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= @@ -518,10 +456,8 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.3.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8= -github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= @@ -545,16 +481,13 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU= github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= -github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= -github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= @@ -573,10 +506,8 @@ github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml v1.8.0/go.mod h1:D6yutnOGMveHEPV7VQOuvI/gXY61bv+9bAOTRnLElKs= -github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= -github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -586,7 +517,6 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= -github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= @@ -595,7 +525,6 @@ github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.8.0 h1:zvJNkoCFAnYFNC24FV8nW4JdRJ3GIFcLbg65lL/JDcw= github.com/prometheus/client_golang v1.8.0/go.mod h1:O9VU6huf47PktckDQfMTX0Y8tY0/7TSWwj+ITvv0TnM= @@ -612,8 +541,6 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.13.0 h1:vJlpe9wPgDRM1Z+7Wj3zUUjY1nr6/1jNKyl7llliccg= -github.com/prometheus/common v0.13.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4= github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= @@ -621,7 +548,6 @@ github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= @@ -645,7 +571,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= @@ -657,28 +582,19 @@ github.com/snowflakedb/gosnowflake v1.3.5/go.mod h1:13Ky+lxzIm3VqNDZJdyvu9MCGy+W github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= -github.com/spf13/afero v1.4.0 h1:jsLTaI1zwYO3vjrzHalkVcIHXTNmdQFepW4OI8H3+x8= -github.com/spf13/afero v1.4.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= -github.com/spf13/afero v1.4.1 h1:asw9sl74539yqavKaglDM5hFpdJVK0Y5Dr/JOgQ89nQ= -github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= -github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= -github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= -github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= @@ -689,9 +605,8 @@ github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1Sd github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As= -github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -708,10 +623,6 @@ github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba h1:lUPlXKqgbqT github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba/go.mod h1:O1lAbCgAAX/KZ80LM/OXwtWFI/5TvZlwxSg8Cq08PV0= github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y= github.com/swaggo/swag v1.6.3/go.mod h1:wcc83tB4Mb2aNiL/HP4MFeQdpHUrca+Rp/DRNgWAUio= -github.com/swaggo/swag v1.6.7 h1:e8GC2xDllJZr3omJkm9YfmK0Y56+rMO3cg0JBKNz09s= -github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc= -github.com/swaggo/swag v1.6.8 h1:z3ZNcpJs/NLMpZcKqXUsBELmmY2Ocy09JXKx5gu3L4M= -github.com/swaggo/swag v1.6.8/go.mod h1:a0IpNeMfGidNOcm2TsqODUh9JHdHu3kxDA0UlGbBKjI= github.com/swaggo/swag v1.6.9 h1:BukKRwZjnEcUxQt7Xgfrt9fpav0hiWw9YimdNO9wssw= github.com/swaggo/swag v1.6.9/go.mod h1:a0IpNeMfGidNOcm2TsqODUh9JHdHu3kxDA0UlGbBKjI= github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= @@ -725,26 +636,15 @@ github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2t github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= -github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= -github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/wiliansilvazup/horus-example-vulnerabilities v0.0.0-20200924170348-ca39bbfe5b7f h1:+G40R/nojlZ5KE1Vaj+lGmJndbzLj/7KRTuw5umAluA= -github.com/wiliansilvazup/semver-cli v0.0.3 h1:12jDuS3LfB0ZG8nZXo5LOpQVyiK1Tl4pRElAE6jNA3o= -github.com/wiliansilvazup/semver-cli v0.0.3/go.mod h1:r7j6VgVpCVJvaX2xYMsLqdExK72PdPSUkZxCudbMB9s= github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b/go.mod h1:T3BPAOm2cqquPa0MKWeNkmOM5RQsRhkrwMWonFMN7fE= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -774,7 +674,6 @@ golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -782,7 +681,6 @@ golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -821,7 +719,6 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -835,7 +732,6 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -859,19 +755,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA= -golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200923182212-328152dc79b1 h1:Iu68XRPd67wN4aRGGWwwq6bZo/25jR6uu52l/j2KkUE= -golang.org/x/net v0.0.0-20200923182212-328152dc79b1/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200925080053-05aa5d4ee321 h1:lleNcKRbcaC8MqgLwghIkzZ2JBQAb7QQ9MiwRt1BisA= -golang.org/x/net v0.0.0-20200925080053-05aa5d4ee321/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200927032502-5d4f70055728 h1:5wtQIAulKU5AbLQOkjxl32UufnIOqgBX72pS0AV14H0= -golang.org/x/net v0.0.0-20200927032502-5d4f70055728/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg= -golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201029055024-942e2f445f3c h1:rpcgRPA7OvNEOdprt2Wx8/Re2cBTd8NPo/lvo3AyMqk= -golang.org/x/net v0.0.0-20201029055024-942e2f445f3c/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -886,7 +771,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -906,13 +790,11 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -931,34 +813,20 @@ golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200817155316-9781c653f443/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 h1:YEu4SMq7D0cmT7CBbXfcH0NZeuChAXwsHe/9XueUO6o= -golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es= -golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200926100807-9d91bd62050c h1:38q6VNPWR010vN82/SB121GujZNIfAUb4YttE2rhGuc= -golang.org/x/sys v0.0.0-20200926100807-9d91bd62050c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 h1:5jaG59Zhd+8ZXe8C+lgiAGqkOaZBruqrWclLkgAww34= -golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 h1:HlFl4V6pEMziuLXyRkm5BIYq1y1GAbb02pRlWvI54OM= -golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -981,7 +849,6 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= @@ -1015,35 +882,19 @@ golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200725200936-102e7d357031/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200806022845-90696ccdc692/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200814230902-9882f1d1823d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200817023811-d00afeaade8f/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200818005847-188abfa75333/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200820010801-b793a1359eac h1:DugppSxw0LSF8lcjaODPJZoDzq0ElTGskTst3ZaBkHI= golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200922173257-82fe25c37531 h1:FS7ZiladzQ5yC5TWXke5sO9bHgSg37DItOho2WWf43U= -golang.org/x/tools v0.0.0-20200922173257-82fe25c37531/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= -golang.org/x/tools v0.0.0-20200923182640-463111b69878 h1:VUw1+Jf6KJPf82mbTQMia6HCnNMv2BbAipkEZ4KTcqQ= -golang.org/x/tools v0.0.0-20200923182640-463111b69878/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= -golang.org/x/tools v0.0.0-20200924224222-8d73f17870ce h1:XRr763sMfaUSNR4EsxbddvVEqYFa9picrx6ks9pJkKw= -golang.org/x/tools v0.0.0-20200924224222-8d73f17870ce/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= -golang.org/x/tools v0.0.0-20200928182047-19e03678916f h1:VwGa2Wf+rHGIxvsssCkUNIyFv8jQY0VCBCNWtikoWq0= -golang.org/x/tools v0.0.0-20200928182047-19e03678916f/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= -golang.org/x/tools v0.0.0-20201017001424-6003fad69a88 h1:ZB1XYzdDo7c/O48jzjMkvIjnC120Z9/CwgDWhePjQdQ= -golang.org/x/tools v0.0.0-20201017001424-6003fad69a88/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= -golang.org/x/tools v0.0.0-20201029182919-e7a17c4c1366 h1:a6x10n1HsMdTywBbnrJhO8r8pa7rnbl8TvRfCUd16Jw= -golang.org/x/tools v0.0.0-20201029182919-e7a17c4c1366/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -1097,10 +948,6 @@ google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200626011028-ee7919e894b5/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200711021454-869866162049/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200720141249-1244ee217b7e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200726014623-da3ae01ef02d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200806141610-86f49bd18e98/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= @@ -1141,7 +988,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= @@ -1150,16 +996,9 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AW gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.61.0 h1:LBCdW4FmFYL4s/vDZD1RQYX7oAR6IjujCYgMdbHBR10= -gopkg.in/ini.v1 v1.61.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= -gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/resty.v1 v1.10.3/go.mod h1:nrgQYbPhkRfn2BfT32NNTLfq3K9NuHRB0MsAcA9weWY= -gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= From 9828c489668e0750ee1e71cdeb8721e40521a1f1 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Tue, 3 Nov 2020 17:25:29 -0300 Subject: [PATCH 16/34] Starting add keycloak e2e tests --- Makefile | 37 ++-- .../docker-compose.server.keycloak.yaml | 24 ++- .../keycloak/entities/user_representation.go | 26 +++ e2e/server/keycloak/http_test.go | 123 ++++++++++++++ e2e/server/keycloak/requests.go | 158 ++++++++++++++++++ e2e/server/shared_requests.go | 46 +++++ 6 files changed, 395 insertions(+), 19 deletions(-) create mode 100644 e2e/server/keycloak/entities/user_representation.go create mode 100644 e2e/server/keycloak/requests.go diff --git a/Makefile b/Makefile index 0a29af638..9c7bf0419 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ GO ?= go GOFMT ?= gofmt GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor) GOCILINT ?= ./bin/golangci-lint +DOCKER_COMPOSE ?= docker-compose # Format all files founded in GO fmt: @@ -65,6 +66,11 @@ test-e2e-messages: go get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/server/messages/... -timeout=5m -parallel=1 -failfast +test-e2e-server-keycloak: + make compose-e2e-server-keycloak + go get -v ./e2e/... + $(GO) clean -testcache + $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast # ========================================================================================= # @@ -91,35 +97,38 @@ compose: compose-down compose-up # Down all containers on depends to the project run compose-down: - docker-compose -f deployments/$(COMPOSE_FILE_NAME) down -v + $(DOCKER_COMPOSE) -f deployments/$(COMPOSE_FILE_NAME) down -v # Up all containers on depends to the project run compose-up: - docker-compose -f deployments/$(COMPOSE_FILE_NAME) up -d --build --force-recreate + $(DOCKER_COMPOSE) -f deployments/$(COMPOSE_FILE_NAME) up -d --build --force-recreate # ========================================================================================= # compose-development-kit: - docker-compose -f development-kit/deployments/docker-compose.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f development-kit/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-api: - docker-compose -f horusec-api/deployments/docker-compose.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f horusec-api/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-messages: - docker-compose -f horusec-messages/deployments/docker-compose.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f horusec-messages/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-account: - docker-compose -f horusec-account/deployments/docker-compose.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f horusec-account/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-analytic: - docker-compose -f horusec-analytic/deployments/docker-compose.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f horusec-analytic/deployments/docker-compose.yaml up -d --build --force-recreate compose-horusec-auth: - docker-compose -f horusec-auth/deployments/docker-compose.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f horusec-auth/deployments/docker-compose.yaml up -d --build --force-recreate compose-e2e-server-horusec: - docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml down -v - docker-compose -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.horusec.yaml down -v + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.horusec.yaml up -d --build --force-recreate compose-e2e-application-admin-horusec: - docker-compose -f e2e/deployments/docker-compose.application-admin.horusec.yaml down -v - docker-compose -f e2e/deployments/docker-compose.application-admin.horusec.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.application-admin.horusec.yaml down -v + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.application-admin.horusec.yaml up -d --build --force-recreate compose-e2e-messages: - docker-compose -f e2e/deployments/docker-compose.server.messages.yaml down -v - docker-compose -f e2e/deployments/docker-compose.server.messages.yaml up -d --build --force-recreate + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.messages.yaml down -v + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.messages.yaml up -d --build --force-recreate +compose-e2e-server-keycloak: + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml down -v + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql keycloak horusec-account horusec-analytic horusec-api # ========================================================================================= # diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index b32095a2d..adfcb9795 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -16,12 +16,22 @@ services: driver: json-file options: max-size: 10m + keycloak: + container_name: keycloak + image: jboss/keycloak + ports: + - "8080:8080" + environment: + DB_VENDOR: h2 + KEYCLOAK_USER: keycloak + KEYCLOAK_PASSWORD: keycloak horusec-account: build: context: ../../ dockerfile: ./horusec-account/deployments/Dockerfile.dev depends_on: - postgresql + - keycloak restart: always container_name: horusec-account ports: @@ -30,7 +40,6 @@ services: HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_JWT_SECRET_KEY: "horusec-secret" HORUSEC_AUTH_URL: "http://horusec-auth:8006" horusec-auth: build: @@ -38,6 +47,7 @@ services: dockerfile: ./horusec-auth/deployments/Dockerfile.dev depends_on: - postgresql + - keycloak restart: always container_name: horusec-auth ports: @@ -45,16 +55,20 @@ services: environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_JWT_SECRET_KEY: "horusec-secret" HORUSEC_ENABLE_APPLICATION_ADMIN: "false" - HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}" - HORUSEC_AUTH_TYPE: "horusec" + HORUSEC_AUTH_TYPE: "keycloak" + HORUSEC_KEYCLOAK_BASE_PATH=http://localhost:8080/auth/realms/master/account/ + HORUSEC_KEYCLOAK_CLIENT_ID=account + HORUSEC_KEYCLOAK_CLIENT_SECRET=afc12778-333b-48bc-b932-65cdcd4025b1 + HORUSEC_KEYCLOAK_REALM=master + HORUSEC_KEYCLOAK_OTP=false horusec-analytic: build: context: ../../ dockerfile: ./horusec-analytic/deployments/Dockerfile.dev depends_on: - postgresql + - keycloak restart: always container_name: horusec-analytic ports: @@ -69,6 +83,7 @@ services: dockerfile: ./horusec-api/deployments/Dockerfile.dev depends_on: - postgresql + - keycloak restart: always container_name: horusec-api ports: @@ -76,5 +91,4 @@ services: environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_JWT_SECRET_KEY: "horusec-secret" HORUSEC_AUTH_URL: "http://horusec-auth:8006" \ No newline at end of file diff --git a/e2e/server/keycloak/entities/user_representation.go b/e2e/server/keycloak/entities/user_representation.go new file mode 100644 index 000000000..a4edf1bdf --- /dev/null +++ b/e2e/server/keycloak/entities/user_representation.go @@ -0,0 +1,26 @@ +package entities + +import "encoding/json" + +type UserRepresentation struct { + Username string `json:"username"` + Email string `json:"email"` + EmailVerified bool `json:"emailVerified"` + Enabled bool `json:"enabled"` +} + +type UserRepresentationCredentials struct { + Temporary bool `json:"temporary"` + Type string `json:"type"` + Value string `json:"value"` +} + +func (u *UserRepresentation) ToBytes() []byte { + content, _ := json.Marshal(u) + return content +} + +func (u *UserRepresentationCredentials) ToBytes() []byte { + content, _ := json.Marshal(u) + return content +} diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index c9405cca8..bd5fa6e60 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -1 +1,124 @@ package ldap + +import ( + "fmt" + accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/utils/env" + "github.com/ZupIT/horusec/development-kit/pkg/utils/logger" + "github.com/ZupIT/horusec/e2e/server" + "github.com/ZupIT/horusec/e2e/server/keycloak/entities" + "github.com/golang-migrate/migrate/v4" + _ "github.com/golang-migrate/migrate/v4/database/postgres" + _ "github.com/golang-migrate/migrate/v4/source/file" + "github.com/stretchr/testify/assert" + "os" + "os/exec" + "strings" + "testing" + "time" +) + +func TestMain(m *testing.M) { + folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" + var connectionStringDB = env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + migration, err := migrate.New(folderOfMigration, connectionStringDB) + if err != nil { + logger.LogPanic("Error in create first instance migration: ", err) + } + if err := migration.Drop(); err != nil { + logger.LogPanic("Error in drop migration: ", err) + } + sourceErr, dbErr := migration.Close() + if sourceErr != nil { + logger.LogPanic("Error in source err to close connection: ", sourceErr) + } + if dbErr != nil { + logger.LogPanic("Error in database err to close connection: ", dbErr) + } + migration, err = migrate.New(folderOfMigration, connectionStringDB) + if err != nil { + logger.LogPanic("Error in create second instance migration: ", err) + } + if err := migration.Up(); err != nil { + if err.Error() != "no change" { + logger.LogPanic("Error in up migration: ", err) + } + } + code := m.Run() + os.Exit(code) +} + +func TestServer(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + t.Run("Should tests auth-type keycloak http requests", func(t *testing.T) { + bearerToken := CreateDefaultUserInKeycloakAndGetAccessToken(t) + assert.NotEmpty(t, bearerToken) + + CreateUserFromKeycloakInHorusec(t, &accountentities.KeycloakToken{AccessToken: bearerToken}) + // TESTBOOK: Authorize + // TESTBOOK: Create, Read, Update and Delete company + companyID := RunCompanyCRUD(t, bearerToken) + assert.NotEmpty(t, companyID) + }) +} + +func CreateDefaultUserInKeycloakAndGetAccessToken(t *testing.T) string { + user := &entities.UserRepresentation{ + Username: "e2e_user", + Email: "e2e@example.com", + EmailVerified: true, + Enabled: true, + } + credential := &entities.UserRepresentationCredentials{ + Temporary: false, + Type: "password", + Value: "Ch@ng3m3", + } + //responseLogin := LoginInKeycloak(t, "keycloak", "keycloak") + //bearerToken := "Bearer " + responseLogin["access_token"].(string) + //DeleteAllUsersInKeyCloak(t, bearerToken) + //CreateUserInKeyCloak(t, user, credential, bearerToken) + //StartAuthHorusecServices(t, bearerToken) + responseLogin := LoginInKeycloak(t, user.Username, credential.Value) + return "Bearer " + GetOAuthToken(t, "Bearer " + responseLogin["access_token"].(string)) +} + +func StartAuthHorusecServices(t *testing.T, bearerToken string) { + secret := GetClientSecretInAccountClient(t, bearerToken) + assert.NotEmpty(t, secret) + fmt.Println("Starting auth horusec service...") + output, err := exec.Command("whereis", "docker-compose").Output() + assert.NoError(t, err) + assert.NotEmpty(t, output) + pathComposeSplited := strings.Split(string(output), "docker-compose: ") + assert.Len(t, pathComposeSplited, 2) + pathCompose := pathComposeSplited[1][0 : len(pathComposeSplited[1])-1] + cmd := exec.Command(pathCompose, "-f", "../../deployments/docker-compose.server.keycloak.yaml", "up", "-d", "--build", "horusec-auth") + cmd.Env = append(cmd.Env, "HORUSEC_KEYCLOAK_CLIENT_SECRET="+secret) + output, err = cmd.CombinedOutput() + assert.NoError(t, err) + assert.NotEmpty(t, output) + fmt.Println("Waiting container up...") + time.Sleep(3 * time.Second) +} + +func RunCompanyCRUD(t *testing.T, bearerToken string) string { + t.Run("Should create an company, check if it exists, update your name check if name was updated delete a company and return new company to manager in other steps", func(t *testing.T) { + companyID := server.CreateCompany(t, bearerToken, &accountentities.Company{ + Name: "zup", + }) + allCompanies := server.ReadAllCompanies(t, bearerToken, true) + assert.Contains(t, allCompanies, "zup") + server.UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ + Name: "zup-1", + }) + allCompaniesUpdated := server.ReadAllCompanies(t, bearerToken, true) + assert.Contains(t, allCompaniesUpdated, "zup-1") + server.DeleteCompany(t, bearerToken, companyID) + }) + return server.CreateCompany(t, bearerToken, &accountentities.Company{ + Name: "zup", + }) +} diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go new file mode 100644 index 000000000..1211d353e --- /dev/null +++ b/e2e/server/keycloak/requests.go @@ -0,0 +1,158 @@ +package ldap + +import ( + "bytes" + "encoding/json" + "fmt" + "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/e2e/server/keycloak/entities" + "github.com/stretchr/testify/assert" + "net/http" + "strings" + "testing" +) + + +func LoginInKeycloak(t *testing.T, username, password string) map[string]interface{} { + fmt.Println("Running test for LoginInKeycloak in Keycloak") + payload := strings.NewReader(fmt.Sprintf("client_id=admin-cli&username=%s&password=%s&grant_type=password", username, password)) + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/auth/realms/master/protocol/openid-connect/token", payload) + req.Header.Add("content-type", "application/x-www-form-urlencoded") + req.Header.Add("cache-control", "no-cache") + + res, _ := http.DefaultClient.Do(req) + assert.Equal(t, http.StatusOK, res.StatusCode, "LoginInKeycloak error send request") + var response map[string]interface{} + _ = json.NewDecoder(res.Body).Decode(&response) + assert.NoError(t, res.Body.Close()) + assert.NotEmpty(t, response) + return response +} + +func GetOAuthToken(t *testing.T, bearerToken string) string { + fmt.Println("Running test for GetOAuthToken in Keycloak") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/auth/admin/realms/master/clients-initial-access", bytes.NewReader([]byte("{\"count\": 5,\"expiration\": 5}"))) + req.Header.Add("Authorization", bearerToken) + req.Header.Add("content-type", "application/json") + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "GetOAuthToken, create user error mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "GetOAuthToken create user error send request") + var response map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&response) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, response) + return response["token"].(string) +} + +func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserRepresentation, credentials *entities.UserRepresentationCredentials, bearerToken string) { + fmt.Println("Running test for CreateUserInKeyCloak") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/auth/admin/realms/master/users", bytes.NewReader(userRepresentation.ToBytes())) + req.Header.Add("Authorization", bearerToken) + req.Header.Add("content-type", "application/json") + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "CreateUserInKeyCloak, create user error mount request") + assert.Equal(t, http.StatusCreated, resp.StatusCode, "CreateUserInKeyCloak create user error send request") + assert.NoError(t, resp.Body.Close()) + allUsers := ListAllUsersInKeycloak(t, bearerToken) + idToSetCredential := "" + for _, user := range allUsers { + if user["username"] == userRepresentation.Username { + idToSetCredential = user["id"].(string) + } + } + assert.NotEmpty(t, idToSetCredential) + req, _ = http.NewRequest(http.MethodPut, "http://localhost:8080/auth/admin/realms/master/users/"+idToSetCredential+"/reset-password", bytes.NewReader(credentials.ToBytes())) + req.Header.Add("Authorization", bearerToken) + req.Header.Add("content-type", "application/json") + httpClient = http.Client{} + resp, err = httpClient.Do(req) + assert.NoError(t, err, "CreateUserInKeyCloak, update credentials user error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "CreateUserInKeyCloak update credentials user error send request") + assert.NoError(t, resp.Body.Close()) +} + +func ListAllUsersInKeycloak(t *testing.T, bearerToken string) []map[string]interface{} { + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/auth/admin/realms/master/users", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "DeleteAllUsersInKeyCloak: get all users error mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "DeleteAllUsersInKeyCloak: get all users error send request") + var response []map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&response) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, response) + return response +} + +func DeleteAllUsersInKeyCloak(t *testing.T, bearerToken string) { + fmt.Println("Running test for DeleteAllUsersInKeyCloak") + allUsers := ListAllUsersInKeycloak(t, bearerToken) + idsToRemove := []string{} + for _, user := range allUsers { + if user["username"] != "keycloak" { + idsToRemove = append(idsToRemove, user["id"].(string)) + } + } + assert.Equal(t, len(allUsers) - 1, len(idsToRemove)) + for _, id := range idsToRemove { + req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8080/auth/admin/realms/master/users/"+id, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "DeleteAllUsersInKeyCloak: remove user of id: " +id+ " error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "DeleteAllUsersInKeyCloak: remove user of id: " +id+ " error send request") + } +} + +func GetClientSecretInAccountClient(t *testing.T, bearerToken string) string { + fmt.Println("Running test for GetClientSecretInAccountClient") + allClients := ListAllClientsInKeycloak(t, bearerToken) + clientID := "" + for _, client := range allClients { + if client["clientId"] == "account" { + clientID = client["id"].(string) + } + } + assert.NotEmpty(t, clientID) + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/auth/admin/realms/master/clients/"+clientID+"/client-secret", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "GetClientSecretInAccountClient mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "GetClientSecretInAccountClient error send request") + var response map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&response) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, response) + return response["value"].(string) +} + +func ListAllClientsInKeycloak(t *testing.T, bearerToken string) []map[string]interface{} { + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/auth/admin/realms/master/clients", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "ListAllClientsInKeuycloak mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "ListAllClientsInKeuycloak error send request") + var response []map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&response) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, response) + return response +} + +func CreateUserFromKeycloakInHorusec(t *testing.T, token *account.KeycloakToken) { + fmt.Println("Running test for CreateUserFromKeycloakInHorusec") + req, _ := http.NewRequest(http.MethodPost, "http://localhost:8007/api/account/create-account-from-keycloak", bytes.NewReader(token.ToBytes())) + httpClient := http.Client{} + createCompanyResp, err := httpClient.Do(req) + assert.NoError(t, err, "CreateUserFromKeycloakInHorusec error send request") + assert.Equal(t, http.StatusOK, createCompanyResp.StatusCode, "CreateUserFromKeycloakInHorusec error check response") + var bodyResponse map[string]map[string]string + _ = json.NewDecoder(createCompanyResp.Body).Decode(&bodyResponse) + assert.NoError(t, createCompanyResp.Body.Close()) + assert.NotEmpty(t, bodyResponse) +} diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go index f4a849e9f..884db71bc 100644 --- a/e2e/server/shared_requests.go +++ b/e2e/server/shared_requests.go @@ -10,6 +10,7 @@ import ( "testing" ) + func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { fmt.Println("Running test for CreateCompany") req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(company.ToBytes())) @@ -24,3 +25,48 @@ func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Co assert.NotEmpty(t, createdCompany["content"]["companyID"]) return createdCompany["content"]["companyID"] } + +func UpdateCompany(t *testing.T, bearerToken string, companyID string, company *accountentities.Company) { + fmt.Println("Running test for UpdateCompany") + req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update company error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "update company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) +} + +func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) string { + fmt.Println("Running test for ReadAllCompanies") + req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all companies error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all companies error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + if isCheckBodyEmpty { + assert.NotEmpty(t, body["content"]) + } + content, _ := json.Marshal(body["content"]) + return string(content) +} + +func DeleteCompany(t *testing.T, bearerToken, companyID string) { + fmt.Println("Running test for DeleteCompany") + req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID, nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete company error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} From 22c46ee54269296d3c5ddca968b33299e3a5feba Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Wed, 4 Nov 2020 17:04:44 -0300 Subject: [PATCH 17/34] Adding Request to configure keycloak service --- Makefile | 2 +- .../pkg/services/keycloak/keycloak.go | 2 +- .../docker-compose.server.keycloak.yaml | 25 ++-- e2e/server/keycloak/http_test.go | 23 ++-- e2e/server/keycloak/requests.go | 112 ++++++++++++++++-- 5 files changed, 128 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 9c7bf0419..234961154 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,7 @@ compose-e2e-messages: $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.messages.yaml up -d --build --force-recreate compose-e2e-server-keycloak: $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml down -v - $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql keycloak horusec-account horusec-analytic horusec-api + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql keycloak horusec-account # ========================================================================================= # diff --git a/development-kit/pkg/services/keycloak/keycloak.go b/development-kit/pkg/services/keycloak/keycloak.go index 564ce0ce4..ff8950183 100644 --- a/development-kit/pkg/services/keycloak/keycloak.go +++ b/development-kit/pkg/services/keycloak/keycloak.go @@ -83,7 +83,7 @@ func (s *Service) GetUserInfo(accessToken string) (*gocloak.UserInfo, error) { return nil, errorsEnum.ErrorUnauthorized } - return s.client.GetUserInfo(s.ctx, accessToken, s.realm) + return s.client.GetUserInfo(s.ctx, s.removeBearer(accessToken), s.realm) } func (s *Service) removeBearer(accessToken string) string { diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index adfcb9795..569287da8 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -1,4 +1,5 @@ version: '3' + services: postgresql: container_name: postgresql @@ -38,9 +39,9 @@ services: - "8003:8003" environment: HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://horusec-auth:8006" + HORUSEC_AUTH_URL: "http://localhost:8006" horusec-auth: build: context: ../../ @@ -53,15 +54,15 @@ services: ports: - "8006:8006" environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_ENABLE_APPLICATION_ADMIN: "false" HORUSEC_AUTH_TYPE: "keycloak" - HORUSEC_KEYCLOAK_BASE_PATH=http://localhost:8080/auth/realms/master/account/ - HORUSEC_KEYCLOAK_CLIENT_ID=account - HORUSEC_KEYCLOAK_CLIENT_SECRET=afc12778-333b-48bc-b932-65cdcd4025b1 - HORUSEC_KEYCLOAK_REALM=master - HORUSEC_KEYCLOAK_OTP=false + HORUSEC_KEYCLOAK_BASE_PATH: "http://localhost:8080" + HORUSEC_KEYCLOAK_CLIENT_ID: "account" + HORUSEC_KEYCLOAK_CLIENT_SECRET: ${HORUSEC_KEYCLOAK_CLIENT_SECRET} + HORUSEC_KEYCLOAK_REALM: "master" + HORUSEC_KEYCLOAK_OTP: "false" horusec-analytic: build: context: ../../ @@ -74,9 +75,9 @@ services: ports: - "8005:8005" environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://horusec-auth:8006" + HORUSEC_AUTH_URL: "http://localhost:8006" horusec-api: build: context: ../../ @@ -89,6 +90,6 @@ services: ports: - "8000:8000" environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@postgresql:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://horusec-auth:8006" \ No newline at end of file + HORUSEC_AUTH_URL: "http://localhost:8006" diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index bd5fa6e60..79ec71d4c 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -20,7 +20,7 @@ import ( func TestMain(m *testing.M) { folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" - var connectionStringDB = env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + var connectionStringDB = env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@0.0.0.0:5432/horusec_db?sslmode=disable") migration, err := migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create first instance migration: ", err) @@ -76,18 +76,19 @@ func CreateDefaultUserInKeycloakAndGetAccessToken(t *testing.T) string { Type: "password", Value: "Ch@ng3m3", } - //responseLogin := LoginInKeycloak(t, "keycloak", "keycloak") - //bearerToken := "Bearer " + responseLogin["access_token"].(string) - //DeleteAllUsersInKeyCloak(t, bearerToken) - //CreateUserInKeyCloak(t, user, credential, bearerToken) - //StartAuthHorusecServices(t, bearerToken) - responseLogin := LoginInKeycloak(t, user.Username, credential.Value) - return "Bearer " + GetOAuthToken(t, "Bearer " + responseLogin["access_token"].(string)) -} - -func StartAuthHorusecServices(t *testing.T, bearerToken string) { + responseLogin := LoginInKeycloak(t, "keycloak", "keycloak") + bearerToken := "Bearer " + responseLogin["access_token"].(string) + UpdateRolesToAcceptOAuth(t, bearerToken) + DeleteAllUsersInKeyCloak(t, bearerToken) + CreateUserInKeyCloak(t, user, credential, bearerToken) secret := GetClientSecretInAccountClient(t, bearerToken) assert.NotEmpty(t, secret) + StartAuthHorusecServices(t, bearerToken, secret) + responseLogin = LoginInKeycloak(t, user.Username, credential.Value) + return responseLogin["access_token"].(string) +} + +func StartAuthHorusecServices(t *testing.T, bearerToken, secret string) { fmt.Println("Starting auth horusec service...") output, err := exec.Command("whereis", "docker-compose").Output() assert.NoError(t, err) diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go index 1211d353e..9c5107212 100644 --- a/e2e/server/keycloak/requests.go +++ b/e2e/server/keycloak/requests.go @@ -16,7 +16,7 @@ import ( func LoginInKeycloak(t *testing.T, username, password string) map[string]interface{} { fmt.Println("Running test for LoginInKeycloak in Keycloak") payload := strings.NewReader(fmt.Sprintf("client_id=admin-cli&username=%s&password=%s&grant_type=password", username, password)) - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/auth/realms/master/protocol/openid-connect/token", payload) + req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/realms/master/protocol/openid-connect/token", payload) req.Header.Add("content-type", "application/x-www-form-urlencoded") req.Header.Add("cache-control", "no-cache") @@ -31,7 +31,7 @@ func LoginInKeycloak(t *testing.T, username, password string) map[string]interfa func GetOAuthToken(t *testing.T, bearerToken string) string { fmt.Println("Running test for GetOAuthToken in Keycloak") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/auth/admin/realms/master/clients-initial-access", bytes.NewReader([]byte("{\"count\": 5,\"expiration\": 5}"))) + req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/clients-initial-access", bytes.NewReader([]byte("{\"count\": 5,\"expiration\": 5}"))) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient := http.Client{} @@ -47,7 +47,7 @@ func GetOAuthToken(t *testing.T, bearerToken string) string { func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserRepresentation, credentials *entities.UserRepresentationCredentials, bearerToken string) { fmt.Println("Running test for CreateUserInKeyCloak") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8080/auth/admin/realms/master/users", bytes.NewReader(userRepresentation.ToBytes())) + req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/users", bytes.NewReader(userRepresentation.ToBytes())) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient := http.Client{} @@ -63,7 +63,7 @@ func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserReprese } } assert.NotEmpty(t, idToSetCredential) - req, _ = http.NewRequest(http.MethodPut, "http://localhost:8080/auth/admin/realms/master/users/"+idToSetCredential+"/reset-password", bytes.NewReader(credentials.ToBytes())) + req, _ = http.NewRequest(http.MethodPut, "http://0.0.0.0:8080/auth/admin/realms/master/users/"+idToSetCredential+"/reset-password", bytes.NewReader(credentials.ToBytes())) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient = http.Client{} @@ -71,10 +71,23 @@ func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserReprese assert.NoError(t, err, "CreateUserInKeyCloak, update credentials user error mount request") assert.Equal(t, http.StatusNoContent, resp.StatusCode, "CreateUserInKeyCloak update credentials user error send request") assert.NoError(t, resp.Body.Close()) + + role := GetRoleAdminInKeycloak(t, bearerToken) + var allRoles []map[string]interface{} + allRoles = append(allRoles, role) + allRolesBytes, _ := json.Marshal(allRoles) + req, _ = http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/users/"+idToSetCredential+"/role-mappings/realm", bytes.NewReader(allRolesBytes)) + req.Header.Add("Authorization", bearerToken) + req.Header.Add("content-type", "application/json") + httpClient = http.Client{} + resp, err = httpClient.Do(req) + assert.NoError(t, err, "CreateUserInKeyCloak, update role mapping user error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "CreateUserInKeyCloak, update role mapping user error send request") + assert.NoError(t, resp.Body.Close()) } func ListAllUsersInKeycloak(t *testing.T, bearerToken string) []map[string]interface{} { - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/auth/admin/realms/master/users", nil) + req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/users", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -98,7 +111,7 @@ func DeleteAllUsersInKeyCloak(t *testing.T, bearerToken string) { } assert.Equal(t, len(allUsers) - 1, len(idsToRemove)) for _, id := range idsToRemove { - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8080/auth/admin/realms/master/users/"+id, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://0.0.0.0:8080/auth/admin/realms/master/users/"+id, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -117,7 +130,7 @@ func GetClientSecretInAccountClient(t *testing.T, bearerToken string) string { } } assert.NotEmpty(t, clientID) - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/auth/admin/realms/master/clients/"+clientID+"/client-secret", nil) + req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/clients/"+clientID+"/client-secret", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -130,13 +143,90 @@ func GetClientSecretInAccountClient(t *testing.T, bearerToken string) string { return response["value"].(string) } +func UpdateRolesToAcceptOAuth(t *testing.T, bearerToken string) { + allClients := ListAllClientsInKeycloak(t, bearerToken) + var client map[string]interface{} + for _, actualClient := range allClients { + if actualClient["clientId"] == "account" { + client = actualClient + } + } + assert.NotEmpty(t, client) + client["authorizationServicesEnabled"] = true + client["directAccessGrantsEnabled"] = true + client["enabled"] = true + client["implicitFlowEnabled"] = true + client["serviceAccountsEnabled"] = true + client["standardFlowEnabled"] = true + client["surrogateAuthRequired"] = true + clientID := client["id"].(string) + clientBytes, _ := json.Marshal(client) + req, _ := http.NewRequest(http.MethodPut, "http://0.0.0.0:8080/auth/admin/realms/master/clients/"+clientID, bytes.NewReader(clientBytes)) + req.Header.Add("Authorization", bearerToken) + req.Header.Add("content-type", "application/json") + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "UpdateRolesToAcceptOAuth, update account client content error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "UpdateRolesToAcceptOAuth, update account client error send request") + assert.NoError(t, resp.Body.Close()) + + // Update Role to admin accept all content + role := GetRoleAdminInKeycloak(t, bearerToken) + roleID := role["id"].(string) + allRoles := GetAllRolesFromClientID(t, bearerToken, clientID) + allRolesBytes, _ := json.Marshal(allRoles) + req, _ = http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/roles-by-id/"+roleID+"/composites", bytes.NewReader(allRolesBytes)) + req.Header.Add("Authorization", bearerToken) + req.Header.Add("content-type", "application/json") + httpClient = http.Client{} + resp, err = httpClient.Do(req) + assert.NoError(t, err, "UpdateRolesToAcceptOAuth, update account client content error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "UpdateRolesToAcceptOAuth, update account client error send request") + assert.NoError(t, resp.Body.Close()) +} + func ListAllClientsInKeycloak(t *testing.T, bearerToken string) []map[string]interface{} { - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/auth/admin/realms/master/clients", nil) + req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/clients", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "ListAllClientsInKeycloak mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "ListAllClientsInKeycloak error send request") + var response []map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&response) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, response) + return response +} + +func GetRoleAdminInKeycloak(t *testing.T, bearerToken string) map[string]interface{} { + req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/roles", nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "ListAllRolesInKeycloak mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "ListAllRolesInKeycloak error send request") + var response []map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&response) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, response) + var role map[string]interface{} + for _, currentRole := range response { + if currentRole["name"] == "admin" { + role = currentRole + } + } + assert.NotEmpty(t, role) + return role +} + +func GetAllRolesFromClientID(t *testing.T, bearerToken, clientID string) []map[string]interface{} { + req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/clients/"+clientID+"/roles", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) - assert.NoError(t, err, "ListAllClientsInKeuycloak mount request") - assert.Equal(t, http.StatusOK, resp.StatusCode, "ListAllClientsInKeuycloak error send request") + assert.NoError(t, err, "ListAllRolesInKeycloak mount request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "ListAllRolesInKeycloak error send request") var response []map[string]interface{} _ = json.NewDecoder(resp.Body).Decode(&response) assert.NoError(t, resp.Body.Close()) @@ -146,7 +236,7 @@ func ListAllClientsInKeycloak(t *testing.T, bearerToken string) []map[string]int func CreateUserFromKeycloakInHorusec(t *testing.T, token *account.KeycloakToken) { fmt.Println("Running test for CreateUserFromKeycloakInHorusec") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8007/api/account/create-account-from-keycloak", bytes.NewReader(token.ToBytes())) + req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8006/api/account/create-account-from-keycloak", bytes.NewReader(token.ToBytes())) httpClient := http.Client{} createCompanyResp, err := httpClient.Do(req) assert.NoError(t, err, "CreateUserFromKeycloakInHorusec error send request") From 976afc9bb47b3a64c5951a1a1dbe3f20787dc91f Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 5 Nov 2020 10:21:38 -0300 Subject: [PATCH 18/34] Adding correctly form to run tests using keycloak server --- .github/workflows/e2e.yml | 14 ++++++ Makefile | 2 +- e2e/TESTBOOK.md | 10 ++--- .../docker-compose.server.keycloak.yaml | 42 +++++++++++++----- e2e/server/keycloak/http_test.go | 2 +- e2e/server/keycloak/requests.go | 44 ++++++------------- e2e/server/shared_requests.go | 8 ++-- 7 files changed, 69 insertions(+), 53 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ad6700f25..f46ad399e 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -35,6 +35,20 @@ jobs: uses: actions/checkout@v2 - name: e2e run: make test-e2e-server-horusec + e2e-server-keycloak: + name: e2e-server-keycloak + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - name: Set up Go 1.14 + uses: actions/setup-go@v1 + with: + go-version: 1.14 + id: go + - name: Check out code + uses: actions/checkout@v2 + - name: e2e + run: make test-e2e-server-keycloak e2e-application-admin-horusec: name: e2e-application-admin-horusec runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 234961154..bebf77436 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,7 @@ compose-e2e-messages: $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.messages.yaml up -d --build --force-recreate compose-e2e-server-keycloak: $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml down -v - $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql keycloak horusec-account + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql postgresql_keycloak keycloak horusec-account # ========================================================================================= # diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 9e70db67e..3abeca96d 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -12,23 +12,21 @@ - [ ] Create account - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type + - [X] Keycloak auth type - [ ] Login - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type + - [X] Keycloak auth type - [ ] Logout - [X] Horusec auth type - - [ ] Ldap auth type - - [ ] Keycloak auth type - [ ] Authorize - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type + - [X] Keycloak auth type - [ ] Create, Read, Update and Delete company - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type + - [X] Keycloak auth type - [X] Create, Read, and Delete company token - [X] Create, Read, Update, and Delete repositories - [X] Create, Read, and Delete repository token diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index 569287da8..8e3ec1eac 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -17,15 +17,31 @@ services: driver: json-file options: max-size: 10m + postgresql_keycloak: + container_name: postgresql_keycloak + image: postgres:12 + ports: + - "5433:5433" + expose: + - "5433" + command: -p 5433 + environment: + POSTGRES_PASSWORD: root + POSTGRES_USER: root + POSTGRES_DB: keycloak keycloak: container_name: keycloak image: jboss/keycloak ports: - "8080:8080" environment: - DB_VENDOR: h2 - KEYCLOAK_USER: keycloak - KEYCLOAK_PASSWORD: keycloak + DB_VENDOR: "postgres" + DB_ADDR: "postgresql_keycloak" + DB_PORT: "5433" + DB_USER: "root" + DB_PASSWORD: "root" + KEYCLOAK_USER: "keycloak" + KEYCLOAK_PASSWORD: "keycloak" horusec-account: build: context: ../../ @@ -37,11 +53,12 @@ services: container_name: horusec-account ports: - "8003:8003" + network_mode: "host" environment: HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://localhost:8006" + HORUSEC_AUTH_URL: "http://127.0.0.1:8006" horusec-auth: build: context: ../../ @@ -53,12 +70,13 @@ services: container_name: horusec-auth ports: - "8006:8006" + network_mode: "host" environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_ENABLE_APPLICATION_ADMIN: "false" HORUSEC_AUTH_TYPE: "keycloak" - HORUSEC_KEYCLOAK_BASE_PATH: "http://localhost:8080" + HORUSEC_KEYCLOAK_BASE_PATH: "http://127.0.0.1:8080" HORUSEC_KEYCLOAK_CLIENT_ID: "account" HORUSEC_KEYCLOAK_CLIENT_SECRET: ${HORUSEC_KEYCLOAK_CLIENT_SECRET} HORUSEC_KEYCLOAK_REALM: "master" @@ -74,10 +92,11 @@ services: container_name: horusec-analytic ports: - "8005:8005" + network_mode: "host" environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://localhost:8006" + HORUSEC_AUTH_URL: "http://127.0.0.1:8006" horusec-api: build: context: ../../ @@ -89,7 +108,8 @@ services: container_name: horusec-api ports: - "8000:8000" + network_mode: "host" environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable" + HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://localhost:8006" + HORUSEC_AUTH_URL: "http://127.0.0.1:8006" diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index 79ec71d4c..15431b0f4 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -20,7 +20,7 @@ import ( func TestMain(m *testing.M) { folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" - var connectionStringDB = env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@0.0.0.0:5432/horusec_db?sslmode=disable") + var connectionStringDB = env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable") migration, err := migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create first instance migration: ", err) diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go index 9c5107212..b1670b2ea 100644 --- a/e2e/server/keycloak/requests.go +++ b/e2e/server/keycloak/requests.go @@ -16,7 +16,7 @@ import ( func LoginInKeycloak(t *testing.T, username, password string) map[string]interface{} { fmt.Println("Running test for LoginInKeycloak in Keycloak") payload := strings.NewReader(fmt.Sprintf("client_id=admin-cli&username=%s&password=%s&grant_type=password", username, password)) - req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/realms/master/protocol/openid-connect/token", payload) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token", payload) req.Header.Add("content-type", "application/x-www-form-urlencoded") req.Header.Add("cache-control", "no-cache") @@ -29,25 +29,9 @@ func LoginInKeycloak(t *testing.T, username, password string) map[string]interfa return response } -func GetOAuthToken(t *testing.T, bearerToken string) string { - fmt.Println("Running test for GetOAuthToken in Keycloak") - req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/clients-initial-access", bytes.NewReader([]byte("{\"count\": 5,\"expiration\": 5}"))) - req.Header.Add("Authorization", bearerToken) - req.Header.Add("content-type", "application/json") - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "GetOAuthToken, create user error mount request") - assert.Equal(t, http.StatusOK, resp.StatusCode, "GetOAuthToken create user error send request") - var response map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&response) - assert.NoError(t, resp.Body.Close()) - assert.NotEmpty(t, response) - return response["token"].(string) -} - func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserRepresentation, credentials *entities.UserRepresentationCredentials, bearerToken string) { fmt.Println("Running test for CreateUserInKeyCloak") - req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/users", bytes.NewReader(userRepresentation.ToBytes())) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8080/auth/admin/realms/master/users", bytes.NewReader(userRepresentation.ToBytes())) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient := http.Client{} @@ -63,7 +47,7 @@ func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserReprese } } assert.NotEmpty(t, idToSetCredential) - req, _ = http.NewRequest(http.MethodPut, "http://0.0.0.0:8080/auth/admin/realms/master/users/"+idToSetCredential+"/reset-password", bytes.NewReader(credentials.ToBytes())) + req, _ = http.NewRequest(http.MethodPut, "http://127.0.0.1:8080/auth/admin/realms/master/users/"+idToSetCredential+"/reset-password", bytes.NewReader(credentials.ToBytes())) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient = http.Client{} @@ -76,7 +60,7 @@ func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserReprese var allRoles []map[string]interface{} allRoles = append(allRoles, role) allRolesBytes, _ := json.Marshal(allRoles) - req, _ = http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/users/"+idToSetCredential+"/role-mappings/realm", bytes.NewReader(allRolesBytes)) + req, _ = http.NewRequest(http.MethodPost, "http://127.0.0.1:8080/auth/admin/realms/master/users/"+idToSetCredential+"/role-mappings/realm", bytes.NewReader(allRolesBytes)) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient = http.Client{} @@ -87,7 +71,7 @@ func CreateUserInKeyCloak(t *testing.T, userRepresentation *entities.UserReprese } func ListAllUsersInKeycloak(t *testing.T, bearerToken string) []map[string]interface{} { - req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/users", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/auth/admin/realms/master/users", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -111,7 +95,7 @@ func DeleteAllUsersInKeyCloak(t *testing.T, bearerToken string) { } assert.Equal(t, len(allUsers) - 1, len(idsToRemove)) for _, id := range idsToRemove { - req, _ := http.NewRequest(http.MethodDelete, "http://0.0.0.0:8080/auth/admin/realms/master/users/"+id, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8080/auth/admin/realms/master/users/"+id, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -130,7 +114,7 @@ func GetClientSecretInAccountClient(t *testing.T, bearerToken string) string { } } assert.NotEmpty(t, clientID) - req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/clients/"+clientID+"/client-secret", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/auth/admin/realms/master/clients/"+clientID+"/client-secret", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -161,7 +145,7 @@ func UpdateRolesToAcceptOAuth(t *testing.T, bearerToken string) { client["surrogateAuthRequired"] = true clientID := client["id"].(string) clientBytes, _ := json.Marshal(client) - req, _ := http.NewRequest(http.MethodPut, "http://0.0.0.0:8080/auth/admin/realms/master/clients/"+clientID, bytes.NewReader(clientBytes)) + req, _ := http.NewRequest(http.MethodPut, "http://127.0.0.1:8080/auth/admin/realms/master/clients/"+clientID, bytes.NewReader(clientBytes)) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient := http.Client{} @@ -175,7 +159,7 @@ func UpdateRolesToAcceptOAuth(t *testing.T, bearerToken string) { roleID := role["id"].(string) allRoles := GetAllRolesFromClientID(t, bearerToken, clientID) allRolesBytes, _ := json.Marshal(allRoles) - req, _ = http.NewRequest(http.MethodPost, "http://0.0.0.0:8080/auth/admin/realms/master/roles-by-id/"+roleID+"/composites", bytes.NewReader(allRolesBytes)) + req, _ = http.NewRequest(http.MethodPost, "http://127.0.0.1:8080/auth/admin/realms/master/roles-by-id/"+roleID+"/composites", bytes.NewReader(allRolesBytes)) req.Header.Add("Authorization", bearerToken) req.Header.Add("content-type", "application/json") httpClient = http.Client{} @@ -186,7 +170,7 @@ func UpdateRolesToAcceptOAuth(t *testing.T, bearerToken string) { } func ListAllClientsInKeycloak(t *testing.T, bearerToken string) []map[string]interface{} { - req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/clients", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/auth/admin/realms/master/clients", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -200,7 +184,7 @@ func ListAllClientsInKeycloak(t *testing.T, bearerToken string) []map[string]int } func GetRoleAdminInKeycloak(t *testing.T, bearerToken string) map[string]interface{} { - req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/roles", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/auth/admin/realms/master/roles", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -221,7 +205,7 @@ func GetRoleAdminInKeycloak(t *testing.T, bearerToken string) map[string]interfa } func GetAllRolesFromClientID(t *testing.T, bearerToken, clientID string) []map[string]interface{} { - req, _ := http.NewRequest(http.MethodGet, "http://0.0.0.0:8080/auth/admin/realms/master/clients/"+clientID+"/roles", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/auth/admin/realms/master/clients/"+clientID+"/roles", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -236,12 +220,12 @@ func GetAllRolesFromClientID(t *testing.T, bearerToken, clientID string) []map[s func CreateUserFromKeycloakInHorusec(t *testing.T, token *account.KeycloakToken) { fmt.Println("Running test for CreateUserFromKeycloakInHorusec") - req, _ := http.NewRequest(http.MethodPost, "http://0.0.0.0:8006/api/account/create-account-from-keycloak", bytes.NewReader(token.ToBytes())) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8006/api/account/create-account-from-keycloak", bytes.NewReader(token.ToBytes())) httpClient := http.Client{} createCompanyResp, err := httpClient.Do(req) assert.NoError(t, err, "CreateUserFromKeycloakInHorusec error send request") assert.Equal(t, http.StatusOK, createCompanyResp.StatusCode, "CreateUserFromKeycloakInHorusec error check response") - var bodyResponse map[string]map[string]string + var bodyResponse map[string]interface{} _ = json.NewDecoder(createCompanyResp.Body).Decode(&bodyResponse) assert.NoError(t, createCompanyResp.Body.Close()) assert.NotEmpty(t, bodyResponse) diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go index 884db71bc..65f2e9cfd 100644 --- a/e2e/server/shared_requests.go +++ b/e2e/server/shared_requests.go @@ -13,7 +13,7 @@ import ( func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { fmt.Println("Running test for CreateCompany") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(company.ToBytes())) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/companies", bytes.NewReader(company.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} createCompanyResp, err := httpClient.Do(req) @@ -28,7 +28,7 @@ func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Co func UpdateCompany(t *testing.T, bearerToken string, companyID string, company *accountentities.Company) { fmt.Println("Running test for UpdateCompany") - req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) + req, _ := http.NewRequest(http.MethodPatch, "http://127.0.0.1:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -42,7 +42,7 @@ func UpdateCompany(t *testing.T, bearerToken string, companyID string, company * func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) string { fmt.Println("Running test for ReadAllCompanies") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8003/api/companies", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -60,7 +60,7 @@ func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) s func DeleteCompany(t *testing.T, bearerToken, companyID string) { fmt.Println("Running test for DeleteCompany") - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8003/api/companies/"+companyID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) From 4f708c13c75893a78ec1cc6f6187bb20690a5ce1 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 5 Nov 2020 10:30:16 -0300 Subject: [PATCH 19/34] Fixing makefile --- Makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index bebf77436..9b73878af 100644 --- a/Makefile +++ b/Makefile @@ -47,30 +47,30 @@ test: $(GO) clean -testcache && $(GO) test -v ./... -timeout=20m -parallel=1 -failfast -short test-e2e-cli: - go get -v ./e2e/... - go get -v ./horusec-cli/... + $(GO) get -v ./e2e/... + $(GO) get -v ./horusec-cli/... $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast test-e2e-server-horusec: make compose-e2e-server-horusec - go get -v ./e2e/... + $(GO) get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/server/horusec/... -timeout=5m -parallel=1 -failfast test-e2e-application-admin-horusec: make compose-e2e-application-admin-horusec - go get -v ./e2e/... + $(GO) get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/application_admin/horusec/... -timeout=5m -parallel=1 -failfast test-e2e-messages: make compose-e2e-messages - go get -v ./e2e/... + $(GO) get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/server/messages/... -timeout=5m -parallel=1 -failfast test-e2e-server-keycloak: make compose-e2e-server-keycloak - go get -v ./e2e/... + $(GO) get -v ./e2e/... $(GO) clean -testcache - $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast + sleep 3 && $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast # ========================================================================================= # @@ -146,7 +146,7 @@ install-cli: curl -fsSL https://horusec-cli.s3.amazonaws.com/install.sh | bash build-install-cli: - go build -o horusec ./horusec-cli/cmd/horusec/main.go + $(GO) build -o horusec ./horusec-cli/cmd/horusec/main.go chmod +x horusec rm -rf $(GOPATH)/bin/horusec mv horusec $(GOPATH)/bin @@ -154,7 +154,7 @@ build-install-cli: horusec version build-install-leaks-cli: - go build -o horusec ./horusec-leaks/cmd/app/main.go + $(GO) build -o horusec ./horusec-leaks/cmd/app/main.go chmod +x horusec rm -rf $(GOPATH)/bin/horusec-leaks mv horusec $(GOPATH)/bin/horusec-leaks @@ -162,7 +162,7 @@ build-install-leaks-cli: horusec-leaks version build-install-kotlin-cli: - go build -o horusec ./horusec-kotlin/cmd/app/main.go + $(GO) build -o horusec ./horusec-kotlin/cmd/app/main.go chmod +x horusec rm -rf $(GOPATH)/bin/horusec-kotlin mv horusec $(GOPATH)/bin/horusec-kotlin @@ -170,7 +170,7 @@ build-install-kotlin-cli: horusec-kotlin version build-install-java-cli: - go build -o horusec ./horusec-java/cmd/app/main.go + $(GO) build -o horusec ./horusec-java/cmd/app/main.go chmod +x horusec rm -rf $(GOPATH)/bin/horusec-java mv horusec $(GOPATH)/bin/horusec-java From 2d03f5ac31165ddae510ce9e353c53aefe5c17f9 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 5 Nov 2020 14:55:15 -0300 Subject: [PATCH 20/34] Adding tests in keycloak to validate invite user --- Makefile | 2 +- e2e/TESTBOOK.md | 5 +- .../docker-compose.server.keycloak.yaml | 16 -- e2e/server/horusec/http_test.go | 31 ++-- e2e/server/horusec/requests.go | 143 ------------------ e2e/server/keycloak/http_test.go | 75 +++++++++ e2e/server/shared_requests.go | 90 +++++++++++ 7 files changed, 184 insertions(+), 178 deletions(-) diff --git a/Makefile b/Makefile index 9b73878af..15f0500dc 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,7 @@ compose-e2e-messages: $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.messages.yaml up -d --build --force-recreate compose-e2e-server-keycloak: $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml down -v - $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql postgresql_keycloak keycloak horusec-account + $(DOCKER_COMPOSE) -f e2e/deployments/docker-compose.server.keycloak.yaml up -d --build --force-recreate postgresql postgresql_keycloak keycloak horusec-account horusec-analytic # ========================================================================================= # diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 3abeca96d..68dd38293 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -30,16 +30,15 @@ - [X] Create, Read, and Delete company token - [X] Create, Read, Update, and Delete repositories - [X] Create, Read, and Delete repository token -- [ ] Invite, Read, Update and Remove users in company +- [X] Invite, Read, Update and Remove users in company - [X] Horusec auth type - - [ ] Keycloak auth + - [X] Keycloak auth - [X] Create and Read analysis - [X] Repository Token - [X] Company Token + repository name - [ ] Invite, Read, Update and Remove users in repository - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type - [X] Get Dashboard content - [X] Company view - [X] Repository view diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index 8e3ec1eac..bd421728d 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -97,19 +97,3 @@ services: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_AUTH_URL: "http://127.0.0.1:8006" - horusec-api: - build: - context: ../../ - dockerfile: ./horusec-api/deployments/Dockerfile.dev - depends_on: - - postgresql - - keycloak - restart: always - container_name: horusec-api - ports: - - "8000:8000" - network_mode: "host" - environment: - HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" - HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" diff --git a/e2e/server/horusec/http_test.go b/e2e/server/horusec/http_test.go index dc2048fe9..d0bb1f18f 100644 --- a/e2e/server/horusec/http_test.go +++ b/e2e/server/horusec/http_test.go @@ -10,6 +10,7 @@ import ( rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account" horusecEnums "github.com/ZupIT/horusec/development-kit/pkg/enums/horusec" "github.com/ZupIT/horusec/development-kit/pkg/utils/test" + "github.com/ZupIT/horusec/e2e/server" "github.com/google/uuid" "github.com/stretchr/testify/assert" "net/http" @@ -104,19 +105,19 @@ func TestServer(t *testing.T) { func RunCompanyCRUD(t *testing.T, bearerToken string) string { t.Run("Should create an company, check if it exists, update your name check if name was updated delete a company and return new company to manager in other steps", func(t *testing.T) { - companyID := CreateCompany(t, bearerToken, &accountentities.Company{ + companyID := server.CreateCompany(t, bearerToken, &accountentities.Company{ Name: "zup", }) - allCompanies := ReadAllCompanies(t, bearerToken, true) + allCompanies := server.ReadAllCompanies(t, bearerToken, true) assert.Contains(t, allCompanies, "zup") - UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ + server.UpdateCompany(t, bearerToken, companyID, &accountentities.Company{ Name: "zup-1", }) - allCompaniesUpdated := ReadAllCompanies(t, bearerToken, true) + allCompaniesUpdated := server.ReadAllCompanies(t, bearerToken, true) assert.Contains(t, allCompaniesUpdated, "zup-1") - DeleteCompany(t, bearerToken, companyID) + server.DeleteCompany(t, bearerToken, companyID) }) - return CreateCompany(t, bearerToken, &accountentities.Company{ + return server.CreateCompany(t, bearerToken, &accountentities.Company{ Name: "zup", }) } @@ -304,14 +305,14 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { CreateAccount(t, account2) // Invite user to existing company - InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ + server.InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ Role: rolesEnum.Member, Email: account2.Email, CompanyID: companyIDParsed, }) // Check if exist two users in company - allUsersInCompany := ReadAllUserInCompany(t, bearerTokenAccount1, companyID) + allUsersInCompany := server.ReadAllUserInCompany(t, bearerTokenAccount1, companyID) accountRoles := []roles.AccountRole{} assert.NoError(t, json.Unmarshal([]byte(allUsersInCompany), &accountRoles)) assert.NotEmpty(t, accountRoles) @@ -331,27 +332,27 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { bearerTokenAccount2 := contentLoginAccount2["accessToken"] // Check if company exists to new user - allCompanies := ReadAllCompanies(t, bearerTokenAccount2, true) + allCompanies := server.ReadAllCompanies(t, bearerTokenAccount2, true) assert.Contains(t, allCompanies, "zup") // Expected return unauthorized because user is not admin of company to see dashboard in company view - responseChart := GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") + responseChart := server.GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") assert.Equal(t, http.StatusUnauthorized, responseChart.GetStatusCode()) // Update permission of new user to admin - UpdateUserInCompany(t, bearerTokenAccount1, companyID, accountID, &roles.AccountCompany{ + server.UpdateUserInCompany(t, bearerTokenAccount1, companyID, accountID, &roles.AccountCompany{ Role: rolesEnum.Admin, }) // Expected return OK because user is authorized view dashboard in company view - responseChart = GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") + responseChart = server.GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") assert.Equal(t, http.StatusOK, responseChart.GetStatusCode()) // Expected remove user from company - RemoveUserInCompany(t, bearerTokenAccount1, companyID, accountID) + server.RemoveUserInCompany(t, bearerTokenAccount1, companyID, accountID) // Not show company for user when get all companies - allCompanies = ReadAllCompanies(t, bearerTokenAccount2, false) + allCompanies = server.ReadAllCompanies(t, bearerTokenAccount2, false) assert.NotContains(t, allCompanies, "zup") // Logout session new user @@ -372,7 +373,7 @@ func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repos CreateAccount(t, account2) // Invite new user to existing company - InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ + server.InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ Role: rolesEnum.Member, Email: account2.Email, CompanyID: companyIDParsed, diff --git a/e2e/server/horusec/requests.go b/e2e/server/horusec/requests.go index dee61357b..636bac7f2 100644 --- a/e2e/server/horusec/requests.go +++ b/e2e/server/horusec/requests.go @@ -61,66 +61,6 @@ func Logout(t *testing.T, bearerToken string) { assert.NoError(t, resp.Body.Close()) } -func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { - fmt.Println("Running test for CreateCompany") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(company.ToBytes())) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - createCompanyResp, err := httpClient.Do(req) - assert.NoError(t, err, "create company error send request") - assert.Equal(t, http.StatusCreated, createCompanyResp.StatusCode, "create company error check response") - var createdCompany map[string]map[string]string - _ = json.NewDecoder(createCompanyResp.Body).Decode(&createdCompany) - assert.NoError(t, createCompanyResp.Body.Close()) - assert.NotEmpty(t, createdCompany["content"]["companyID"]) - return createdCompany["content"]["companyID"] -} - -func UpdateCompany(t *testing.T, bearerToken string, companyID string, company *accountentities.Company) { - fmt.Println("Running test for UpdateCompany") - req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "update company error send request") - assert.Equal(t, http.StatusOK, resp.StatusCode, "update company error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) - assert.NotEmpty(t, body["content"]) -} - -func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) string { - fmt.Println("Running test for ReadAllCompanies") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "read all companies error send request") - assert.Equal(t, http.StatusOK, resp.StatusCode, "read all companies error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) - if isCheckBodyEmpty { - assert.NotEmpty(t, body["content"]) - } - content, _ := json.Marshal(body["content"]) - return string(content) -} - -func DeleteCompany(t *testing.T, bearerToken, companyID string) { - fmt.Println("Running test for DeleteCompany") - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID, nil) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "delete company error send request") - assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete company error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) -} - func CreateRepository(t *testing.T, bearerToken, companyID string, repository *accountentities.Repository) string { repositoryBytes, _ := json.Marshal(repository) fmt.Println("Running test for CreateRepository") @@ -449,89 +389,6 @@ func UpdateVulnerabilitiesType(t *testing.T, bearerToken, companyID, repositoryI content, _ := json.Marshal(body["content"]) return string(content) } -func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *accountentities.InviteUser) { - fmt.Println("Running test for InviteUserToCompany") - req, _ := http.NewRequest( - http.MethodPost, - "http://localhost:8003/api/companies/"+companyID+"/roles", - bytes.NewReader(user.ToBytes())) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "invite user error send request") - assert.Equal(t, http.StatusNoContent, resp.StatusCode, "invite user error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) -} -func ReadAllUserInCompany(t *testing.T, bearerToken, companyID string) string { - fmt.Println("Running test for InviteUserToCompany") - req, _ := http.NewRequest( - http.MethodGet, - "http://localhost:8003/api/companies/"+companyID+"/roles", - nil) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "read all user in company error send request") - assert.Equal(t, http.StatusOK, resp.StatusCode, "read all user in company error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) - assert.NotEmpty(t, body["content"]) - content, _ := json.Marshal(body["content"]) - return string(content) -} -func UpdateUserInCompany(t *testing.T, bearerToken, companyID, accountID string, account *roles.AccountCompany) string { - fmt.Println("Running test for UpdateUserInCompany") - req, _ := http.NewRequest( - http.MethodPatch, - "http://localhost:8003/api/companies/"+companyID+"/roles/"+accountID, - bytes.NewReader(account.ToBytes())) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "update user in company error send request") - assert.Equal(t, http.StatusOK, resp.StatusCode, "update user in company error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) - assert.NotEmpty(t, body["content"]) - content, _ := json.Marshal(body["content"]) - return string(content) -} -func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) { - fmt.Println("Running test for RemoveUserInCompany") - req, _ := http.NewRequest( - http.MethodDelete, - "http://localhost:8003/api/companies/"+companyID+"/roles/"+accountID, - nil) - req.Header.Add("Authorization", bearerToken) - httpClient := http.Client{} - resp, err := httpClient.Do(req) - assert.NoError(t, err, "delete user in company error send request") - assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete user in company error check response") - var body map[string]interface{} - _ = json.NewDecoder(resp.Body).Decode(&body) - assert.NoError(t, resp.Body.Close()) -} -func GetChartContentWithoutTreatment(t *testing.T, route, bearerToken, companyID, repositoryID string) httpResponse.Interface { - fmt.Println("Running test for GetChartContent in route: " + route) - fmt.Println("Running test for GetChartRESTContentAndReturnBody") - now := time.Now() - initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" - finalDateStr := now.Format("2006-01-02") + "T23:59:59Z" - URL := fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/%s?initialDate=%s&finalDate=%s", companyID, route, initialDateStr, finalDateStr) - if repositoryID != "" { - URL = fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/repositories/%s/%s?initialDate=%s&finalDate=%s", companyID, repositoryID, route, initialDateStr, finalDateStr) - } - req, err := request.NewHTTPRequest().Request(http.MethodGet, URL, nil, map[string]string{"Authorization": bearerToken, "Content-type": "application/json"}) - assert.NoError(t, err) - res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) - assert.NoError(t, err) - return res -} - func InviteUserToRepository(t *testing.T, bearerToken, companyID, repositoryID string, user *accountentities.InviteUser) { fmt.Println("Running test for InviteUserToRepository") req, _ := http.NewRequest( diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index 15431b0f4..b892d6a41 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -1,8 +1,11 @@ package ldap import ( + "encoding/json" "fmt" accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles" + rolesEnum "github.com/ZupIT/horusec/development-kit/pkg/enums/account" "github.com/ZupIT/horusec/development-kit/pkg/utils/env" "github.com/ZupIT/horusec/development-kit/pkg/utils/logger" "github.com/ZupIT/horusec/e2e/server" @@ -10,7 +13,9 @@ import ( "github.com/golang-migrate/migrate/v4" _ "github.com/golang-migrate/migrate/v4/database/postgres" _ "github.com/golang-migrate/migrate/v4/source/file" + "github.com/google/uuid" "github.com/stretchr/testify/assert" + "net/http" "os" "os/exec" "strings" @@ -61,6 +66,7 @@ func TestServer(t *testing.T) { // TESTBOOK: Create, Read, Update and Delete company companyID := RunCompanyCRUD(t, bearerToken) assert.NotEmpty(t, companyID) + RunCRUDUserInCompany(t, bearerToken, companyID) }) } @@ -123,3 +129,72 @@ func RunCompanyCRUD(t *testing.T, bearerToken string) string { Name: "zup", }) } + +func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { + t.Run("Should create new user and invite to existing company with permission of the member after update your permission to admin and check if is enable view dashboard by company and remove user from company", func(t *testing.T) { + companyIDParsed, _ := uuid.Parse(companyID) + + // Add new user to invite + user := &entities.UserRepresentation{ + Username: "e2e_user_2", + Email: "e2e_2@example.com", + EmailVerified: true, + Enabled: true, + } + credential := &entities.UserRepresentationCredentials{ + Temporary: false, + Type: "password", + Value: "Ch@ng3m3", + } + responseLoginAdmin := LoginInKeycloak(t, "keycloak", "keycloak") + CreateUserInKeyCloak(t, user, credential, "Bearer " + responseLoginAdmin["access_token"].(string)) + responseLoginNewUser := LoginInKeycloak(t, user.Username, credential.Value) + bearerTokenAccount2 := responseLoginNewUser["access_token"].(string) + CreateUserFromKeycloakInHorusec(t, &accountentities.KeycloakToken{AccessToken: bearerTokenAccount2}) + + // Invite user to existing company + server.InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ + Role: rolesEnum.Member, + Email: user.Email, + CompanyID: companyIDParsed, + }) + + // Check if exist two users in company + allUsersInCompany := server.ReadAllUserInCompany(t, bearerTokenAccount1, companyID) + accountRoles := []roles.AccountRole{} + assert.NoError(t, json.Unmarshal([]byte(allUsersInCompany), &accountRoles)) + assert.NotEmpty(t, accountRoles) + assert.Equal(t, 2, len(accountRoles)) + accountID := "" + for _, user := range accountRoles { + if user.Email == user.Email { + accountID = user.AccountID.String() + } + } + assert.NotEmpty(t, accountID) + + // Check if company exists to new user + allCompanies := server.ReadAllCompanies(t, bearerTokenAccount2, true) + assert.Contains(t, allCompanies, "zup") + + // Expected return unauthorized because user is not admin of company to see dashboard in company view + responseChart := server.GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") + assert.Equal(t, http.StatusUnauthorized, responseChart.GetStatusCode()) + + // Update permission of new user to admin + server.UpdateUserInCompany(t, bearerTokenAccount1, companyID, accountID, &roles.AccountCompany{ + Role: rolesEnum.Admin, + }) + + // Expected return OK because user is authorized view dashboard in company view + responseChart = server.GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") + assert.Equal(t, http.StatusOK, responseChart.GetStatusCode()) + + // Expected remove user from company + server.RemoveUserInCompany(t, bearerTokenAccount1, companyID, accountID) + + // Not show company for user when get all companies + allCompanies = server.ReadAllCompanies(t, bearerTokenAccount2, false) + assert.NotContains(t, allCompanies, "zup") + }) +} diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go index 65f2e9cfd..956cad428 100644 --- a/e2e/server/shared_requests.go +++ b/e2e/server/shared_requests.go @@ -2,12 +2,18 @@ package server import ( "bytes" + "crypto/tls" "encoding/json" "fmt" accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account" + "github.com/ZupIT/horusec/development-kit/pkg/entities/account/roles" + "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/client" + "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/request" + httpResponse "github.com/ZupIT/horusec/development-kit/pkg/utils/http-request/response" "github.com/stretchr/testify/assert" "net/http" "testing" + "time" ) @@ -70,3 +76,87 @@ func DeleteCompany(t *testing.T, bearerToken, companyID string) { _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) } + + +func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *accountentities.InviteUser) { + fmt.Println("Running test for InviteUserToCompany") + req, _ := http.NewRequest( + http.MethodPost, + "http://127.0.0.1:8003/api/companies/"+companyID+"/roles", + bytes.NewReader(user.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "invite user error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "invite user error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} +func ReadAllUserInCompany(t *testing.T, bearerToken, companyID string) string { + fmt.Println("Running test for InviteUserToCompany") + req, _ := http.NewRequest( + http.MethodGet, + "http://127.0.0.1:8003/api/companies/"+companyID+"/roles", + nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "read all user in company error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "read all user in company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} +func UpdateUserInCompany(t *testing.T, bearerToken, companyID, accountID string, account *roles.AccountCompany) string { + fmt.Println("Running test for UpdateUserInCompany") + req, _ := http.NewRequest( + http.MethodPatch, + "http://127.0.0.1:8003/api/companies/"+companyID+"/roles/"+accountID, + bytes.NewReader(account.ToBytes())) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "update user in company error send request") + assert.Equal(t, http.StatusOK, resp.StatusCode, "update user in company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) + assert.NotEmpty(t, body["content"]) + content, _ := json.Marshal(body["content"]) + return string(content) +} +func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) { + fmt.Println("Running test for RemoveUserInCompany") + req, _ := http.NewRequest( + http.MethodDelete, + "http://127.0.0.1:8003/api/companies/"+companyID+"/roles/"+accountID, + nil) + req.Header.Add("Authorization", bearerToken) + httpClient := http.Client{} + resp, err := httpClient.Do(req) + assert.NoError(t, err, "delete user in company error send request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "delete user in company error check response") + var body map[string]interface{} + _ = json.NewDecoder(resp.Body).Decode(&body) + assert.NoError(t, resp.Body.Close()) +} +func GetChartContentWithoutTreatment(t *testing.T, route, bearerToken, companyID, repositoryID string) httpResponse.Interface { + fmt.Println("Running test for GetChartContent in route: " + route) + fmt.Println("Running test for GetChartRESTContentAndReturnBody") + now := time.Now() + initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" + finalDateStr := now.Format("2006-01-02") + "T23:59:59Z" + URL := fmt.Sprintf("http://127.0.0.1:8005/api/dashboard/companies/%s/%s?initialDate=%s&finalDate=%s", companyID, route, initialDateStr, finalDateStr) + if repositoryID != "" { + URL = fmt.Sprintf("http://127.0.0.1:8005/api/dashboard/companies/%s/repositories/%s/%s?initialDate=%s&finalDate=%s", companyID, repositoryID, route, initialDateStr, finalDateStr) + } + req, err := request.NewHTTPRequest().Request(http.MethodGet, URL, nil, map[string]string{"Authorization": bearerToken, "Content-type": "application/json"}) + assert.NoError(t, err) + res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) + assert.NoError(t, err) + return res +} From 01f021fdc9c9d0872e314cd639bb5df65419690f Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 5 Nov 2020 15:04:08 -0300 Subject: [PATCH 21/34] Fixing makefile --- Makefile | 12 ++++-------- e2e/server/keycloak/requests.go | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 15f0500dc..59baf293b 100644 --- a/Makefile +++ b/Makefile @@ -51,23 +51,19 @@ test-e2e-cli: $(GO) get -v ./horusec-cli/... $(GO) clean -testcache $(GO) test -v ./e2e/cli/scan_languages/scan_languages_test.go -timeout=5m -parallel=1 -failfast -test-e2e-server-horusec: - make compose-e2e-server-horusec +test-e2e-server-horusec: compose-e2e-server-horusec $(GO) get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/server/horusec/... -timeout=5m -parallel=1 -failfast -test-e2e-application-admin-horusec: - make compose-e2e-application-admin-horusec +test-e2e-application-admin-horusec: compose-e2e-application-admin-horusec $(GO) get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/application_admin/horusec/... -timeout=5m -parallel=1 -failfast -test-e2e-messages: - make compose-e2e-messages +test-e2e-messages: compose-e2e-messages $(GO) get -v ./e2e/... $(GO) clean -testcache $(GO) test -v ./e2e/server/messages/... -timeout=5m -parallel=1 -failfast -test-e2e-server-keycloak: - make compose-e2e-server-keycloak +test-e2e-server-keycloak: compose-e2e-server-keycloak $(GO) get -v ./e2e/... $(GO) clean -testcache sleep 3 && $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go index b1670b2ea..563f3e477 100644 --- a/e2e/server/keycloak/requests.go +++ b/e2e/server/keycloak/requests.go @@ -128,6 +128,7 @@ func GetClientSecretInAccountClient(t *testing.T, bearerToken string) string { } func UpdateRolesToAcceptOAuth(t *testing.T, bearerToken string) { + fmt.Println("Running test for UpdateRolesToAcceptOAuth") allClients := ListAllClientsInKeycloak(t, bearerToken) var client map[string]interface{} for _, actualClient := range allClients { From fa37576128d8586dceceae12124dff1b1d738954 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 5 Nov 2020 15:15:35 -0300 Subject: [PATCH 22/34] Fixing names and docs of e2e --- e2e/TESTBOOK.md | 5 ----- e2e/application_admin/horusec/http_test.go | 2 ++ e2e/application_admin/horusec/requests.go | 1 + e2e/application_admin/keycloak/http_test.go | 2 ++ e2e/application_admin/ldap/http_test.go | 2 ++ e2e/cli/scan_languages/scan_languages_test.go | 2 ++ e2e/server/horusec/http_test.go | 2 ++ e2e/server/horusec/requests.go | 1 + e2e/server/keycloak/entities/user_representation.go | 1 + e2e/server/keycloak/http_test.go | 4 +++- e2e/server/keycloak/requests.go | 3 ++- e2e/server/ldap/http_test.go | 2 ++ e2e/server/messages/messages_test.go | 2 ++ e2e/server/messages/requests.go | 1 + e2e/server/shared_requests.go | 2 +- 15 files changed, 24 insertions(+), 8 deletions(-) diff --git a/e2e/TESTBOOK.md b/e2e/TESTBOOK.md index 68dd38293..22d43c9c9 100644 --- a/e2e/TESTBOOK.md +++ b/e2e/TESTBOOK.md @@ -55,23 +55,18 @@ - [ ] Create account - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type - [ ] Login - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type - [ ] Logout - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type - [ ] Authorize - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type - [ ] Create, Read, Update and Delete company - [X] Horusec auth type - [ ] Ldap auth type - - [ ] Keycloak auth type ## Horusec CLI - [ ] Setup log level diff --git a/e2e/application_admin/horusec/http_test.go b/e2e/application_admin/horusec/http_test.go index ddd8c22c9..0af5cf991 100644 --- a/e2e/application_admin/horusec/http_test.go +++ b/e2e/application_admin/horusec/http_test.go @@ -1,3 +1,5 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-application-admin-horusec package horusec import ( diff --git a/e2e/application_admin/horusec/requests.go b/e2e/application_admin/horusec/requests.go index d795df9c5..7f0388e64 100644 --- a/e2e/application_admin/horusec/requests.go +++ b/e2e/application_admin/horusec/requests.go @@ -1,3 +1,4 @@ +// Requests save in this file are exclusive of horusec e2e package horusec import ( diff --git a/e2e/application_admin/keycloak/http_test.go b/e2e/application_admin/keycloak/http_test.go index c9405cca8..59863d67f 100644 --- a/e2e/application_admin/keycloak/http_test.go +++ b/e2e/application_admin/keycloak/http_test.go @@ -1 +1,3 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-application-admin-keycloak package ldap diff --git a/e2e/application_admin/ldap/http_test.go b/e2e/application_admin/ldap/http_test.go index c9405cca8..c8367d5da 100644 --- a/e2e/application_admin/ldap/http_test.go +++ b/e2e/application_admin/ldap/http_test.go @@ -1 +1,3 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-application-admin-ldap package ldap diff --git a/e2e/cli/scan_languages/scan_languages_test.go b/e2e/cli/scan_languages/scan_languages_test.go index cd7a0e074..63d3a9307 100644 --- a/e2e/cli/scan_languages/scan_languages_test.go +++ b/e2e/cli/scan_languages/scan_languages_test.go @@ -1,3 +1,5 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-cli package scan_languages import ( diff --git a/e2e/server/horusec/http_test.go b/e2e/server/horusec/http_test.go index d0bb1f18f..9d234f6b3 100644 --- a/e2e/server/horusec/http_test.go +++ b/e2e/server/horusec/http_test.go @@ -1,3 +1,5 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-server-horusec package horusec import ( diff --git a/e2e/server/horusec/requests.go b/e2e/server/horusec/requests.go index 636bac7f2..77cbd45fd 100644 --- a/e2e/server/horusec/requests.go +++ b/e2e/server/horusec/requests.go @@ -1,3 +1,4 @@ +// Requests save in this file are exclusive of horusec e2e package horusec import ( diff --git a/e2e/server/keycloak/entities/user_representation.go b/e2e/server/keycloak/entities/user_representation.go index a4edf1bdf..55f5bb02c 100644 --- a/e2e/server/keycloak/entities/user_representation.go +++ b/e2e/server/keycloak/entities/user_representation.go @@ -1,3 +1,4 @@ +// Entities created in this files are exclusive from keycloak e2e package entities import "encoding/json" diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index b892d6a41..abad97815 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -1,4 +1,6 @@ -package ldap +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-server-keycloak +package keycloak import ( "encoding/json" diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go index 563f3e477..d9957504d 100644 --- a/e2e/server/keycloak/requests.go +++ b/e2e/server/keycloak/requests.go @@ -1,4 +1,5 @@ -package ldap +// Requests save in this file are exclusive of keycloak e2e +package keycloak import ( "bytes" diff --git a/e2e/server/ldap/http_test.go b/e2e/server/ldap/http_test.go index c9405cca8..fc363d573 100644 --- a/e2e/server/ldap/http_test.go +++ b/e2e/server/ldap/http_test.go @@ -1 +1,3 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-server-ldap package ldap diff --git a/e2e/server/messages/messages_test.go b/e2e/server/messages/messages_test.go index c6f2a3f6e..3c6c8de43 100644 --- a/e2e/server/messages/messages_test.go +++ b/e2e/server/messages/messages_test.go @@ -1,3 +1,5 @@ +// Test e2e refers workflow: .github/workflows/e2e.yml +// In step: e2e-messages package messages import ( diff --git a/e2e/server/messages/requests.go b/e2e/server/messages/requests.go index 796a3cf92..a71a4b907 100644 --- a/e2e/server/messages/requests.go +++ b/e2e/server/messages/requests.go @@ -1,3 +1,4 @@ +// Requests save in this file are exclusive of messages e2e package messages import ( diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go index 956cad428..c4098cdea 100644 --- a/e2e/server/shared_requests.go +++ b/e2e/server/shared_requests.go @@ -1,3 +1,4 @@ +// Requests save in this file are shared into all server e2e. package server import ( @@ -16,7 +17,6 @@ import ( "time" ) - func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { fmt.Println("Running test for CreateCompany") req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/companies", bytes.NewReader(company.ToBytes())) From 5ea71594efe248633a473e3df4464d5048ec89ee Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Thu, 5 Nov 2020 15:43:03 -0300 Subject: [PATCH 23/34] Removing trash of tests of analysis --- horusec-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/horusec-config.json b/horusec-config.json index 5d10c6dfc..d1060a362 100644 --- a/horusec-config.json +++ b/horusec-config.json @@ -7,7 +7,7 @@ "horusecCliPrintOutputType": "text", "horusecCliJsonOutputFilepath": "", "horusecCliTypesOfVulnerabilitiesToIgnore": "", - "horusecCliFilesOrPathsToIgnore": "**/e2e/**, **/examples/**, **/*.toml, **/*_test.go, **/*_mock.go, **/*README.md, **/development-kit/pkg/enums/engine/advisories/**, **/horusec-lp/.cache/**, **/horusec-lp/public/**, **/deployments/docker-compose*", + "horusecCliFilesOrPathsToIgnore": "**/e2e/**, **/examples/**, **/*.toml, **/*_test.go, **/*_mock.go, **/*README.md, **/development-kit/pkg/enums/engine/advisories/**, **/horusec-lp/.cache/**, **/horusec-lp/public/**, **/deployments/docker-compose*, **/horusec-cli/cmd/horusec/start/analysis/*", "horusecCliReturnErrorIfFoundVulnerability": false, "horusecCliProjectPath": "./", "horusecCliFalsePositiveHashes": "e2eaa19612eed0124b1fec396f8d41381c618c677c2025fc07c1cd0ccbe92b3c, 2b156198552b17c44bab579d68b8cb4204789859ef69a37a7a11e65667cbc66f, 2ce87bddc40e085562618f441750eeefe3cffc79d0b05b2e07a98f644c55b2c5", From 62173d1753ad38a2dad4311080d150295c18696a Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 09:01:33 -0300 Subject: [PATCH 24/34] Fixing e2e --- e2e/application_admin/horusec/http_test.go | 12 ++--- e2e/application_admin/horusec/requests.go | 14 ++--- e2e/server/horusec/http_test.go | 2 +- e2e/server/horusec/requests.go | 54 +++++++++---------- .../keycloak/entities/user_representation.go | 14 ++--- e2e/server/keycloak/http_test.go | 2 +- e2e/server/keycloak/requests.go | 7 ++- e2e/server/messages/messages_test.go | 8 +-- e2e/server/messages/requests.go | 18 +++---- e2e/server/shared_requests.go | 1 - go.sum | 11 ++++ 11 files changed, 76 insertions(+), 67 deletions(-) diff --git a/e2e/application_admin/horusec/http_test.go b/e2e/application_admin/horusec/http_test.go index 0af5cf991..26d2fa922 100644 --- a/e2e/application_admin/horusec/http_test.go +++ b/e2e/application_admin/horusec/http_test.go @@ -19,7 +19,7 @@ import ( func TestMain(m *testing.M) { folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" - connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable") migration, err := migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create first instance migration: ", err) @@ -45,7 +45,7 @@ func TestMain(m *testing.M) { } output, err := exec.Command("docker", "restart", "horusec-auth").Output() if err != nil { - logger.LogPanic("Error restart auth service: " + string(output), err) + logger.LogPanic("Error restart auth service: "+string(output), err) } time.Sleep(3 * time.Second) code := m.Run() @@ -66,8 +66,8 @@ func TestServer(t *testing.T) { // create company and add to logged user companyID := CreateCompanyApplicationAdmin(t, bearerToken, &accountentities.CompanyApplicationAdmin{ - Name: "zup", - AdminEmail: "horusec-admin@example.com", + Name: "zup", + AdminEmail: "horusec-admin@example.com", }) // check if company show to logged user allCompanies := ReadAllCompanies(t, bearerToken, true) @@ -90,8 +90,8 @@ func TestServer(t *testing.T) { }) // Create new company to new user in system _ = CreateCompanyApplicationAdmin(t, bearerToken, &accountentities.CompanyApplicationAdmin{ - Name: "zup", - AdminEmail: "e2e@example.com", + Name: "zup", + AdminEmail: "e2e@example.com", }) // Not can possible show company to first user allCompanies = ReadAllCompanies(t, bearerToken, false) diff --git a/e2e/application_admin/horusec/requests.go b/e2e/application_admin/horusec/requests.go index 7f0388e64..239273dc0 100644 --- a/e2e/application_admin/horusec/requests.go +++ b/e2e/application_admin/horusec/requests.go @@ -13,7 +13,7 @@ import ( func CreateAccount(t *testing.T, account *accountentities.Account) { fmt.Println("Running test for CreateAccount") - createAccountResp, err := http.Post("http://localhost:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) + createAccountResp, err := http.Post("http://127.0.0.1:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) assert.NoError(t, err, "create account error mount request") assert.Equal(t, http.StatusCreated, createAccountResp.StatusCode, "create account error send request") @@ -26,7 +26,7 @@ func CreateAccount(t *testing.T, account *accountentities.Account) { func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string { fmt.Println("Running test for Login") loginResp, err := http.Post( - "http://localhost:8003/api/account/login", + "http://127.0.0.1:8003/api/account/login", "text/json", bytes.NewReader(credentials.ToBytes()), ) @@ -41,7 +41,7 @@ func Login(t *testing.T, credentials *accountentities.LoginData) map[string]stri func Logout(t *testing.T, bearerToken string) { fmt.Println("Running test for Logout") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/account/logout", nil) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/account/logout", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -56,7 +56,7 @@ func Logout(t *testing.T, bearerToken string) { func CreateCompanyApplicationAdmin(t *testing.T, bearerToken string, company *accountentities.CompanyApplicationAdmin) (CompanyID string) { companyBytes, _ := json.Marshal(company) fmt.Println("Running test for CreateCompany") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(companyBytes)) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/companies", bytes.NewReader(companyBytes)) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} createCompanyResp, err := httpClient.Do(req) @@ -71,7 +71,7 @@ func CreateCompanyApplicationAdmin(t *testing.T, bearerToken string, company *ac func UpdateCompany(t *testing.T, bearerToken string, companyID string, company *accountentities.Company) { fmt.Println("Running test for UpdateCompany") - req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) + req, _ := http.NewRequest(http.MethodPatch, "http://127.0.0.1:8003/api/companies/"+companyID, bytes.NewReader(company.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -85,7 +85,7 @@ func UpdateCompany(t *testing.T, bearerToken string, companyID string, company * func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) string { fmt.Println("Running test for ReadAllCompanies") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8003/api/companies", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -103,7 +103,7 @@ func ReadAllCompanies(t *testing.T, bearerToken string, isCheckBodyEmpty bool) s func DeleteCompany(t *testing.T, bearerToken, companyID string) { fmt.Println("Running test for DeleteCompany") - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8003/api/companies/"+companyID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) diff --git a/e2e/server/horusec/http_test.go b/e2e/server/horusec/http_test.go index 9d234f6b3..d797c37ec 100644 --- a/e2e/server/horusec/http_test.go +++ b/e2e/server/horusec/http_test.go @@ -29,7 +29,7 @@ import ( func TestMain(m *testing.M) { folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" - connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable") migration, err := migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create first instance migration: ", err) diff --git a/e2e/server/horusec/requests.go b/e2e/server/horusec/requests.go index 77cbd45fd..4ce509ce6 100644 --- a/e2e/server/horusec/requests.go +++ b/e2e/server/horusec/requests.go @@ -22,7 +22,7 @@ import ( func CreateAccount(t *testing.T, account *accountentities.Account) { fmt.Println("Running test for CreateAccount") - createAccountResp, err := http.Post("http://localhost:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) + createAccountResp, err := http.Post("http://127.0.0.1:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) assert.NoError(t, err, "create account error mount request") assert.Equal(t, http.StatusCreated, createAccountResp.StatusCode, "create account error send request") @@ -35,7 +35,7 @@ func CreateAccount(t *testing.T, account *accountentities.Account) { func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string { fmt.Println("Running test for Login") loginResp, err := http.Post( - "http://localhost:8003/api/account/login", + "http://127.0.0.1:8003/api/account/login", "text/json", bytes.NewReader(credentials.ToBytes()), ) @@ -50,7 +50,7 @@ func Login(t *testing.T, credentials *accountentities.LoginData) map[string]stri func Logout(t *testing.T, bearerToken string) { fmt.Println("Running test for Logout") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/account/logout", nil) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/account/logout", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -65,7 +65,7 @@ func Logout(t *testing.T, bearerToken string) { func CreateRepository(t *testing.T, bearerToken, companyID string, repository *accountentities.Repository) string { repositoryBytes, _ := json.Marshal(repository) fmt.Println("Running test for CreateRepository") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies/"+companyID+"/repositories", bytes.NewReader(repositoryBytes)) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories", bytes.NewReader(repositoryBytes)) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -82,7 +82,7 @@ func UpdateRepository(t *testing.T, bearerToken, companyID, repositoryID string, fmt.Println("Running test for UpdateRepository") repositoryBytes, _ := json.Marshal(repository) fmt.Println("Running test for UpdateRepository") - req, _ := http.NewRequest(http.MethodPatch, "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID, bytes.NewReader(repositoryBytes)) + req, _ := http.NewRequest(http.MethodPatch, "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories/"+repositoryID, bytes.NewReader(repositoryBytes)) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -95,7 +95,7 @@ func UpdateRepository(t *testing.T, bearerToken, companyID, repositoryID string, func ReadAllRepositories(t *testing.T, bearerToken, companyID string, isCheckBodyEmpty bool) string { fmt.Println("Running test for ReadAllRepositories") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8003/api/companies/"+companyID+"/repositories", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -113,7 +113,7 @@ func ReadAllRepositories(t *testing.T, bearerToken, companyID string, isCheckBod func DeleteRepository(t *testing.T, bearerToken, companyID, repositoryID string) { fmt.Println("Running test for DeleteRepository") - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories/"+repositoryID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -128,7 +128,7 @@ func GenerateRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID fmt.Println("Running test for GenerateRepositoryToken") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", + "http://127.0.0.1:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", bytes.NewReader(token.ToBytes()), ) req.Header.Add("Authorization", bearerToken) @@ -146,7 +146,7 @@ func GenerateRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID func ReadAllRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID string) string { fmt.Println("Running test for ReadAllRepositoryToken") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -161,7 +161,7 @@ func ReadAllRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID s } func ReadAllRepositoryTokenWithoutTreatment(t *testing.T, bearerToken, companyID, repositoryID string) httpResponse.Interface { fmt.Println("Running test for ReadAllRepositoryToken") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens", nil) req.Header.Add("Authorization", bearerToken) res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) assert.NoError(t, err) @@ -169,7 +169,7 @@ func ReadAllRepositoryTokenWithoutTreatment(t *testing.T, bearerToken, companyID } func RevokeRepositoryToken(t *testing.T, bearerToken, companyID, repositoryID, tokenID string) { fmt.Println("Running test for RevokeRepositoryToken") - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens/"+tokenID, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/tokens/"+tokenID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -184,7 +184,7 @@ func GenerateCompanyToken(t *testing.T, bearerToken, companyID string, token api fmt.Println("Running test for GenerateCompanyToken") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8000/api/companies/"+companyID+"/tokens", + "http://127.0.0.1:8000/api/companies/"+companyID+"/tokens", bytes.NewReader(token.ToBytes()), ) req.Header.Add("Authorization", bearerToken) @@ -202,7 +202,7 @@ func GenerateCompanyToken(t *testing.T, bearerToken, companyID string, token api func ReadAllCompanyToken(t *testing.T, bearerToken, companyID string) string { fmt.Println("Running test for ReadAllCompanyToken") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/tokens", nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/api/companies/"+companyID+"/tokens", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -218,7 +218,7 @@ func ReadAllCompanyToken(t *testing.T, bearerToken, companyID string) string { func RevokeCompanyToken(t *testing.T, bearerToken, companyID, tokenID string) { fmt.Println("Running test for RevokeCompanyToken") - req, _ := http.NewRequest(http.MethodDelete, "http://localhost:8000/api/companies/"+companyID+"/tokens/"+tokenID, nil) + req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8000/api/companies/"+companyID+"/tokens/"+tokenID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -233,7 +233,7 @@ func InsertAnalysisWithRepositoryToken(t *testing.T, analysisData *api.AnalysisD fmt.Println("Running test for InsertAnalysisWithRepositoryToken") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8000/api/analysis", + "http://127.0.0.1:8000/api/analysis", bytes.NewReader(analysisData.ToBytes()), ) req.Header.Add("Authorization", repositoryToken) @@ -253,7 +253,7 @@ func InsertAnalysisWithCompanyToken(t *testing.T, analysisData *api.AnalysisData fmt.Println("Running test for InsertAnalysisWithRepositoryToken") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8000/api/analysis", + "http://127.0.0.1:8000/api/analysis", bytes.NewReader(analysisData.ToBytes()), ) req.Header.Add("Authorization", companyToken) @@ -271,7 +271,7 @@ func InsertAnalysisWithCompanyToken(t *testing.T, analysisData *api.AnalysisData func GetAnalysisByID(t *testing.T, analysisID, authorization string) string { fmt.Println("Running test for GetAnalysisByID") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/analysis/"+analysisID, nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/api/analysis/"+analysisID, nil) req.Header.Add("Authorization", authorization) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -291,9 +291,9 @@ func GetChartContent(t *testing.T, route, bearerToken, companyID, repositoryID s now := time.Now() initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" finalDateStr := now.Format("2006-01-02") + "T23:59:59Z" - URL := fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/%s?initialDate=%s&finalDate=%s", companyID, route, initialDateStr, finalDateStr) + URL := fmt.Sprintf("http://127.0.0.1:8005/api/dashboard/companies/%s/%s?initialDate=%s&finalDate=%s", companyID, route, initialDateStr, finalDateStr) if repositoryID != "" { - URL = fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/repositories/%s/%s?initialDate=%s&finalDate=%s", companyID, repositoryID, route, initialDateStr, finalDateStr) + URL = fmt.Sprintf("http://127.0.0.1:8005/api/dashboard/companies/%s/repositories/%s/%s?initialDate=%s&finalDate=%s", companyID, repositoryID, route, initialDateStr, finalDateStr) } req, err := request.NewHTTPRequest().Request(http.MethodGet, URL, nil, map[string]string{"Authorization": bearerToken, "Content-type": "application/json"}) assert.NoError(t, err) @@ -342,9 +342,9 @@ func GetChartDetailsUsingGraphQLAndReturnBody(t *testing.T, bearerToken, company queryGraphQL = strings.ReplaceAll(queryGraphQL, "\n", "%20") queryGraphQL = strings.ReplaceAll(queryGraphQL, "\t", "%20") queryGraphQL = strings.ReplaceAll(queryGraphQL, " ", "%20") - URL := fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/details?query=%s&page=1&size=1000", companyID, queryGraphQL) + URL := fmt.Sprintf("http://127.0.0.1:8005/api/dashboard/companies/%s/details?query=%s&page=1&size=1000", companyID, queryGraphQL) if repositoryID != "" { - URL = fmt.Sprintf("http://localhost:8005/api/dashboard/companies/%s/repositories/%s/details?query=%s&page=1&size=1000", companyID, repositoryID, queryGraphQL) + URL = fmt.Sprintf("http://127.0.0.1:8005/api/dashboard/companies/%s/repositories/%s/details?query=%s&page=1&size=1000", companyID, repositoryID, queryGraphQL) } req, err := request.NewHTTPRequest().Request(http.MethodGet, URL, nil, map[string]string{"Authorization": bearerToken, "Content-Type": "application/json"}) assert.NoError(t, err) @@ -358,7 +358,7 @@ func GetChartDetailsUsingGraphQLAndReturnBody(t *testing.T, bearerToken, company func GetAllVulnerabilitiesToManager(t *testing.T, bearerToken, companyID, repositoryID string, queryString string) string { fmt.Println("Running test for GetAllVulnerabilitiesToManager") - req, _ := http.NewRequest(http.MethodGet, "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management?"+queryString, nil) + req, _ := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management?"+queryString, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -376,7 +376,7 @@ func UpdateVulnerabilitiesType(t *testing.T, bearerToken, companyID, repositoryI fmt.Println("Running test for UpdateVulnerabilitiesType") req, _ := http.NewRequest( http.MethodPut, - "http://localhost:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management/"+vulnerabilityID+"/type", + "http://127.0.0.1:8000/api/companies/"+companyID+"/repositories/"+repositoryID+"/management/"+vulnerabilityID+"/type", bytes.NewReader(vulnType.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -394,7 +394,7 @@ func InviteUserToRepository(t *testing.T, bearerToken, companyID, repositoryID s fmt.Println("Running test for InviteUserToRepository") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles", + "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles", bytes.NewReader(user.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -409,7 +409,7 @@ func ReadAllUserInRepository(t *testing.T, bearerToken, companyID, repositoryID fmt.Println("Running test for InviteUserToCompany") req, _ := http.NewRequest( http.MethodGet, - "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles", + "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -427,7 +427,7 @@ func UpdateUserInRepository(t *testing.T, bearerToken, companyID, repositoryID, fmt.Println("Running test for UpdateUserInRepository") req, _ := http.NewRequest( http.MethodPatch, - "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles/"+accountID, + "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles/"+accountID, bytes.NewReader(account.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -442,7 +442,7 @@ func RemoveUserInRepository(t *testing.T, bearerToken, companyID, repositoryID, fmt.Println("Running test for RemoveUserInRepository") req, _ := http.NewRequest( http.MethodDelete, - "http://localhost:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles/"+accountID, + "http://127.0.0.1:8003/api/companies/"+companyID+"/repositories/"+repositoryID+"/roles/"+accountID, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} diff --git a/e2e/server/keycloak/entities/user_representation.go b/e2e/server/keycloak/entities/user_representation.go index 55f5bb02c..fe80591ed 100644 --- a/e2e/server/keycloak/entities/user_representation.go +++ b/e2e/server/keycloak/entities/user_representation.go @@ -4,16 +4,16 @@ package entities import "encoding/json" type UserRepresentation struct { - Username string `json:"username"` - Email string `json:"email"` - EmailVerified bool `json:"emailVerified"` - Enabled bool `json:"enabled"` + Username string `json:"username"` + Email string `json:"email"` + EmailVerified bool `json:"emailVerified"` + Enabled bool `json:"enabled"` } type UserRepresentationCredentials struct { - Temporary bool `json:"temporary"` - Type string `json:"type"` - Value string `json:"value"` + Temporary bool `json:"temporary"` + Type string `json:"type"` + Value string `json:"value"` } func (u *UserRepresentation) ToBytes() []byte { diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index abad97815..bd0f2628d 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -149,7 +149,7 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { Value: "Ch@ng3m3", } responseLoginAdmin := LoginInKeycloak(t, "keycloak", "keycloak") - CreateUserInKeyCloak(t, user, credential, "Bearer " + responseLoginAdmin["access_token"].(string)) + CreateUserInKeyCloak(t, user, credential, "Bearer "+responseLoginAdmin["access_token"].(string)) responseLoginNewUser := LoginInKeycloak(t, user.Username, credential.Value) bearerTokenAccount2 := responseLoginNewUser["access_token"].(string) CreateUserFromKeycloakInHorusec(t, &accountentities.KeycloakToken{AccessToken: bearerTokenAccount2}) diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go index d9957504d..f3db22c3c 100644 --- a/e2e/server/keycloak/requests.go +++ b/e2e/server/keycloak/requests.go @@ -13,7 +13,6 @@ import ( "testing" ) - func LoginInKeycloak(t *testing.T, username, password string) map[string]interface{} { fmt.Println("Running test for LoginInKeycloak in Keycloak") payload := strings.NewReader(fmt.Sprintf("client_id=admin-cli&username=%s&password=%s&grant_type=password", username, password)) @@ -94,14 +93,14 @@ func DeleteAllUsersInKeyCloak(t *testing.T, bearerToken string) { idsToRemove = append(idsToRemove, user["id"].(string)) } } - assert.Equal(t, len(allUsers) - 1, len(idsToRemove)) + assert.Equal(t, len(allUsers)-1, len(idsToRemove)) for _, id := range idsToRemove { req, _ := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8080/auth/admin/realms/master/users/"+id, nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) - assert.NoError(t, err, "DeleteAllUsersInKeyCloak: remove user of id: " +id+ " error mount request") - assert.Equal(t, http.StatusNoContent, resp.StatusCode, "DeleteAllUsersInKeyCloak: remove user of id: " +id+ " error send request") + assert.NoError(t, err, "DeleteAllUsersInKeyCloak: remove user of id: "+id+" error mount request") + assert.Equal(t, http.StatusNoContent, resp.StatusCode, "DeleteAllUsersInKeyCloak: remove user of id: "+id+" error send request") } } diff --git a/e2e/server/messages/messages_test.go b/e2e/server/messages/messages_test.go index 3c6c8de43..b415b7a8f 100644 --- a/e2e/server/messages/messages_test.go +++ b/e2e/server/messages/messages_test.go @@ -21,7 +21,7 @@ import ( func TestMain(m *testing.M) { folderOfMigration := "file://../../../development-kit/pkg/databases/relational/migration" - connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@localhost:5432/horusec_db?sslmode=disable") + connectionStringDB := env.GetEnvOrDefault("HORUSEC_DATABASE_SQL_URI", "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable") migration, err := migrate.New(folderOfMigration, connectionStringDB) if err != nil { logger.LogPanic("Error in create first instance migration: ", err) @@ -64,7 +64,7 @@ func TestMessages(t *testing.T) { // When try login without confirm account return unauthorized loginResp := Login(t, &accountentities.LoginData{ - Email: "e2e@example.com", + Email: "e2e@example.com", Password: "Ch@ng3m3", }) assert.Equal(t, http.StatusForbidden, loginResp.GetStatusCode()) @@ -77,7 +77,7 @@ func TestMessages(t *testing.T) { // Check if is possible login now bearerToken := LoginAndReturnAccessToken(t, &accountentities.LoginData{ - Email: "e2e@example.com", + Email: "e2e@example.com", Password: "Ch@ng3m3", }) Logout(t, bearerToken) @@ -91,4 +91,4 @@ func GetLastAccountCreated(t *testing.T) (accountCreated accountentities.Account assert.NotEmpty(t, accountCreated) assert.NotEqual(t, accountCreated.AccountID, uuid.Nil) return accountCreated -} \ No newline at end of file +} diff --git a/e2e/server/messages/requests.go b/e2e/server/messages/requests.go index a71a4b907..600163a02 100644 --- a/e2e/server/messages/requests.go +++ b/e2e/server/messages/requests.go @@ -17,7 +17,7 @@ import ( func CreateAccount(t *testing.T, account *accountentities.Account) { fmt.Println("Running test for CreateAccount") - createAccountResp, err := http.Post("http://localhost:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) + createAccountResp, err := http.Post("http://127.0.0.1:8003/api/account/create-account", "text/json", bytes.NewReader(account.ToBytes())) assert.NoError(t, err, "create account error mount request") assert.Equal(t, http.StatusCreated, createAccountResp.StatusCode, "create account error send request") @@ -31,7 +31,7 @@ func Login(t *testing.T, credentials *accountentities.LoginData) httpResponse.In fmt.Println("Running test for Login") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8003/api/account/login", + "http://127.0.0.1:8003/api/account/login", bytes.NewReader(credentials.ToBytes())) res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) assert.NoError(t, err) @@ -40,7 +40,7 @@ func Login(t *testing.T, credentials *accountentities.LoginData) httpResponse.In func LoginAndReturnAccessToken(t *testing.T, credentials *accountentities.LoginData) string { fmt.Println("Running test for Login") loginResp, err := http.Post( - "http://localhost:8003/api/account/login", + "http://127.0.0.1:8003/api/account/login", "text/json", bytes.NewReader(credentials.ToBytes()), ) @@ -56,11 +56,11 @@ func ValidateAccount(t *testing.T, accountID string) { fmt.Println("Running test for ValidateAccount") req, _ := http.NewRequest( http.MethodGet, - "http://localhost:8003/api/account/validate/"+accountID, + "http://127.0.0.1:8003/api/account/validate/"+accountID, nil) res, err := client.NewHTTPClient(15).DoRequest(req, &tls.Config{}) if err != nil { - if !strings.Contains(err.Error(), "Get \"http://localhost:8043\": ") { + if !strings.Contains(err.Error(), "Get \"http://127.0.0.1:8043\": ") { assert.NoError(t, err) } } else { @@ -70,7 +70,7 @@ func ValidateAccount(t *testing.T, accountID string) { func Logout(t *testing.T, bearerToken string) { fmt.Println("Running test for Logout") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/account/logout", nil) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/account/logout", nil) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} resp, err := httpClient.Do(req) @@ -84,7 +84,7 @@ func Logout(t *testing.T, bearerToken string) { func CreateCompany(t *testing.T, bearerToken string, company *accountentities.Company) (CompanyID string) { fmt.Println("Running test for CreateCompany") - req, _ := http.NewRequest(http.MethodPost, "http://localhost:8003/api/companies", bytes.NewReader(company.ToBytes())) + req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8003/api/companies", bytes.NewReader(company.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} createCompanyResp, err := httpClient.Do(req) @@ -101,7 +101,7 @@ func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *acco fmt.Println("Running test for InviteUserToCompany") req, _ := http.NewRequest( http.MethodPost, - "http://localhost:8003/api/companies/"+companyID+"/roles", + "http://127.0.0.1:8003/api/companies/"+companyID+"/roles", bytes.NewReader(user.ToBytes())) req.Header.Add("Authorization", bearerToken) httpClient := http.Client{} @@ -111,4 +111,4 @@ func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *acco var body map[string]interface{} _ = json.NewDecoder(resp.Body).Decode(&body) assert.NoError(t, resp.Body.Close()) -} \ No newline at end of file +} diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go index c4098cdea..9711b2cb8 100644 --- a/e2e/server/shared_requests.go +++ b/e2e/server/shared_requests.go @@ -77,7 +77,6 @@ func DeleteCompany(t *testing.T, bearerToken, companyID string) { assert.NoError(t, resp.Body.Close()) } - func InviteUserToCompany(t *testing.T, bearerToken, companyID string, user *accountentities.InviteUser) { fmt.Println("Running test for InviteUserToCompany") req, _ := http.NewRequest( diff --git a/go.sum b/go.sum index 3544dc571..81c1de88f 100644 --- a/go.sum +++ b/go.sum @@ -645,6 +645,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b/go.mod h1:T3BPAOm2cqquPa0MKWeNkmOM5RQsRhkrwMWonFMN7fE= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -755,6 +756,9 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201029055024-942e2f445f3c h1:rpcgRPA7OvNEOdprt2Wx8/Re2cBTd8NPo/lvo3AyMqk= +golang.org/x/net v0.0.0-20201029055024-942e2f445f3c/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -771,6 +775,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -821,12 +826,16 @@ golang.org/x/sys v0.0.0-20200817155316-9781c653f443/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 h1:HlFl4V6pEMziuLXyRkm5BIYq1y1GAbb02pRlWvI54OM= +golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -890,6 +899,8 @@ golang.org/x/tools v0.0.0-20200817023811-d00afeaade8f/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200818005847-188abfa75333/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200820010801-b793a1359eac h1:DugppSxw0LSF8lcjaODPJZoDzq0ElTGskTst3ZaBkHI= golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20201029182919-e7a17c4c1366 h1:a6x10n1HsMdTywBbnrJhO8r8pa7rnbl8TvRfCUd16Jw= +golang.org/x/tools v0.0.0-20201029182919-e7a17c4c1366/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 9698177e62adc3c40bfe5e4eec662d2c7a5e602a Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 09:35:38 -0300 Subject: [PATCH 25/34] Fixing e2e messages --- .../docker-compose.application-admin.horusec.yaml | 1 - e2e/deployments/docker-compose.server.messages.yaml | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/e2e/deployments/docker-compose.application-admin.horusec.yaml b/e2e/deployments/docker-compose.application-admin.horusec.yaml index 7ca82cefb..473a7c5e0 100644 --- a/e2e/deployments/docker-compose.application-admin.horusec.yaml +++ b/e2e/deployments/docker-compose.application-admin.horusec.yaml @@ -5,7 +5,6 @@ services: image: postgres:12 ports: - "5432:5432" - network_mode: "host" environment: POSTGRES_PASSWORD: root POSTGRES_USER: root diff --git a/e2e/deployments/docker-compose.server.messages.yaml b/e2e/deployments/docker-compose.server.messages.yaml index 782ddace4..97e9d3a26 100644 --- a/e2e/deployments/docker-compose.server.messages.yaml +++ b/e2e/deployments/docker-compose.server.messages.yaml @@ -5,7 +5,6 @@ services: image: postgres:12 ports: - "5432:5432" - network_mode: "host" environment: POSTGRES_PASSWORD: root POSTGRES_USER: root @@ -23,7 +22,6 @@ services: ports: - "5672:5672" - "15672:15672" - network_mode: "host" horusec-messages: build: context: ../../ @@ -36,7 +34,7 @@ services: - "8004:8004" network_mode: "host" environment: - HORUSEC_BROKER_HOST: rabbit + HORUSEC_BROKER_HOST: "127.0.0.1" HORUSEC_BROKER_PORT: "5672" HORUSEC_BROKER_USERNAME: "guest" HORUSEC_BROKER_PASSWORD: "guest" @@ -60,7 +58,7 @@ services: network_mode: "host" environment: HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "false" - HORUSEC_BROKER_HOST: rabbit + HORUSEC_BROKER_HOST: "127.0.0.1" HORUSEC_BROKER_PORT: "5672" HORUSEC_BROKER_USERNAME: "guest" HORUSEC_BROKER_PASSWORD: "guest" @@ -68,6 +66,7 @@ services: HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_MANAGER_URL: "http://127.0.0.1:8043" horusec-auth: build: context: ../../ From 451020869c13e521be1684e3738d3d755b60ebe0 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 10:18:49 -0300 Subject: [PATCH 26/34] Fixing create company --- .../internal/controller/companies/companies.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/horusec-account/internal/controller/companies/companies.go b/horusec-account/internal/controller/companies/companies.go index 3692cfa69..1682a455e 100644 --- a/horusec-account/internal/controller/companies/companies.go +++ b/horusec-account/internal/controller/companies/companies.go @@ -78,14 +78,14 @@ func (c *Controller) Create(accountID uuid.UUID, data *accountEntities.Company) if err != nil { return nil, err } - if err = c.repoAccountCompany.CreateAccountCompany( newCompany.CompanyID, accountID, accountEnums.Admin, tx); err != nil { - return nil, tx.RollbackTransaction().GetError() + if errTx := tx.RollbackTransaction().GetError(); errTx != nil { + return nil, errTx + } + return nil, err } - tx.CommitTransaction() - return newCompany, nil } From d64e4b596090f25d32896a8f6fa594f54c9d2104 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 10:20:03 -0300 Subject: [PATCH 27/34] Fixing create company --- horusec-account/internal/controller/companies/companies.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/horusec-account/internal/controller/companies/companies.go b/horusec-account/internal/controller/companies/companies.go index 1682a455e..f89ea84da 100644 --- a/horusec-account/internal/controller/companies/companies.go +++ b/horusec-account/internal/controller/companies/companies.go @@ -80,12 +80,10 @@ func (c *Controller) Create(accountID uuid.UUID, data *accountEntities.Company) } if err = c.repoAccountCompany.CreateAccountCompany( newCompany.CompanyID, accountID, accountEnums.Admin, tx); err != nil { - if errTx := tx.RollbackTransaction().GetError(); errTx != nil { - return nil, errTx - } + _ = tx.RollbackTransaction() return nil, err } - tx.CommitTransaction() + _ = tx.CommitTransaction() return newCompany, nil } From 381c3d3e708200bfc9e9e09e1272153703476a1d Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 10:41:33 -0300 Subject: [PATCH 28/34] Fixing e2e --- Makefile | 3 ++- e2e/server/keycloak/http_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 59baf293b..569112188 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,8 @@ test-e2e-messages: compose-e2e-messages test-e2e-server-keycloak: compose-e2e-server-keycloak $(GO) get -v ./e2e/... $(GO) clean -testcache - sleep 3 && $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast + sleep 10 + $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast # ========================================================================================= # diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index bd0f2628d..03d240938 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -91,12 +91,12 @@ func CreateDefaultUserInKeycloakAndGetAccessToken(t *testing.T) string { CreateUserInKeyCloak(t, user, credential, bearerToken) secret := GetClientSecretInAccountClient(t, bearerToken) assert.NotEmpty(t, secret) - StartAuthHorusecServices(t, bearerToken, secret) + StartAuthHorusecServices(t, secret) responseLogin = LoginInKeycloak(t, user.Username, credential.Value) return responseLogin["access_token"].(string) } -func StartAuthHorusecServices(t *testing.T, bearerToken, secret string) { +func StartAuthHorusecServices(t *testing.T, secret string) { fmt.Println("Starting auth horusec service...") output, err := exec.Command("whereis", "docker-compose").Output() assert.NoError(t, err) @@ -168,9 +168,9 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { assert.NotEmpty(t, accountRoles) assert.Equal(t, 2, len(accountRoles)) accountID := "" - for _, user := range accountRoles { - if user.Email == user.Email { - accountID = user.AccountID.String() + for _, currentUser := range accountRoles { + if currentUser.Email == user.Email { + accountID = currentUser.AccountID.String() } } assert.NotEmpty(t, accountID) From 2dc4c3179553dd1c5d7e1cae452ea531b0fc943c Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 11:15:45 -0300 Subject: [PATCH 29/34] Fixing e2e --- Makefile | 1 - e2e/application_admin/horusec/http_test.go | 1 + e2e/server/keycloak/http_test.go | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 569112188..d568d64eb 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,6 @@ test-e2e-messages: compose-e2e-messages test-e2e-server-keycloak: compose-e2e-server-keycloak $(GO) get -v ./e2e/... $(GO) clean -testcache - sleep 10 $(GO) test -v ./e2e/server/keycloak/... -timeout=5m -parallel=1 -failfast # ========================================================================================= # diff --git a/e2e/application_admin/horusec/http_test.go b/e2e/application_admin/horusec/http_test.go index 26d2fa922..5fc52839b 100644 --- a/e2e/application_admin/horusec/http_test.go +++ b/e2e/application_admin/horusec/http_test.go @@ -57,6 +57,7 @@ func TestServer(t *testing.T) { t.Skip("skipping integration test") } t.Run("Should tests default auth-type (horusec) http requests in application admin enable", func(t *testing.T) { + time.Sleep(5 * time.Second) // Login with default application admin contentLogin := Login(t, &accountentities.LoginData{ Email: "horusec-admin@example.com", diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index 03d240938..0d7056479 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -60,6 +60,7 @@ func TestServer(t *testing.T) { t.Skip("skipping integration test") } t.Run("Should tests auth-type keycloak http requests", func(t *testing.T) { + time.Sleep(10 * time.Second) bearerToken := CreateDefaultUserInKeycloakAndGetAccessToken(t) assert.NotEmpty(t, bearerToken) From 8f5926b7630ddde635b7a57d7f817be20bd8388c Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 11:32:17 -0300 Subject: [PATCH 30/34] Fixing e2e --- e2e/server/keycloak/http_test.go | 29 ++++++++++++++++------------- e2e/server/keycloak/requests.go | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index 0d7056479..cd682b9f5 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -61,10 +61,24 @@ func TestServer(t *testing.T) { } t.Run("Should tests auth-type keycloak http requests", func(t *testing.T) { time.Sleep(10 * time.Second) - bearerToken := CreateDefaultUserInKeycloakAndGetAccessToken(t) + user := &entities.UserRepresentation{ + Username: "e2e_user", + Email: "e2e@example.com", + EmailVerified: true, + Enabled: true, + } + credential := &entities.UserRepresentationCredentials{ + Temporary: false, + Type: "password", + Value: "Ch@ng3m3", + } + bearerToken := SetupKeycloakAndGetFirstAccessToken(t, user, credential) assert.NotEmpty(t, bearerToken) CreateUserFromKeycloakInHorusec(t, &accountentities.KeycloakToken{AccessToken: bearerToken}) + + bearerToken = LoginInKeycloak(t, user.Username, credential.Value)["access_token"].(string) + // TESTBOOK: Authorize // TESTBOOK: Create, Read, Update and Delete company companyID := RunCompanyCRUD(t, bearerToken) @@ -73,18 +87,7 @@ func TestServer(t *testing.T) { }) } -func CreateDefaultUserInKeycloakAndGetAccessToken(t *testing.T) string { - user := &entities.UserRepresentation{ - Username: "e2e_user", - Email: "e2e@example.com", - EmailVerified: true, - Enabled: true, - } - credential := &entities.UserRepresentationCredentials{ - Temporary: false, - Type: "password", - Value: "Ch@ng3m3", - } +func SetupKeycloakAndGetFirstAccessToken(t *testing.T, user *entities.UserRepresentation, credential *entities.UserRepresentationCredentials) string { responseLogin := LoginInKeycloak(t, "keycloak", "keycloak") bearerToken := "Bearer " + responseLogin["access_token"].(string) UpdateRolesToAcceptOAuth(t, bearerToken) diff --git a/e2e/server/keycloak/requests.go b/e2e/server/keycloak/requests.go index f3db22c3c..5a6df07f5 100644 --- a/e2e/server/keycloak/requests.go +++ b/e2e/server/keycloak/requests.go @@ -14,7 +14,7 @@ import ( ) func LoginInKeycloak(t *testing.T, username, password string) map[string]interface{} { - fmt.Println("Running test for LoginInKeycloak in Keycloak") + fmt.Println("Running test for LoginInKeycloak") payload := strings.NewReader(fmt.Sprintf("client_id=admin-cli&username=%s&password=%s&grant_type=password", username, password)) req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token", payload) req.Header.Add("content-type", "application/x-www-form-urlencoded") From 77aba6d6124498a40944b023adcd30a748a09b7f Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 13:02:49 -0300 Subject: [PATCH 31/34] Fixing e2e --- e2e/deployments/docker-compose.server.keycloak.yaml | 3 ++- e2e/server/shared_requests.go | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index bd421728d..eb0a26802 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -34,9 +34,10 @@ services: image: jboss/keycloak ports: - "8080:8080" + network_mode: "host" environment: DB_VENDOR: "postgres" - DB_ADDR: "postgresql_keycloak" + DB_ADDR: "127.0.0.1" DB_PORT: "5433" DB_USER: "root" DB_PASSWORD: "root" diff --git a/e2e/server/shared_requests.go b/e2e/server/shared_requests.go index 9711b2cb8..964221eb2 100644 --- a/e2e/server/shared_requests.go +++ b/e2e/server/shared_requests.go @@ -144,8 +144,7 @@ func RemoveUserInCompany(t *testing.T, bearerToken, companyID, accountID string) assert.NoError(t, resp.Body.Close()) } func GetChartContentWithoutTreatment(t *testing.T, route, bearerToken, companyID, repositoryID string) httpResponse.Interface { - fmt.Println("Running test for GetChartContent in route: " + route) - fmt.Println("Running test for GetChartRESTContentAndReturnBody") + fmt.Println("Running test for GetChartContentWithoutTreatment in route: " + route) now := time.Now() initialDateStr := now.Format("2006-01-02") + "T00:00:00Z" finalDateStr := now.Format("2006-01-02") + "T23:59:59Z" From 47be7634582ee43e8e43c8c93f078f65f1aaffa4 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 13:15:28 -0300 Subject: [PATCH 32/34] Fixing e2e --- e2e/server/keycloak/http_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/e2e/server/keycloak/http_test.go b/e2e/server/keycloak/http_test.go index cd682b9f5..ba50a5e61 100644 --- a/e2e/server/keycloak/http_test.go +++ b/e2e/server/keycloak/http_test.go @@ -79,6 +79,9 @@ func TestServer(t *testing.T) { bearerToken = LoginInKeycloak(t, user.Username, credential.Value)["access_token"].(string) + fmt.Println("Waiting register token in keycloak and register new user in horusec...") + time.Sleep(3 * time.Second) + // TESTBOOK: Authorize // TESTBOOK: Create, Read, Update and Delete company companyID := RunCompanyCRUD(t, bearerToken) @@ -157,7 +160,8 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { responseLoginNewUser := LoginInKeycloak(t, user.Username, credential.Value) bearerTokenAccount2 := responseLoginNewUser["access_token"].(string) CreateUserFromKeycloakInHorusec(t, &accountentities.KeycloakToken{AccessToken: bearerTokenAccount2}) - + fmt.Println("Waiting register token in keycloak and register new user in horusec...") + time.Sleep(3 * time.Second) // Invite user to existing company server.InviteUserToCompany(t, bearerTokenAccount1, companyID, &accountentities.InviteUser{ Role: rolesEnum.Member, @@ -191,6 +195,7 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) { server.UpdateUserInCompany(t, bearerTokenAccount1, companyID, accountID, &roles.AccountCompany{ Role: rolesEnum.Admin, }) + time.Sleep(1 * time.Second) // Expected return OK because user is authorized view dashboard in company view responseChart = server.GetChartContentWithoutTreatment(t, "total-repositories", bearerTokenAccount2, companyID, "") From c50db3e436105cb259b84f3b2d4e4961e965ecc8 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 13:25:48 -0300 Subject: [PATCH 33/34] Fixing e2e --- .../docker-compose.application-admin.horusec.yaml | 3 ++- e2e/deployments/docker-compose.server.horusec.yaml | 7 ++++--- e2e/deployments/docker-compose.server.keycloak.yaml | 4 ++-- e2e/deployments/docker-compose.server.messages.yaml | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/e2e/deployments/docker-compose.application-admin.horusec.yaml b/e2e/deployments/docker-compose.application-admin.horusec.yaml index 473a7c5e0..e92d76f4d 100644 --- a/e2e/deployments/docker-compose.application-admin.horusec.yaml +++ b/e2e/deployments/docker-compose.application-admin.horusec.yaml @@ -32,7 +32,7 @@ services: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_AUTH_URL: "127.0.0.1:8007" horusec-auth: build: context: ../../ @@ -43,6 +43,7 @@ services: container_name: horusec-auth ports: - "8006:8006" + - "8007:8007" network_mode: "host" environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" diff --git a/e2e/deployments/docker-compose.server.horusec.yaml b/e2e/deployments/docker-compose.server.horusec.yaml index f7576741b..dc4574777 100644 --- a/e2e/deployments/docker-compose.server.horusec.yaml +++ b/e2e/deployments/docker-compose.server.horusec.yaml @@ -33,7 +33,7 @@ services: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_AUTH_URL: "127.0.0.1:8007" horusec-auth: build: context: ../../ @@ -45,6 +45,7 @@ services: network_mode: "host" ports: - "8006:8006" + - "8007:8007" environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" @@ -66,7 +67,7 @@ services: environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_AUTH_URL: "127.0.0.1:8007" horusec-api: build: context: ../../ @@ -82,4 +83,4 @@ services: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" \ No newline at end of file + HORUSEC_AUTH_URL: "127.0.0.1:8007" \ No newline at end of file diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index eb0a26802..0e34e0478 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -59,7 +59,7 @@ services: HORUSEC_ACCOUNT_DISABLE_EMAIL_SERVICE: "true" HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_AUTH_URL: "127.0.0.1:8007" horusec-auth: build: context: ../../ @@ -97,4 +97,4 @@ services: environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_AUTH_URL: "127.0.0.1:8007" diff --git a/e2e/deployments/docker-compose.server.messages.yaml b/e2e/deployments/docker-compose.server.messages.yaml index 97e9d3a26..6c94c2090 100644 --- a/e2e/deployments/docker-compose.server.messages.yaml +++ b/e2e/deployments/docker-compose.server.messages.yaml @@ -65,7 +65,7 @@ services: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" HORUSEC_JWT_SECRET_KEY: "horusec-secret" - HORUSEC_AUTH_URL: "http://127.0.0.1:8006" + HORUSEC_AUTH_URL: "127.0.0.1:8007" HORUSEC_MANAGER_URL: "http://127.0.0.1:8043" horusec-auth: build: @@ -77,6 +77,7 @@ services: container_name: horusec-auth ports: - "8006:8006" + - "8007:8007" network_mode: "host" environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" From 88e680db12da612ccbed86b958033ffbc2228c79 Mon Sep 17 00:00:00 2001 From: Wilian Gabriel Date: Fri, 6 Nov 2020 13:35:48 -0300 Subject: [PATCH 34/34] Fixing e2e --- e2e/deployments/docker-compose.server.keycloak.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/e2e/deployments/docker-compose.server.keycloak.yaml b/e2e/deployments/docker-compose.server.keycloak.yaml index 0e34e0478..fdf783f37 100644 --- a/e2e/deployments/docker-compose.server.keycloak.yaml +++ b/e2e/deployments/docker-compose.server.keycloak.yaml @@ -69,19 +69,21 @@ services: - keycloak restart: always container_name: horusec-auth + network_mode: "host" ports: - "8006:8006" - network_mode: "host" + - "8007:8007" environment: HORUSEC_DATABASE_SQL_URI: "postgresql://root:root@127.0.0.1:5432/horusec_db?sslmode=disable" HORUSEC_DATABASE_SQL_DIALECT: "postgres" - HORUSEC_ENABLE_APPLICATION_ADMIN: "false" - HORUSEC_AUTH_TYPE: "keycloak" + HORUSEC_JWT_SECRET_KEY: "horusec-secret" HORUSEC_KEYCLOAK_BASE_PATH: "http://127.0.0.1:8080" HORUSEC_KEYCLOAK_CLIENT_ID: "account" HORUSEC_KEYCLOAK_CLIENT_SECRET: ${HORUSEC_KEYCLOAK_CLIENT_SECRET} HORUSEC_KEYCLOAK_REALM: "master" - HORUSEC_KEYCLOAK_OTP: "false" + HORUSEC_ENABLE_APPLICATION_ADMIN: "false" + HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}" + HORUSEC_AUTH_TYPE: "keycloak" horusec-analytic: build: context: ../../