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

[WIP] Fixing e2e #115

Merged
merged 22 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 14 additions & 14 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +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-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
Expand Down
4 changes: 2 additions & 2 deletions deployments/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ services:
HORUS_LDAP_USERFILTER: "(uid=%s)"
HORUS_LDAP_GROUPFILTER: "(memberUid=%s)"
HORUSEC_LDAP_ADMIN_GROUP: "admin"
HORUSEC_ENABLE_APPLICATION_ADMIN: "false"
HORUSEC_ENABLE_APPLICATION_ADMIN: "true"
HORUSEC_APPLICATION_ADMIN_DATA: "{\"username\": \"horusec-admin\", \"email\":\"horusec-admin@example.com\", \"password\":\"Devpass0*\"}"
HORUSEC_AUTH_TYPE: "ldap"
HORUSEC_AUTH_TYPE: "horusec"
horusec-analytic:
build:
context: ../
Expand Down
6 changes: 6 additions & 0 deletions development-kit/pkg/entities/auth/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package auth

import (
"encoding/json"
validation "github.com/go-ozzo/ozzo-validation/v4"
)

Expand All @@ -30,3 +31,8 @@ func (c *Credentials) Validate() error {
validation.Field(&c.Password, validation.Length(1, 255), validation.Required),
)
}

func (c *Credentials) ToBytes() []byte {
content, _ := json.Marshal(c)
return content
}
8 changes: 8 additions & 0 deletions development-kit/pkg/entities/auth/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ func TestValidateCredentials(t *testing.T) {

assert.Error(t, credentials.Validate())
})

t.Run("Should not empty when marshal", func(t *testing.T) {
credentials := &Credentials{
Username: "horus@test.com",
Password: "UltraSafePass",
}
assert.NotEmpty(t, credentials.ToBytes())
})
}
11 changes: 6 additions & 5 deletions e2e/application_admin/horusec/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package horusec
import (
"fmt"
accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"github.com/ZupIT/horusec/development-kit/pkg/utils/env"
"github.com/ZupIT/horusec/development-kit/pkg/utils/logger"
"github.com/golang-migrate/migrate/v4"
Expand Down Expand Up @@ -57,10 +58,10 @@ 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)
time.Sleep(10 * time.Second)
// Login with default application admin
contentLogin := Login(t, &accountentities.LoginData{
Email: "horusec-admin@example.com",
contentLogin := Login(t, &authEntities.Credentials{
Username: "horusec-admin@example.com",
Password: "Devpass0*",
})
bearerToken := contentLogin["accessToken"]
Expand Down Expand Up @@ -99,8 +100,8 @@ func TestServer(t *testing.T) {
assert.NotContains(t, allCompanies, "zup")

// Login with new user
contentLoginNewUser := Login(t, &accountentities.LoginData{
Email: "e2e@example.com",
contentLoginNewUser := Login(t, &authEntities.Credentials{
Username: "e2e@example.com",
Password: "Ch@ng3m3",
})
bearerTokenNewUser := contentLoginNewUser["accessToken"]
Expand Down
5 changes: 3 additions & 2 deletions e2e/application_admin/horusec/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
accountentities "github.com/ZupIT/horusec/development-kit/pkg/entities/account"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
Expand All @@ -23,10 +24,10 @@ func CreateAccount(t *testing.T, account *accountentities.Account) {
assert.NotEmpty(t, createAccountResponse["content"])
}

func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string {
func Login(t *testing.T, credentials *authEntities.Credentials) map[string]string {
fmt.Println("Running test for Login")
loginResp, err := http.Post(
"http://127.0.0.1:8003/api/account/login",
"http://127.0.0.1:8006/api/auth/authenticate",
"text/json",
bytes.NewReader(credentials.ToBytes()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
image: postgres:12
ports:
- "5432:5432"
network_mode: "host"
environment:
POSTGRES_PASSWORD: root
POSTGRES_USER: root
Expand Down
13 changes: 7 additions & 6 deletions e2e/server/horusec/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"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"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"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"
Expand Down Expand Up @@ -69,8 +70,8 @@ func TestServer(t *testing.T) {
Username: "e2e_user",
})
// TESTBOOK: Login
contentLogin := Login(t, &accountentities.LoginData{
Email: "e2e@example.com",
contentLogin := Login(t, &authEntities.Credentials{
Username: "e2e@example.com",
Password: "Ch@ng3m3",
})
bearerToken := contentLogin["accessToken"]
Expand Down Expand Up @@ -327,8 +328,8 @@ func RunCRUDUserInCompany(t *testing.T, bearerTokenAccount1, companyID string) {
}
assert.NotEmpty(t, accountID)
// Login with new user
contentLoginAccount2 := Login(t, &accountentities.LoginData{
Email: account2.Email,
contentLoginAccount2 := Login(t, &authEntities.Credentials{
Username: account2.Email,
Password: account2.Password,
})
bearerTokenAccount2 := contentLoginAccount2["accessToken"]
Expand Down Expand Up @@ -402,8 +403,8 @@ func RunCRUDUserInRepository(t *testing.T, bearerTokenAccount1, companyID, repos
assert.NotEmpty(t, accountID)

// Login with new user
contentLoginAccount2 := Login(t, &accountentities.LoginData{
Email: account2.Email,
contentLoginAccount2 := Login(t, &authEntities.Credentials{
Username: account2.Email,
Password: account2.Password,
})
bearerTokenAccount2 := contentLoginAccount2["accessToken"]
Expand Down
5 changes: 3 additions & 2 deletions e2e/server/horusec/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"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"
authEntities "github.com/ZupIT/horusec/development-kit/pkg/entities/auth"
"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"
Expand All @@ -32,10 +33,10 @@ func CreateAccount(t *testing.T, account *accountentities.Account) {
assert.NotEmpty(t, createAccountResponse["content"])
}

func Login(t *testing.T, credentials *accountentities.LoginData) map[string]string {
func Login(t *testing.T, credentials *authEntities.Credentials) map[string]string {
fmt.Println("Running test for Login")
loginResp, err := http.Post(
"http://127.0.0.1:8003/api/account/login",
"http://127.0.0.1:8006/api/auth/authenticate",
"text/json",
bytes.NewReader(credentials.ToBytes()),
)
Expand Down
Loading