1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-17 04:30:03 +02:00

internal/types/blacklist.go: change Lookup to IsAllowed and add IsDenied

This commit is contained in:
Henrik Hautakoski 2024-07-13 15:54:35 +02:00
parent e2443dcd27
commit cbd3196cf9
3 changed files with 18 additions and 14 deletions

View file

@ -153,7 +153,7 @@ func (processor *ShipProcessor) proccessActionTrace(logger *log.Entry, trace *sh
}
// Check blacklist if we should skip this action
if processor.blacklist.Lookup(trace.Act.Account.String(), trace.Act.Name.String()) {
if !processor.blacklist.IsAllowed(trace.Act.Account.String(), trace.Act.Name.String()) {
logger.WithFields(log.Fields{
"contract": trace.Act.Account,
"action": trace.Act.Name,

View file

@ -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)
}

View file

@ -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"))
}