Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

1.6 KB
Raw Blame
package policy_engine

import (
	"testing"
)

func TestEvaluateConditionsFailsClosedOnUnsupportedOperator(t *testing.T) {
	conditions := PolicyConditions{
		"StringEqualsBogus": {
			"aws:username": NewStringOrStringSlice("alice"),
		},
	}
	contextValues := map[string][]string{}
	got := EvaluateConditions(conditions, contextValues, nil, nil)
	if got {
		t.Fatalf("EvaluateConditions returned true for unsupported operator; expected false (fail closed)")
	}
}

// A policy parsed into interface{} can hand an evaluator a null condition
// value; no operator, set-qualified or not, may panic on it.
func TestConditionEvaluatorsTolerateNilValue(t *testing.T) {
	operators := []string{
		"StringEquals", "StringNotEquals", "StringLike", "StringNotLike",
		"StringEqualsIgnoreCase", "StringNotEqualsIgnoreCase",
		"NumericEquals", "NumericNotEquals", "NumericLessThan", "NumericLessThanEquals",
		"NumericGreaterThan", "NumericGreaterThanEquals",
		"DateEquals", "DateNotEquals", "DateLessThan", "DateLessThanEquals",
		"DateGreaterThan", "DateGreaterThanEquals",
		"Bool", "IpAddress", "NotIpAddress", "ArnEquals", "ArnLike", "Null",
	}
	for _, base := range operators {
		for _, operator := range []string{base, "ForAnyValue:" + base, "ForAllValues:" + base} {
			evaluator, err := GetConditionEvaluator(operator)
			if err != nil {
				t.Fatalf("%s: %v", operator, err)
			}
			for _, contextValues := range [][]string{nil, {"x"}} {
				func() {
					defer func() {
						if r := recover(); r != nil {
							t.Errorf("%s with a nil value and context %v panicked: %v", operator, contextValues, r)
						}
					}()
					evaluator.Evaluate(nil, contextValues)
				}()
			}
		}
	}
}