Skip to content

Commit

Permalink
go-edge-ds bufpool & test updates (#515)
Browse files Browse the repository at this point in the history
* go-edge-ds bufpool & test updates

* upd ci re-enable NoTLS templates test

* rm testcontainer WithDeadline

* refactor NoTLS test

* refactor testcontainer usage
  • Loading branch information
gertd authored Dec 12, 2024
1 parent bdf24e7 commit 7985281
Show file tree
Hide file tree
Showing 20 changed files with 547 additions and 501 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ jobs:
gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/manifest/... github.com/aserto-dev/topaz/pkg/app/tests/manifest/...
gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/policy/... github.com/aserto-dev/topaz/pkg/app/tests/policy/...
gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/query/... github.com/aserto-dev/topaz/pkg/app/tests/query/...
gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/template/... github.com/aserto-dev/topaz/pkg/app/tests/template/...
-
name: Templates Test
run: |
gotestsum --format short-verbose -- -count=1 -timeout 240s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/template/... github.com/aserto-dev/topaz/pkg/app/tests/template/...
-
name: Templates Test (NoTLS)
run: |
gotestsum --format short-verbose -- -count=1 -timeout 120s -parallel=1 -v -coverprofile=cover.out -coverpkg=github.com/aserto-dev/topaz/pkg/app/tests/template-no-tls/... github.com/aserto-dev/topaz/pkg/app/tests/template-no-tls/...
-
name: Upload code coverage
uses: shogo82148/actions-goveralls@v1
Expand Down
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
# Dependency directories (remove the comment below to include it)
# vendor/
/.dev/
/.ext
/.ext/

/bin/
/release/
/test/
.opa/
/bundle/
/dist/
/test/
/dist-test/

# runtime directories
/cfg/
/eds/

# OPA related
.opa/
/bundle/

# misc
.DS_Store

Expand Down
2 changes: 1 addition & 1 deletion .goreleaser-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before:
hooks:

# https://goreleaser.com/customization/dist/
dist: test
dist: dist-test

builds:
# https://goreleaser.com/customization/build/
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/aserto-dev/go-aserto v0.33.4
github.com/aserto-dev/go-authorizer v0.20.11
github.com/aserto-dev/go-directory v0.33.2
github.com/aserto-dev/go-edge-ds v0.33.2
github.com/aserto-dev/go-edge-ds v0.33.3
github.com/aserto-dev/go-grpc v0.9.2
github.com/aserto-dev/go-topaz-ui v0.1.15
github.com/aserto-dev/header v0.0.8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ github.com/aserto-dev/go-decision-logs v0.1.2 h1:f26bgKDIroNeN71+Ot2AXfCAtausNcB
github.com/aserto-dev/go-decision-logs v0.1.2/go.mod h1:T7Pws/IBopk3he4kgAlmZH9/JcwX2s8T2pwc715Mobo=
github.com/aserto-dev/go-directory v0.33.2 h1:QJwzSmfxJ7EG0RzWsgu7In5cAeGtZURZklSsHhMOFh8=
github.com/aserto-dev/go-directory v0.33.2/go.mod h1:gK239V0htJtp0/BwvbTrYv/XIphoK/AugP8sw3m8B0s=
github.com/aserto-dev/go-edge-ds v0.33.2 h1:2ZeqFq6wgL2R0b7Zyx8pQLIVdv6WH6Okg7gjiaahztw=
github.com/aserto-dev/go-edge-ds v0.33.2/go.mod h1:Vg9ZIbUXAc33BAyj0qBTatS/wxQGY1pV59vGa5pZCiU=
github.com/aserto-dev/go-edge-ds v0.33.3 h1:wEFDcTF2WEF9QIEInreNcUWIrIM2OvoniVQKrCIv8IE=
github.com/aserto-dev/go-edge-ds v0.33.3/go.mod h1:Vg9ZIbUXAc33BAyj0qBTatS/wxQGY1pV59vGa5pZCiU=
github.com/aserto-dev/go-grpc v0.9.2 h1:NYhl1yRnLWlTMe/L051lRZwuvv/lUuP9vJ4gFPwzpSw=
github.com/aserto-dev/go-grpc v0.9.2/go.mod h1:pKZdJ9+ITXPBvFQeU+CJmRtQE7rX/+cX9JFRzo8z0TQ=
github.com/aserto-dev/go-topaz-ui v0.1.15 h1:ykez4Em2gEORDi96lDEzS2yWb510dzSKZzAoyP4tQ8Q=
Expand Down
9 changes: 2 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ go-mod-tidy:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@go work edit -json | jq -r '.Use[].DiskPath' | xargs -I{} bash -c 'cd {} && echo "${PWD}/go.mod" && go mod tidy -v && cd -'

.PHONY: dev-release
dev-release:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@${EXT_BIN_DIR}/goreleaser release --clean --snapshot

.PHONY: release
release:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
Expand All @@ -80,7 +75,7 @@ lint:
.PHONY: test-snapshot
test-snapshot:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@${EXT_BIN_DIR}/goreleaser release --config .goreleaser-test.yml --clean --snapshot
@${EXT_BIN_DIR}/goreleaser release --config .goreleaser-test.yml --clean --snapshot --skip archive

.PHONE: container-tag
container-tag:
Expand All @@ -91,7 +86,7 @@ container-tag:
run-test-snapshot:
@echo -e "$(ATTN_COLOR)==> $@ $(NO_COLOR)"
@echo "topaz run $$(${PWD}/dist/topaz_${GOOS}_${GOARCH}/topaz config info | jq '.runtime.active_configuration_file')"
@${PWD}/dist/topazd_${GOOS}_${GOARCH}/topazd run -c $$(${PWD}/dist/topaz_${GOOS}_${GOARCH}/topaz config info | jq -r '.runtime.active_configuration_file')
@${PWD}/dist/topaz_${GOOS}_${GOARCH}/topaz run --container-tag=0.0.0-test-$$(git rev-parse --short HEAD)-$$(uname -m)

.PHONY: start-test-snapshot
start-test-snapshot:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions pkg/app/tests/assets/gdrive/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# yaml-language-server: $schema=https://www.topaz.sh/schema/manifest.json
---

### filename: manifest.yaml ###
### datetime: 2023-12-19T00:00:00-00:00 ###
### description: gdrive manifest ###
#
# model
model:
version: 3

# object type definitions
types:
### display_name: User ###
user:
relations:
### display_name: user#manager ###
manager: user

permissions:
### display_name: user#in_management_chain ###
in_management_chain: manager | manager->in_management_chain


### display_name: Identity ###
identity:
relations:
### display_name: identity#identifier ###
identifier: user


### display_name: Group ###
group:
relations:
### display_name: group#member ###
member: user | group#member


# folder represents a collection of documents and/or other folders
folder:
relations:
parent: folder

owner: user
editor: user | group#member
viewer: user | group#member

permissions:
can_share: owner | parent->can_share
can_write: editor | can_share | parent->can_write
can_read: viewer | can_write | parent->can_read


# doc represents a document within a folder
doc:
relations:
parent: folder

owner: user
editor: user | group#member
viewer: user | user:* | group#member

permissions:
can_share: owner | parent->can_share
can_delete: can_share | parent->can_write
can_write: editor | can_delete | parent->can_write
can_read: viewer | can_write | parent->can_read
96 changes: 49 additions & 47 deletions pkg/app/tests/authz/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package authz_test

import (
"context"
"os"
"testing"
"time"

client "github.com/aserto-dev/go-aserto"
azc "github.com/aserto-dev/go-aserto/az"
"github.com/aserto-dev/go-authorizer/aserto/authorizer/v2"
api "github.com/aserto-dev/go-authorizer/aserto/authorizer/v2/api"
assets_test "github.com/aserto-dev/topaz/assets"
assets_test "github.com/aserto-dev/topaz/pkg/app/tests/assets"
tc "github.com/aserto-dev/topaz/pkg/app/tests/common"

"github.com/stretchr/testify/assert"
Expand All @@ -22,19 +21,14 @@ import (
"google.golang.org/protobuf/types/known/structpb"
)

var addr string

func TestMain(m *testing.M) {
rc := 0
defer func() {
os.Exit(rc)
}()
func TestAuthZ(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())

ctx := context.Background()
t.Logf("\nTEST CONTAINER IMAGE: %q\n", tc.TestImage())

h, err := tc.NewHarness(ctx, &testcontainers.ContainerRequest{
req := testcontainers.ContainerRequest{
Image: tc.TestImage(),
ExposedPorts: []string{"9292/tcp", "9393/tcp"},
ExposedPorts: []string{"9292/tcp"},
Env: map[string]string{
"TOPAZ_CERTS_DIR": "/certs",
"TOPAZ_DB_DIR": "/data",
Expand All @@ -54,50 +48,58 @@ func TestMain(m *testing.M) {
},
WaitingFor: wait.ForAll(
wait.ForExposedPort(),
wait.ForLog("Starting 0.0.0.0:9393 gateway server"),
).WithStartupTimeoutDefault(240 * time.Second).WithDeadline(360 * time.Second),
wait.ForLog("Starting 0.0.0.0:9292 gRPC server"),
).WithStartupTimeoutDefault(300 * time.Second),
}

topaz, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: false,
})
if err != nil {
rc = 99
return
require.NoError(t, err)

if err := topaz.Start(ctx); err != nil {
require.NoError(t, err)
}

defer func() {
if err := h.Close(ctx); err != nil {
rc = 100
}
}()
t.Cleanup(func() {
testcontainers.CleanupContainer(t, topaz)
cancel()
})

addr = h.AddrGRPC(ctx)
grpcAddr, err := tc.MappedAddr(ctx, topaz, "9292")
require.NoError(t, err)

rc = m.Run()
t.Run("testAuthZ", testAuthZ(grpcAddr))
}

func TestWithMissingIdentity(t *testing.T) {
opts := []client.ConnectionOption{
client.WithAddr(addr),
client.WithInsecure(true),
}

azClient, err := azc.New(opts...)
require.NoError(t, err)
t.Cleanup(func() { _ = azClient.Close() })
func testAuthZ(addr string) func(*testing.T) {
return func(t *testing.T) {
opts := []client.ConnectionOption{
client.WithAddr(addr),
client.WithInsecure(true),
}

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

tests := []struct {
name string
test func(*testing.T)
}{
{"TestDecisionTreeWithMissingIdentity", DecisionTreeWithMissingIdentity(ctx, azClient)},
{"TestDecisionTreeWithUserID", DecisionTreeWithUserID(ctx, azClient)},
{"TestIsWithMissingIdentity", IsWithMissingIdentity(ctx, azClient)},
{"TestQueryWithMissingIdentity", QueryWithMissingIdentity(ctx, azClient)},
}
azClient, err := azc.New(opts...)
require.NoError(t, err)
t.Cleanup(func() { _ = azClient.Close() })

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

tests := []struct {
name string
test func(*testing.T)
}{
{"TestDecisionTreeWithMissingIdentity", DecisionTreeWithMissingIdentity(ctx, azClient)},
{"TestDecisionTreeWithUserID", DecisionTreeWithUserID(ctx, azClient)},
{"TestIsWithMissingIdentity", IsWithMissingIdentity(ctx, azClient)},
{"TestQueryWithMissingIdentity", QueryWithMissingIdentity(ctx, azClient)},
}

for _, testCase := range tests {
t.Run(testCase.name, testCase.test)
for _, testCase := range tests {
t.Run(testCase.name, testCase.test)
}
}
}

Expand Down
Loading

0 comments on commit 7985281

Please sign in to comment.