Skip to content
Open
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
8 changes: 2 additions & 6 deletions errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"slices"
"strconv"
"strings"
)
Expand Down Expand Up @@ -113,12 +114,7 @@ func checkApplicability(err ScimError, method string) bool {
return false
}

for _, m := range methods {
if m == method {
return true
}
}
return false
return slices.Contains(methods, method)
}

// ScimError is a SCIM error response to indicate operation success or failure.
Expand Down
10 changes: 5 additions & 5 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (v Validator) GetFilter() filter.Expression {
}

// PassesFilter checks whether given resources passes the filter.
func (v Validator) PassesFilter(resource map[string]interface{}) error {
func (v Validator) PassesFilter(resource map[string]any) error {
switch e := v.filter.(type) {
case *filter.ValuePath:
ref, attr, ok := v.referenceContains(e.AttributePath)
Expand All @@ -144,9 +144,9 @@ func (v Validator) PassesFilter(resource map[string]interface{}) error {
},
}
switch value := value.(type) {
case []interface{}:
case []any:
for _, a := range value {
attr, ok := a.(map[string]interface{})
attr, ok := a.(map[string]any)
if !ok {
return fmt.Errorf("the target is not a complex attribute")
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func (v Validator) PassesFilter(resource map[string]interface{}) error {
return fmt.Errorf("the resource has no sub-attribute named: %s", subAttrName)
}

attr, ok := value.(map[string]interface{})
attr, ok := value.(map[string]any)
if !ok {
return fmt.Errorf("the target is not a complex attribute")
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (v Validator) PassesFilter(resource map[string]interface{}) error {
}

switch value := value.(type) {
case []interface{}:
case []any:
var err error
for _, v := range value {
if err = cmp(v); err == nil {
Expand Down
46 changes: 23 additions & 23 deletions filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@ func TestValidator_PassesFilter(t *testing.T) {
t.Run("simple", func(t *testing.T) {
for _, test := range []struct {
filter string
valid map[string]interface{}
invalid map[string]interface{}
valid map[string]any
invalid map[string]any
}{
{
filter: `userName eq "john"`,
valid: map[string]interface{}{
valid: map[string]any{
"userName": "john",
},
invalid: map[string]interface{}{
invalid: map[string]any{
"userName": "doe",
},
},
{
filter: `emails[type eq "work"]`,
valid: map[string]interface{}{
"emails": []interface{}{
map[string]interface{}{
valid: map[string]any{
"emails": []any{
map[string]any{
"type": "work",
},
},
},
invalid: map[string]interface{}{
"emails": []interface{}{
map[string]interface{}{
invalid: map[string]any{
"emails": []any{
map[string]any{
"type": "private",
},
},
Expand Down Expand Up @@ -222,36 +222,36 @@ func TestValidator_Validate(t *testing.T) {
}
}

func testResources() []map[string]interface{} {
return []map[string]interface{}{
func testResources() []map[string]any {
return []map[string]any{
{
"schemas": []interface{}{
"schemas": []any{
"urn:ietf:params:scim:schemas:core:2.0:User",
},
"userName": "di-wu",
"userType": "admin",
"name": map[string]interface{}{
"name": map[string]any{
"familyName": "di",
"givenName": "wu",
},
"emails": []interface{}{
map[string]interface{}{
"emails": []any{
map[string]any{
"value": "quint@elimity.com",
"type": "work",
},
},
"meta": map[string]interface{}{
"meta": map[string]any{
"lastModified": "2020-07-26T20:02:34Z",
},
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:organization": "Elimity",
},
{
"schemas": []interface{}{
"schemas": []any{
"urn:ietf:params:scim:schemas:core:2.0:User",
},
"userName": "noreply",
"emails": []interface{}{
map[string]interface{}{
"emails": []any{
map[string]any{
"value": "noreply@elimity.com",
"type": "work",
},
Expand All @@ -260,18 +260,18 @@ func testResources() []map[string]interface{} {
{
"userName": "admin",
"userType": "admin",
"name": map[string]interface{}{
"name": map[string]any{
"familyName": "ad",
"givenName": "min",
},
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:manager": map[string]interface{}{
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:manager": map[string]any{
"displayName": "di-wu",
},
},
{"userName": "guest"},
{
"userName": "unknown",
"name": map[string]interface{}{
"name": map[string]any{
"familyName": "un",
"givenName": "known",
},
Expand Down
2 changes: 1 addition & 1 deletion filter/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
//
// Expects a binary attribute. Will panic on unknown filter operator.
// Known operators: eq, ne, co, sw, ew, gt, lt, ge and le.
func cmpBinary(e *filter.AttributeExpression, ref string) (func(interface{}) error, error) {
func cmpBinary(e *filter.AttributeExpression, ref string) (func(any) error, error) {
switch op := e.Operator; op {
case filter.EQ:
return cmpStr(ref, true, func(v, ref string) error {
Expand Down
10 changes: 5 additions & 5 deletions filter/op_boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"
)

func cmpBool(ref bool, cmp func(v, ref bool) error) func(interface{}) error {
return func(i interface{}) error {
func cmpBool(ref bool, cmp func(v, ref bool) error) func(any) error {
return func(i any) error {
value, ok := i.(bool)
if !ok {
panic(fmt.Sprintf("given value is not a boolean: %v", i))
Expand All @@ -17,8 +17,8 @@ func cmpBool(ref bool, cmp func(v, ref bool) error) func(interface{}) error {
}
}

func cmpBoolStr(ref bool, cmp func(v, ref string) error) (func(interface{}) error, error) {
return func(i interface{}) error {
func cmpBoolStr(ref bool, cmp func(v, ref string) error) (func(any) error, error) {
return func(i any) error {
if _, ok := i.(bool); !ok {
panic(fmt.Sprintf("given value is not a boolean: %v", i))
}
Expand All @@ -32,7 +32,7 @@ func cmpBoolStr(ref bool, cmp func(v, ref string) error) (func(interface{}) erro
//
// Expects a boolean attribute. Will panic on unknown filter operator.
// Known operators: eq, ne, co, sw, ew, gt, lt, ge and le.
func cmpBoolean(e *filter.AttributeExpression, attr schema.CoreAttribute, ref bool) (func(interface{}) error, error) {
func cmpBoolean(e *filter.AttributeExpression, attr schema.CoreAttribute, ref bool) (func(any) error, error) {
switch op := e.Operator; op {
case filter.EQ:
return cmpBool(ref, func(v, ref bool) error {
Expand Down
2 changes: 1 addition & 1 deletion filter/op_boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestValidatorBoolean(t *testing.T) {
})),
},
}
attr = map[string]interface{}{
attr = map[string]any{
"bool": true,
}
)
Expand Down
6 changes: 3 additions & 3 deletions filter/op_datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
//
// Expects a dateTime attribute. Will panic on unknown filter operator.
// Known operators: eq, ne, co, sw, ew, gt, lt, ge and le.
func cmpDateTime(e *filter.AttributeExpression, date string, ref time.Time) (func(interface{}) error, error) {
func cmpDateTime(e *filter.AttributeExpression, date string, ref time.Time) (func(any) error, error) {
switch op := e.Operator; op {
case filter.EQ:
return cmpTime(ref, func(v, ref time.Time) error {
Expand Down Expand Up @@ -83,8 +83,8 @@ func cmpDateTime(e *filter.AttributeExpression, date string, ref time.Time) (fun
}
}

func cmpTime(ref time.Time, cmp func(v, ref time.Time) error) func(interface{}) error {
return func(i interface{}) error {
func cmpTime(ref time.Time, cmp func(v, ref time.Time) error) func(any) error {
return func(i any) error {
date, ok := i.(string)
if !ok {
panic(fmt.Sprintf("given value is not a string: %v", i))
Expand Down
2 changes: 1 addition & 1 deletion filter/op_datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestValidatorDateTime(t *testing.T) {
})),
},
}
attrs = [3]map[string]interface{}{
attrs = [3]map[string]any{
{"time": "2021-01-01T08:00:00Z"}, // before
{"time": "2021-01-01T12:00:00Z"}, // equal
{"time": "2021-01-01T16:00:00Z"}, // after
Expand Down
10 changes: 5 additions & 5 deletions filter/op_decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
//
// Expects a decimal attribute. Will panic on unknown filter operator.
// Known operators: eq, ne, co, sw, ew, gt, lt, ge and le.
func cmpDecimal(e *filter.AttributeExpression, ref float64) (func(interface{}) error, error) {
func cmpDecimal(e *filter.AttributeExpression, ref float64) (func(any) error, error) {
switch op := e.Operator; op {
case filter.EQ:
return cmpFloat(ref, func(v, ref float64) error {
Expand Down Expand Up @@ -81,8 +81,8 @@ func cmpDecimal(e *filter.AttributeExpression, ref float64) (func(interface{}) e
}
}

func cmpFloat(ref float64, cmp func(v, ref float64) error) func(interface{}) error {
return func(i interface{}) error {
func cmpFloat(ref float64, cmp func(v, ref float64) error) func(any) error {
return func(i any) error {
f, ok := i.(float64)
if !ok {
panic(fmt.Sprintf("given value is not a float: %v", i))
Expand All @@ -91,8 +91,8 @@ func cmpFloat(ref float64, cmp func(v, ref float64) error) func(interface{}) err
}
}

func cmpFloatStr(ref float64, cmp func(v, ref string) error) (func(interface{}) error, error) {
return func(i interface{}) error {
func cmpFloatStr(ref float64, cmp func(v, ref string) error) (func(any) error, error) {
return func(i any) error {
if _, ok := i.(float64); !ok {
panic(fmt.Sprintf("given value is not a float: %v", i))
}
Expand Down
2 changes: 1 addition & 1 deletion filter/op_decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestValidatorDecimal(t *testing.T) {
})),
},
}
attrs = [3]map[string]interface{}{
attrs = [3]map[string]any{
{"dec": -0.1}, // less
{"dec": float64(1)}, // equal
{"dec": 1.1}, // greater
Expand Down
10 changes: 5 additions & 5 deletions filter/op_integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
)

func cmpInt(ref int, cmp func(v, ref int) error) func(interface{}) error {
return func(i interface{}) error {
func cmpInt(ref int, cmp func(v, ref int) error) func(any) error {
return func(i any) error {
v, ok := i.(int)
if !ok {
panic(fmt.Sprintf("given value is not an integer: %v", i))
Expand All @@ -16,8 +16,8 @@ func cmpInt(ref int, cmp func(v, ref int) error) func(interface{}) error {
}
}

func cmpIntStr(ref int, cmp func(v, ref string) error) (func(interface{}) error, error) {
return func(i interface{}) error {
func cmpIntStr(ref int, cmp func(v, ref string) error) (func(any) error, error) {
return func(i any) error {
if _, ok := i.(int); !ok {
panic(fmt.Sprintf("given value is not an integer: %v", i))
}
Expand All @@ -30,7 +30,7 @@ func cmpIntStr(ref int, cmp func(v, ref string) error) (func(interface{}) error,
//
// Expects a integer attribute. Will panic on unknown filter operator.
// Known operators: eq, ne, co, sw, ew, gt, lt, ge and le.
func cmpInteger(e *filter.AttributeExpression, ref int) (func(interface{}) error, error) {
func cmpInteger(e *filter.AttributeExpression, ref int) (func(any) error, error) {
switch op := e.Operator; op {
case filter.EQ:
return cmpInt(ref, func(v, ref int) error {
Expand Down
2 changes: 1 addition & 1 deletion filter/op_integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestValidatorInteger(t *testing.T) {
})),
},
}
attrs = [3]map[string]interface{}{
attrs = [3]map[string]any{
{"int": -1}, // less
{"int": 0}, // equal
{"int": 10}, // greater
Expand Down
8 changes: 4 additions & 4 deletions filter/op_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
"strings"
)

func cmpStr(ref string, caseExact bool, cmp func(v, ref string) error) (func(interface{}) error, error) {
func cmpStr(ref string, caseExact bool, cmp func(v, ref string) error) (func(any) error, error) {
if caseExact {
return func(i interface{}) error {
return func(i any) error {
value, ok := i.(string)
if !ok {
panic(fmt.Sprintf("given value is not a string: %v", i))
}
return cmp(value, ref)
}, nil
}
return func(i interface{}) error {
return func(i any) error {
value, ok := i.(string)
if !ok {
panic(fmt.Sprintf("given value is not a string: %v", i))
Expand All @@ -31,7 +31,7 @@ func cmpStr(ref string, caseExact bool, cmp func(v, ref string) error) (func(int
//
// Expects a string/reference attribute. Will panic on unknown filter operator.
// Known operators: eq, ne, co, sw, ew, gt, lt, ge and le.
func cmpString(e *filter.AttributeExpression, attr schema.CoreAttribute, ref string) (func(interface{}) error, error) {
func cmpString(e *filter.AttributeExpression, attr schema.CoreAttribute, ref string) (func(any) error, error) {
switch op := e.Operator; op {
case filter.EQ:
return cmpStr(ref, attr.CaseExact(), func(v, ref string) error {
Expand Down
2 changes: 1 addition & 1 deletion filter/op_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestValidatorString(t *testing.T) {
exp = func(op filter.CompareOperator) string {
return fmt.Sprintf("str %s \"x\"", op)
}
attrs = [3]map[string]interface{}{
attrs = [3]map[string]any{
{"str": "x"},
{"str": "X"},
{"str": "y"},
Expand Down
2 changes: 1 addition & 1 deletion filter/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// createCompareFunction returns a compare function based on the attribute expression and attribute.
// e.g. `userName eq "john"` will return a string comparator that checks whether the passed value is equal to "john".
func createCompareFunction(e *filter.AttributeExpression, attr schema.CoreAttribute) (func(interface{}) error, error) {
func createCompareFunction(e *filter.AttributeExpression, attr schema.CoreAttribute) (func(any) error, error) {
switch typ := attr.AttributeType(); typ {
case "binary":
ref, ok := e.CompareValue.(string)
Expand Down
Loading