Skip to content

Commit

Permalink
Add def and params validation
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Oct 17, 2024
1 parent 4b90b61 commit 0fdcbff
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ go 1.23.1
toolchain go1.23.2

require (
github.com/mindersec/minder v0.0.0-00010101000000-000000000000
github.com/mindersec/minder v0.0.67
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
google.golang.org/protobuf v1.35.1
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -178,7 +180,6 @@ require (
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sassoftware/relic v7.2.1+incompatible // indirect
Expand Down Expand Up @@ -248,7 +249,6 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand All @@ -257,6 +257,3 @@ require (
sigs.k8s.io/release-utils v0.8.5 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

// Replace minder with local path
replace github.com/mindersec/minder => ../minder
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxU
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4=
github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY=
github.com/mindersec/minder v0.0.67 h1:B8MkUv9pJOTFSIeiSgS9VgcWvZnYvb50uku85tWetZA=
github.com/mindersec/minder v0.0.67/go.mod h1:uV0pATH/HikfAt68XqRyyMB2W6ewPdGuk16VD0vMMUE=
github.com/minio/highwayhash v1.0.3 h1:kbnuUMoHYyVl7szWjSxJnxw11k2U709jqFPPmIUyD6Q=
github.com/minio/highwayhash v1.0.3/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
Expand Down
4 changes: 3 additions & 1 deletion rule-types/common/license.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ tests:
git:
repo_base: license_should_be_mit
- name: "License missing"
def: {}
def:
license_filename: LICENSE
license_type: MIT
params: {}
expect: "fail"
git:
Expand Down
2 changes: 2 additions & 0 deletions rule-types/github/secret_scanning.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ tests:
entity: *test-repo
http:
status: 500
body: |
{ "message": "Internal server error" }
4 changes: 4 additions & 0 deletions rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func TestRuleTypes(t *testing.T) {
rte, err := rtengine.NewRuleTypeEngine(ctx, rt, tk)
require.NoError(t, err)

val := rte.GetRuleInstanceValidator()
require.NoError(t, val.ValidateRuleDefAgainstSchema(tc.Def), "Failed to validate rule definition against schema")
require.NoError(t, val.ValidateParamsAgainstSchema(tc.Params), "Failed to validate params against schema")

if tk.ShouldOverrideIngest() {
rte.WithCustomIngester(tk)
}
Expand Down

0 comments on commit 0fdcbff

Please sign in to comment.