Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improving test #102

Merged
merged 37 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f4f2cc2
Adding more e2e tests
wiliansilvazup Oct 29, 2020
2e9b696
Adding more e2e tests
wiliansilvazup Oct 30, 2020
14ea86b
Adding more tests e2e
wiliansilvazup Oct 30, 2020
335d923
Fixing fmt lint
wiliansilvazup Oct 30, 2020
c5394ec
Update test e2e
wiliansilvazup Oct 30, 2020
375daa0
Update test e2e
wiliansilvazup Oct 30, 2020
3a9c762
Fixing workflow e2e
wiliansilvazup Oct 30, 2020
3b727dd
Fixing e2e running
wiliansilvazup Oct 30, 2020
8309dfd
Adding validation to restart service with up migratin
wiliansilvazup Oct 30, 2020
95c876e
Fixing tests e2e
wiliansilvazup Oct 30, 2020
7c01ca4
Fixing tests e2e
wiliansilvazup Oct 30, 2020
019946a
Fixing e2e
wiliansilvazup Oct 30, 2020
56462ff
Adding e2e to check if send messages correctly
wiliansilvazup Oct 30, 2020
033487a
Update testbook
wiliansilvazup Oct 30, 2020
d280893
Fixing gomod
wiliansilvazup Nov 3, 2020
9828c48
Starting add keycloak e2e tests
wiliansilvazup Nov 3, 2020
22c46ee
Adding Request to configure keycloak service
wiliansilvazup Nov 4, 2020
976afc9
Adding correctly form to run tests using keycloak server
wiliansilvazup Nov 5, 2020
4f708c1
Fixing makefile
wiliansilvazup Nov 5, 2020
2d03f5a
Adding tests in keycloak to validate invite user
wiliansilvazup Nov 5, 2020
01f021f
Fixing makefile
wiliansilvazup Nov 5, 2020
fa37576
Fixing names and docs of e2e
wiliansilvazup Nov 5, 2020
f684849
Merge branch 'develop' of github.com:ZupIT/horusec into feature/impro…
wiliansilvazup Nov 5, 2020
47bbf32
Merge branch 'develop' of github.com:ZupIT/horusec into feature/impro…
wiliansilvazup Nov 5, 2020
5ea7159
Removing trash of tests of analysis
wiliansilvazup Nov 5, 2020
cc5e3a6
Fixing conflicts
wiliansilvazup Nov 6, 2020
62173d1
Fixing e2e
wiliansilvazup Nov 6, 2020
9698177
Fixing e2e messages
wiliansilvazup Nov 6, 2020
4510208
Fixing create company
wiliansilvazup Nov 6, 2020
d64e4b5
Fixing create company
wiliansilvazup Nov 6, 2020
381c3d3
Fixing e2e
wiliansilvazup Nov 6, 2020
2dc4c31
Fixing e2e
wiliansilvazup Nov 6, 2020
8f5926b
Fixing e2e
wiliansilvazup Nov 6, 2020
77aba6d
Fixing e2e
wiliansilvazup Nov 6, 2020
47be763
Fixing e2e
wiliansilvazup Nov 6, 2020
c50db3e
Fixing e2e
wiliansilvazup Nov 6, 2020
88e680d
Fixing e2e
wiliansilvazup Nov 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 67 additions & 13 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,73 @@ 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:
- 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: Setup External Dependences
run: make compose-e2e
- 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-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
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
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-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
68 changes: 48 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -43,14 +44,31 @@ 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:
go get -v ./e2e/...
go get -v ./horusec-cli/...
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
$(GO) test -v ./e2e/server/... -timeout=5m -parallel=1 -failfast
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: 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: 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: compose-e2e-server-keycloak
$(GO) get -v ./e2e/...
$(GO) clean -testcache
$(GO) test -v ./e2e/server/keycloak/... -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
Expand All @@ -75,28 +93,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
compose-e2e:
docker-compose -f e2e/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
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
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 horusec-analytic

# ========================================================================================= #

Expand All @@ -114,31 +142,31 @@ 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
cd ..
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
cd ..
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
cd ..
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
Expand All @@ -149,4 +177,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
6 changes: 6 additions & 0 deletions development-kit/pkg/entities/account/invite_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions development-kit/pkg/entities/account/invite_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
6 changes: 6 additions & 0 deletions development-kit/pkg/entities/account/roles/account_company.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package roles

import (
"encoding/json"
"time"

"github.com/go-ozzo/ozzo-validation/v4/is"
Expand Down Expand Up @@ -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
}
14 changes: 12 additions & 2 deletions development-kit/pkg/entities/account/roles/account_company_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
})
}
6 changes: 6 additions & 0 deletions development-kit/pkg/entities/api/dto/update_vuln_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions development-kit/pkg/entities/api/dto/update_vuln_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
2 changes: 1 addition & 1 deletion development-kit/pkg/services/keycloak/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading