mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-19 04:50:02 +02:00
internal/types/blacklist.go: change Lookup to IsAllowed and add IsDenied
This commit is contained in:
parent
e2443dcd27
commit
cbd3196cf9
3 changed files with 18 additions and 14 deletions
|
|
@ -9,13 +9,17 @@ func (bl Blacklist) Add(contract string, action string) {
|
|||
bl[contract] = append(bl[contract], action)
|
||||
}
|
||||
|
||||
func (bl Blacklist) Lookup(contract string, action string) bool {
|
||||
func (bl Blacklist) IsAllowed(contract string, action string) bool {
|
||||
if v, ok := bl[contract]; ok {
|
||||
for _, act := range v {
|
||||
if act == action || act == "*" {
|
||||
return true
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
func (bl Blacklist) IsDenied(contract string, action string) bool {
|
||||
return bl.IsAllowed(contract, action)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,24 +20,24 @@ func TestBlacklist_Add(t *testing.T) {
|
|||
require.Equal(t, expected, bl)
|
||||
}
|
||||
|
||||
func TestBlacklist_Lookup(t *testing.T) {
|
||||
func TestBlacklist_IsAllowed(t *testing.T) {
|
||||
bl := Blacklist{
|
||||
"mycontract": {"myaction", "noop"},
|
||||
}
|
||||
|
||||
require.True(t, bl.Lookup("mycontract", "myaction"))
|
||||
require.True(t, bl.Lookup("mycontract", "noop"))
|
||||
require.False(t, bl.Lookup("mycontract", "xxx"))
|
||||
require.False(t, bl.Lookup("xxx", "yyy"))
|
||||
require.False(t, bl.IsAllowed("mycontract", "myaction"))
|
||||
require.False(t, bl.IsAllowed("mycontract", "noop"))
|
||||
require.True(t, bl.IsAllowed("mycontract", "xxx"))
|
||||
require.True(t, bl.IsAllowed("xxx", "yyy"))
|
||||
}
|
||||
|
||||
func TestBlacklist_LookupWildcard(t *testing.T) {
|
||||
func TestBlacklist_IsAllowedWildcard(t *testing.T) {
|
||||
bl := Blacklist{
|
||||
"mycontract": {"*"},
|
||||
}
|
||||
|
||||
require.True(t, bl.Lookup("mycontract", "myaction"))
|
||||
require.True(t, bl.Lookup("mycontract", "noop"))
|
||||
require.True(t, bl.Lookup("mycontract", "xxx"))
|
||||
require.False(t, bl.Lookup("xxx", "yyy"))
|
||||
require.False(t, bl.IsAllowed("mycontract", "myaction"))
|
||||
require.False(t, bl.IsAllowed("mycontract", "noop"))
|
||||
require.False(t, bl.IsAllowed("mycontract", "xxx"))
|
||||
require.True(t, bl.IsAllowed("xxx", "yyy"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue