Skip to content
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
14 changes: 7 additions & 7 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *AuthZenPlugin) Stop(_ context.Context) {
func (p *AuthZenPlugin) Reconfigure(_ context.Context, config any) {
cfg, ok := config.(*Config)
if !ok || cfg == nil {
p.logger.Error("AuthZEN reconfigure: unexpected or nil config type %T", config)
p.logger.WithFields(map[string]any{"config_type": fmt.Sprintf("%T", config)}).Error("AuthZEN reconfigure: unexpected or nil config type")
return
}
p.mu.Lock()
Expand Down Expand Up @@ -259,10 +259,10 @@ func buildInput(subject, action, resource, ctx json.RawMessage) (map[string]any,
// A JSON `null` value is treated as absent. If both are null, nil is returned
// so that the required-field check catches the missing value.
func mergeField(deflt, override json.RawMessage) json.RawMessage {
if len(override) > 0 && string(override) != "null" {
if len(override) > 0 && !isJSONNull(override) {
return override
}
if len(deflt) > 0 && string(deflt) != "null" {
if len(deflt) > 0 && !isJSONNull(deflt) {
return deflt
}
return nil
Expand Down Expand Up @@ -326,12 +326,12 @@ func (p *AuthZenPlugin) handleEvaluation(w http.ResponseWriter, r *http.Request)

decision, path, decisionRule, err := p.eval(r.Context(), input)
if err != nil {
p.logger.Error("AuthZEN evaluation error: path=%s.%s error=%v", path, decisionRule, err)
p.logger.WithFields(map[string]any{"path": path, "decision_rule": decisionRule, "error": err}).Error("AuthZEN evaluation error")
jsonError(w, "evaluation failed", http.StatusInternalServerError)
return
}

p.logger.Debug("AuthZEN evaluation: path=%s.%s decision=%v input=%v", path, decisionRule, decision, input)
p.logger.WithFields(map[string]any{"path": path, "decision_rule": decisionRule, "decision": decision, "input": input}).Debug("AuthZEN evaluation")

resp := evaluationResponse{
Decision: decision,
Expand Down Expand Up @@ -502,15 +502,15 @@ func (p *AuthZenPlugin) handleEvaluations(w http.ResponseWriter, r *http.Request

decision, path, decisionRule, err := p.evalWithTxn(r.Context(), txn, input)
if err != nil {
p.logger.Error("AuthZEN batch evaluation error: path=%s.%s error=%v", path, decisionRule, err)
p.logger.WithFields(map[string]any{"path": path, "decision_rule": decisionRule, "error": err}).Error("AuthZEN batch evaluation error")
results = append(results, evalErrorResponse(500, "evaluation failed"))
if semantic == semanticDenyOnFirstDeny {
break
}
continue
}

p.logger.Debug("AuthZEN batch evaluation: path=%s.%s decision=%v", path, decisionRule, decision)
p.logger.WithFields(map[string]any{"path": path, "decision_rule": decisionRule, "decision": decision}).Debug("AuthZEN batch evaluation")

if semantic == semanticDenyOnFirstDeny && !decision {
// Short-circuit: include reason in context (Section 7.1.2.1).
Expand Down
10 changes: 5 additions & 5 deletions internal/internal_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func BenchmarkEvaluationAllow(b *testing.B) {
p := testPlugin(&testing.T{}, module)
p := testPlugin(b, module)
if err := p.Start(context.Background()); err != nil {
b.Fatal(err)
}
Expand All @@ -34,7 +34,7 @@ func BenchmarkEvaluationAllow(b *testing.B) {
}

func BenchmarkEvaluationDeny(b *testing.B) {
p := testPlugin(&testing.T{}, module)
p := testPlugin(b, module)
if err := p.Start(context.Background()); err != nil {
b.Fatal(err)
}
Expand All @@ -60,7 +60,7 @@ func BenchmarkEvaluationDeny(b *testing.B) {
}

func BenchmarkBatchEvaluations(b *testing.B) {
p := testPlugin(&testing.T{}, module)
p := testPlugin(b, module)
if err := p.Start(context.Background()); err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func BenchmarkBatchEvaluations(b *testing.B) {
}

func BenchmarkWellKnown(b *testing.B) {
p := testPlugin(&testing.T{}, module)
p := testPlugin(b, module)
if err := p.Start(context.Background()); err != nil {
b.Fatal(err)
}
Expand All @@ -111,7 +111,7 @@ func BenchmarkWellKnown(b *testing.B) {
}

func BenchmarkParallelEvaluations(b *testing.B) {
p := testPlugin(&testing.T{}, module)
p := testPlugin(b, module)
if err := p.Start(context.Background()); err != nil {
b.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ const module = `
}
`

func testPlugin(t *testing.T, module string) *AuthZenPlugin {
t.Helper()
func testPlugin(tb testing.TB, module string) *AuthZenPlugin {
tb.Helper()

ctx := context.Background()
store := inmem.New()
txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams)
if err := store.UpsertPolicy(ctx, txn, "test.rego", []byte(module)); err != nil {
t.Fatal(err)
tb.Fatal(err)
}
if err := store.Commit(ctx, txn); err != nil {
t.Fatal(err)
tb.Fatal(err)
}

m, err := plugins.New([]byte{}, "test", store)
if err != nil {
t.Fatal(err)
tb.Fatal(err)
}

if err := m.Start(ctx); err != nil {
t.Fatal(err)
tb.Fatal(err)
}

cfg := &Config{
Expand Down