Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug] Integers passed into 'Enforce' is treated as strings  #868

@ComradeProgrammer

Description

@ComradeProgrammer

Describe the bug
I found that integers passed into 'Enforce' are treated as strings ,which caused '<' and '>' operators in model cannot work as users' expectation

To Reproduce
Steps to reproduce the behavior:

  1. Use this model
[request_definition]
r = namespace, cpu, memory

[policy_definition]
p = namespace, cpu, memory, eft

[policy_effect]
e=!some(where (p.eft == deny))

[matchers]
m= r.namespace == p.namespace && ( r.cpu > p.cpu || r.memory > p.memory ) 
  1. Use the following policy
    p,default,104857600,104857600,deny
  2. Run the following golang code
package main

import (
	"fmt"
	casbin "github.com/casbin/casbin/v2"
)

func main() {
	enforcer, _ := casbin.NewEnforcer("container_resource_limit.conf","container_resource_limit.csv")
	res,err:=enforcer.Enforce("default",10000,10000)
	fmt.Println(err.Error())
	fmt.Println(res)
}
  1. See the following error in output
    PS D:\workspace\vscode\golang> go run . Value '10000' cannot be used with the comparator '>', it is not a number false

Expected behavior
The operator '>' should have worked.

Desktop (please complete the following information):

  • OS: Both Windows 10 and Windows WSL2
  • Golang: go 1.16
  • Casbin Version v2.36.1

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions