mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-17 05:44:57 +00:00
refactor: raise checker to be a subpackage of lib
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -28,12 +28,15 @@ import (
|
|||||||
"github.com/TecharoHQ/anubis/internal/dnsbl"
|
"github.com/TecharoHQ/anubis/internal/dnsbl"
|
||||||
"github.com/TecharoHQ/anubis/internal/ogtags"
|
"github.com/TecharoHQ/anubis/internal/ogtags"
|
||||||
"github.com/TecharoHQ/anubis/lib/challenge"
|
"github.com/TecharoHQ/anubis/lib/challenge"
|
||||||
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/localization"
|
"github.com/TecharoHQ/anubis/lib/localization"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy"
|
"github.com/TecharoHQ/anubis/lib/policy"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/config"
|
"github.com/TecharoHQ/anubis/lib/policy/config"
|
||||||
"github.com/TecharoHQ/anubis/lib/store"
|
"github.com/TecharoHQ/anubis/lib/store"
|
||||||
|
|
||||||
|
// checker implementations
|
||||||
|
_ "github.com/TecharoHQ/anubis/lib/checker/all"
|
||||||
|
|
||||||
// challenge implementations
|
// challenge implementations
|
||||||
_ "github.com/TecharoHQ/anubis/lib/challenge/metarefresh"
|
_ "github.com/TecharoHQ/anubis/lib/challenge/metarefresh"
|
||||||
_ "github.com/TecharoHQ/anubis/lib/challenge/proofofwork"
|
_ "github.com/TecharoHQ/anubis/lib/challenge/proofofwork"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package checker
|
package checker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -9,12 +10,17 @@ import (
|
|||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Impl interface {
|
var (
|
||||||
|
ErrUnparseableConfig = errors.New("checker: config is unparseable")
|
||||||
|
ErrInvalidConfig = errors.New("checker: config is invalid")
|
||||||
|
)
|
||||||
|
|
||||||
|
type Interface interface {
|
||||||
Check(*http.Request) (matches bool, err error)
|
Check(*http.Request) (matches bool, err error)
|
||||||
Hash() string
|
Hash() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type List []Impl
|
type List []Interface
|
||||||
|
|
||||||
func (l List) Check(r *http.Request) (bool, error) {
|
func (l List) Check(r *http.Request) (bool, error) {
|
||||||
for _, c := range l {
|
for _, c := range l {
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
package checker
|
package checker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Factory interface {
|
type Factory interface {
|
||||||
ValidateConfig(json.RawMessage) error
|
Build(context.Context, json.RawMessage) (Interface, error)
|
||||||
Create(json.RawMessage) (Impl, error)
|
Valid(context.Context, json.RawMessage) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -1,31 +1,34 @@
|
|||||||
package remoteaddress
|
package remoteaddress
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
|
"github.com/TecharoHQ/anubis"
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/config"
|
|
||||||
"github.com/gaissmai/bart"
|
"github.com/gaissmai/bart"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoRemoteAddresses = errors.New("remoteaddress: no remote addresses defined")
|
ErrNoRemoteAddresses = errors.New("remoteaddress: no remote addresses defined")
|
||||||
|
ErrInvalidCIDR = errors.New("remoteaddress: invalid CIDR")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {}
|
func init() {
|
||||||
|
checker.Register("remote_address", Factory{})
|
||||||
|
}
|
||||||
|
|
||||||
type Factory struct{}
|
type Factory struct{}
|
||||||
|
|
||||||
func (Factory) ValidateConfig(inp json.RawMessage) error {
|
func (Factory) Valid(_ context.Context, inp json.RawMessage) error {
|
||||||
var fc fileConfig
|
var fc fileConfig
|
||||||
if err := json.Unmarshal([]byte(inp), &fc); err != nil {
|
if err := json.Unmarshal([]byte(inp), &fc); err != nil {
|
||||||
return fmt.Errorf("%w: %w", config.ErrUnparseableConfig, err)
|
return fmt.Errorf("%w: %w", checker.ErrUnparseableConfig, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := fc.Valid(); err != nil {
|
if err := fc.Valid(); err != nil {
|
||||||
@@ -35,13 +38,13 @@ func (Factory) ValidateConfig(inp json.RawMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Factory) Create(inp json.RawMessage) (checker.Impl, error) {
|
func (Factory) Build(_ context.Context, inp json.RawMessage) (checker.Interface, error) {
|
||||||
c := struct {
|
c := struct {
|
||||||
RemoteAddr []netip.Prefix `json:"remote_addresses,omitempty" yaml:"remote_addresses,omitempty"`
|
RemoteAddr []netip.Prefix `json:"remote_addresses,omitempty" yaml:"remote_addresses,omitempty"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(inp), &c); err != nil {
|
if err := json.Unmarshal([]byte(inp), &c); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %w", config.ErrUnparseableConfig, err)
|
return nil, fmt.Errorf("%w: %w", checker.ErrUnparseableConfig, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
table := new(bart.Lite)
|
table := new(bart.Lite)
|
||||||
@@ -69,17 +72,29 @@ func (fc fileConfig) Valid() error {
|
|||||||
|
|
||||||
for _, cidr := range fc.RemoteAddr {
|
for _, cidr := range fc.RemoteAddr {
|
||||||
if _, err := netip.ParsePrefix(cidr); err != nil {
|
if _, err := netip.ParsePrefix(cidr); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("%w: cidr %q is invalid: %w", config.ErrInvalidCIDR, cidr, err))
|
errs = append(errs, fmt.Errorf("%w: cidr %q is invalid: %w", ErrInvalidCIDR, cidr, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) != 0 {
|
if len(errs) != 0 {
|
||||||
return fmt.Errorf("%w: %w", policy.ErrMisconfiguration, errors.Join(errs...))
|
return fmt.Errorf("%w: %w", checker.ErrInvalidConfig, errors.Join(errs...))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func New(cidrs []string) (checker.Interface, error) {
|
||||||
|
fc := fileConfig{
|
||||||
|
RemoteAddr: cidrs,
|
||||||
|
}
|
||||||
|
data, err := json.Marshal(fc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return Factory{}.Build(context.Background(), json.RawMessage(data))
|
||||||
|
}
|
||||||
|
|
||||||
type RemoteAddrChecker struct {
|
type RemoteAddrChecker struct {
|
||||||
prefixTable *bart.Lite
|
prefixTable *bart.Lite
|
||||||
hash string
|
hash string
|
||||||
@@ -88,12 +103,12 @@ type RemoteAddrChecker struct {
|
|||||||
func (rac *RemoteAddrChecker) Check(r *http.Request) (bool, error) {
|
func (rac *RemoteAddrChecker) Check(r *http.Request) (bool, error) {
|
||||||
host := r.Header.Get("X-Real-Ip")
|
host := r.Header.Get("X-Real-Ip")
|
||||||
if host == "" {
|
if host == "" {
|
||||||
return false, fmt.Errorf("%w: header X-Real-Ip is not set", policy.ErrMisconfiguration)
|
return false, fmt.Errorf("%w: header X-Real-Ip is not set", anubis.ErrMisconfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := netip.ParseAddr(host)
|
addr, err := netip.ParseAddr(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("%w: %s is not an IP address: %w", policy.ErrMisconfiguration, host, err)
|
return false, fmt.Errorf("%w: %s is not an IP address: %w", anubis.ErrMisconfiguration, host, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return rac.prefixTable.Contains(addr), nil
|
return rac.prefixTable.Contains(addr), nil
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/config"
|
"github.com/TecharoHQ/anubis/lib/policy/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ func TestFactoryValidateConfig(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
data := json.RawMessage(tt.data)
|
data := json.RawMessage(tt.data)
|
||||||
|
|
||||||
if err := f.ValidateConfig(data); !errors.Is(err, tt.err) {
|
if err := f.Valid(t.Context(), data); !errors.Is(err, tt.err) {
|
||||||
t.Logf("want: %v", tt.err)
|
t.Logf("want: %v", tt.err)
|
||||||
t.Logf("got: %v", err)
|
t.Logf("got: %v", err)
|
||||||
t.Fatal("validation didn't do what was expected")
|
t.Fatal("validation didn't do what was expected")
|
||||||
@@ -100,7 +100,7 @@ func TestFactoryCreate(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
data := json.RawMessage(tt.data)
|
data := json.RawMessage(tt.data)
|
||||||
|
|
||||||
impl, err := f.Create(data)
|
impl, err := f.Build(t.Context(), data)
|
||||||
if !errors.Is(err, tt.err) {
|
if !errors.Is(err, tt.err) {
|
||||||
t.Logf("want: %v", tt.err)
|
t.Logf("want: %v", tt.err)
|
||||||
t.Logf("got: %v", err)
|
t.Logf("got: %v", err)
|
||||||
@@ -136,81 +136,3 @@ func TestFactoryCreate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestRemoteAddrChecker(t *testing.T) {
|
|
||||||
// for _, tt := range []struct {
|
|
||||||
// err error
|
|
||||||
// name string
|
|
||||||
// ip string
|
|
||||||
// cidrs []string
|
|
||||||
// ok bool
|
|
||||||
// }{
|
|
||||||
// {
|
|
||||||
// name: "match_ipv4",
|
|
||||||
// cidrs: []string{"0.0.0.0/0"},
|
|
||||||
// ip: "1.1.1.1",
|
|
||||||
// ok: true,
|
|
||||||
// err: nil,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "match_ipv6",
|
|
||||||
// cidrs: []string{"::/0"},
|
|
||||||
// ip: "cafe:babe::",
|
|
||||||
// ok: true,
|
|
||||||
// err: nil,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "not_match_ipv4",
|
|
||||||
// cidrs: []string{"1.1.1.1/32"},
|
|
||||||
// ip: "1.1.1.2",
|
|
||||||
// ok: false,
|
|
||||||
// err: nil,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "not_match_ipv6",
|
|
||||||
// cidrs: []string{"cafe:babe::/128"},
|
|
||||||
// ip: "cafe:babe:4::/128",
|
|
||||||
// ok: false,
|
|
||||||
// err: nil,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "no_ip_set",
|
|
||||||
// cidrs: []string{"::/0"},
|
|
||||||
// ok: false,
|
|
||||||
// err: policy.ErrMisconfiguration,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "invalid_ip",
|
|
||||||
// cidrs: []string{"::/0"},
|
|
||||||
// ip: "According to all natural laws of aviation",
|
|
||||||
// ok: false,
|
|
||||||
// err: policy.ErrMisconfiguration,
|
|
||||||
// },
|
|
||||||
// } {
|
|
||||||
// t.Run(tt.name, func(t *testing.T) {
|
|
||||||
// rac, err := NewRemoteAddrChecker(tt.cidrs)
|
|
||||||
// if err != nil && !errors.Is(err, tt.err) {
|
|
||||||
// t.Fatalf("creating RemoteAddrChecker failed: %v", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// r, err := http.NewRequest(http.MethodGet, "/", nil)
|
|
||||||
// if err != nil {
|
|
||||||
// t.Fatalf("can't make request: %v", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if tt.ip != "" {
|
|
||||||
// r.Header.Add("X-Real-Ip", tt.ip)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ok, err := rac.Check(r)
|
|
||||||
|
|
||||||
// if tt.ok != ok {
|
|
||||||
// t.Errorf("ok: %v, wanted: %v", ok, tt.ok)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if err != nil && tt.err != nil && !errors.Is(err, tt.err) {
|
|
||||||
// t.Errorf("err: %v, wanted: %v", err, tt.err)
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -4,12 +4,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/config"
|
"github.com/TecharoHQ/anubis/lib/policy/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
Rules checker.Impl
|
Rules checker.Interface
|
||||||
Challenge *config.ChallengeRules
|
Challenge *config.ChallengeRules
|
||||||
Weight *config.Weight
|
Weight *config.Weight
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/TecharoHQ/anubis"
|
"github.com/TecharoHQ/anubis"
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/gaissmai/bart"
|
"github.com/gaissmai/bart"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ type RemoteAddrChecker struct {
|
|||||||
hash string
|
hash string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRemoteAddrChecker(cidrs []string) (checker.Impl, error) {
|
func NewRemoteAddrChecker(cidrs []string) (checker.Interface, error) {
|
||||||
table := new(bart.Lite)
|
table := new(bart.Lite)
|
||||||
|
|
||||||
for _, cidr := range cidrs {
|
for _, cidr := range cidrs {
|
||||||
@@ -61,11 +61,11 @@ type HeaderMatchesChecker struct {
|
|||||||
hash string
|
hash string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserAgentChecker(rexStr string) (checker.Impl, error) {
|
func NewUserAgentChecker(rexStr string) (checker.Interface, error) {
|
||||||
return NewHeaderMatchesChecker("User-Agent", rexStr)
|
return NewHeaderMatchesChecker("User-Agent", rexStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHeaderMatchesChecker(header, rexStr string) (checker.Impl, error) {
|
func NewHeaderMatchesChecker(header, rexStr string) (checker.Interface, error) {
|
||||||
rex, err := regexp.Compile(strings.TrimSpace(rexStr))
|
rex, err := regexp.Compile(strings.TrimSpace(rexStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: regex %s failed parse: %w", anubis.ErrMisconfiguration, rexStr, err)
|
return nil, fmt.Errorf("%w: regex %s failed parse: %w", anubis.ErrMisconfiguration, rexStr, err)
|
||||||
@@ -90,7 +90,7 @@ type PathChecker struct {
|
|||||||
hash string
|
hash string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPathChecker(rexStr string) (checker.Impl, error) {
|
func NewPathChecker(rexStr string) (checker.Interface, error) {
|
||||||
rex, err := regexp.Compile(strings.TrimSpace(rexStr))
|
rex, err := regexp.Compile(strings.TrimSpace(rexStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%w: regex %s failed parse: %w", anubis.ErrMisconfiguration, rexStr, err)
|
return nil, fmt.Errorf("%w: regex %s failed parse: %w", anubis.ErrMisconfiguration, rexStr, err)
|
||||||
@@ -110,7 +110,7 @@ func (pc *PathChecker) Hash() string {
|
|||||||
return pc.hash
|
return pc.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHeaderExistsChecker(key string) checker.Impl {
|
func NewHeaderExistsChecker(key string) checker.Interface {
|
||||||
return headerExistsChecker{strings.TrimSpace(key)}
|
return headerExistsChecker{strings.TrimSpace(key)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ func (hec headerExistsChecker) Hash() string {
|
|||||||
return internal.FastHash(hec.header)
|
return internal.FastHash(hec.header)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHeadersChecker(headermap map[string]string) (checker.Impl, error) {
|
func NewHeadersChecker(headermap map[string]string) (checker.Interface, error) {
|
||||||
var result checker.List
|
var result checker.List
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TecharoHQ/anubis"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoteAddrChecker(t *testing.T) {
|
func TestRemoteAddrChecker(t *testing.T) {
|
||||||
@@ -46,14 +48,14 @@ func TestRemoteAddrChecker(t *testing.T) {
|
|||||||
name: "no_ip_set",
|
name: "no_ip_set",
|
||||||
cidrs: []string{"::/0"},
|
cidrs: []string{"::/0"},
|
||||||
ok: false,
|
ok: false,
|
||||||
err: ErrMisconfiguration,
|
err: anubis.ErrMisconfiguration,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid_ip",
|
name: "invalid_ip",
|
||||||
cidrs: []string{"::/0"},
|
cidrs: []string{"::/0"},
|
||||||
ip: "According to all natural laws of aviation",
|
ip: "According to all natural laws of aviation",
|
||||||
ok: false,
|
ok: false,
|
||||||
err: ErrMisconfiguration,
|
err: anubis.ErrMisconfiguration,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@@ -124,7 +126,7 @@ func TestHeaderMatchesChecker(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid_regex",
|
name: "invalid_regex",
|
||||||
rexStr: "a(b",
|
rexStr: "a(b",
|
||||||
err: ErrMisconfiguration,
|
err: anubis.ErrMisconfiguration,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/config"
|
"github.com/TecharoHQ/anubis/lib/policy/config"
|
||||||
"github.com/TecharoHQ/anubis/lib/store"
|
"github.com/TecharoHQ/anubis/lib/store"
|
||||||
"github.com/TecharoHQ/anubis/lib/thoth"
|
"github.com/TecharoHQ/anubis/lib/thoth"
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
iptoasnv1 "github.com/TecharoHQ/thoth-proto/gen/techaro/thoth/iptoasn/v1"
|
iptoasnv1 "github.com/TecharoHQ/thoth-proto/gen/techaro/thoth/iptoasn/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) ASNCheckerFor(asns []uint32) checker.Impl {
|
func (c *Client) ASNCheckerFor(asns []uint32) checker.Interface {
|
||||||
asnMap := map[uint32]struct{}{}
|
asnMap := map[uint32]struct{}{}
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
fmt.Fprintln(&sb, "ASNChecker")
|
fmt.Fprintln(&sb, "ASNChecker")
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/thoth"
|
"github.com/TecharoHQ/anubis/lib/thoth"
|
||||||
iptoasnv1 "github.com/TecharoHQ/thoth-proto/gen/techaro/thoth/iptoasn/v1"
|
iptoasnv1 "github.com/TecharoHQ/thoth-proto/gen/techaro/thoth/iptoasn/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ checker.Impl = &thoth.ASNChecker{}
|
var _ checker.Interface = &thoth.ASNChecker{}
|
||||||
|
|
||||||
func TestASNChecker(t *testing.T) {
|
func TestASNChecker(t *testing.T) {
|
||||||
cli := loadSecrets(t)
|
cli := loadSecrets(t)
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
iptoasnv1 "github.com/TecharoHQ/thoth-proto/gen/techaro/thoth/iptoasn/v1"
|
iptoasnv1 "github.com/TecharoHQ/thoth-proto/gen/techaro/thoth/iptoasn/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) GeoIPCheckerFor(countries []string) checker.Impl {
|
func (c *Client) GeoIPCheckerFor(countries []string) checker.Interface {
|
||||||
countryMap := map[string]struct{}{}
|
countryMap := map[string]struct{}{}
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
fmt.Fprintln(&sb, "GeoIPChecker")
|
fmt.Fprintln(&sb, "GeoIPChecker")
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
"github.com/TecharoHQ/anubis/lib/checker"
|
||||||
"github.com/TecharoHQ/anubis/lib/thoth"
|
"github.com/TecharoHQ/anubis/lib/thoth"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ checker.Impl = &thoth.GeoIPChecker{}
|
var _ checker.Interface = &thoth.GeoIPChecker{}
|
||||||
|
|
||||||
func TestGeoIPChecker(t *testing.T) {
|
func TestGeoIPChecker(t *testing.T) {
|
||||||
cli := loadSecrets(t)
|
cli := loadSecrets(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user