Skip to content

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

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

Activity

  1. sagilio commented on Aug 17, 2021

    @sagilio
    Member

    @closetool @tangyang9464

  2. changed the title [-][Bug] Integers passing into 'Enforce' is treated as strings [/-] [+][Bug] Integers passed into 'Enforce' is treated as strings [/+] on Aug 17, 2021
  3. kilosonc commented on Aug 18, 2021

    @kilosonc
    Contributor

    @sagilio @ComradeProgrammer This matcher is not supported. Could replace by eval, https://casbin.org/docs/en/abac

  4. hsluoyz commented on Aug 18, 2021

    @hsluoyz
    Member

    @ComradeProgrammer elements like r.cpu will be treated as string. You need to define a custom function like parseInt() to do type conversion.

  5. sagilio commented on Aug 18, 2021

    @sagilio
    Member

    @hsluoyz The custom function ParseFloat() has been used on this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions