Replace per-source enable booleans with SourcePrecheck and bump SDK to v1.9.0
Sources that always work (botvrij, disconnect, oisd, openphish, phishtank, quad9) drop their user-facing enable_* option; the rule's enabled/disabled state is now solely controlled by the SDK rule toggle. Sources that require credentials (criminalip, malwarebazaar, otx, pulsedive, safebrowsing, threatfox, urlhaus, virustotal) instead implement the new SourcePrecheck interface so the host UI can surface "not configured" before attempting a query.
This commit is contained in:
parent
ce59a976d5
commit
c3cda1f104
25 changed files with 189 additions and 175 deletions
|
|
@ -6,8 +6,6 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
const disconnectFakeFeed = `{
|
||||
|
|
@ -42,7 +40,7 @@ func TestDisconnectSource_Listed(t *testing.T) {
|
|||
defer srv.Close()
|
||||
|
||||
s := newDisconnectTestSource(srv)
|
||||
r := s.Query(context.Background(), "tracker.com", "tracker.com", sdk.CheckerOptions{"enable_disconnect": true})[0]
|
||||
r := s.Query(context.Background(), "tracker.com", "tracker.com", nil)[0]
|
||||
|
||||
if !r.Enabled || r.Error != "" {
|
||||
t.Fatalf("expected enabled with no error, got %+v", r)
|
||||
|
|
@ -75,7 +73,7 @@ func TestDisconnectSource_SubdomainInFeed(t *testing.T) {
|
|||
|
||||
// Feed has "sub.example.org"; querying registered domain "example.org" should match.
|
||||
s := newDisconnectTestSource(srv)
|
||||
r := s.Query(context.Background(), "example.org", "example.org", sdk.CheckerOptions{"enable_disconnect": true})[0]
|
||||
r := s.Query(context.Background(), "example.org", "example.org", nil)[0]
|
||||
|
||||
if !r.Enabled || r.Error != "" {
|
||||
t.Fatalf("expected enabled with no error, got %+v", r)
|
||||
|
|
@ -92,7 +90,7 @@ func TestDisconnectSource_NotListed(t *testing.T) {
|
|||
defer srv.Close()
|
||||
|
||||
s := newDisconnectTestSource(srv)
|
||||
r := s.Query(context.Background(), "clean.example.com", "clean.example.com", sdk.CheckerOptions{"enable_disconnect": true})[0]
|
||||
r := s.Query(context.Background(), "clean.example.com", "clean.example.com", nil)[0]
|
||||
|
||||
if !r.Enabled || r.Error != "" {
|
||||
t.Fatalf("expected enabled with no error, got %+v", r)
|
||||
|
|
@ -105,14 +103,6 @@ func TestDisconnectSource_NotListed(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDisconnectSource_Disabled(t *testing.T) {
|
||||
s := &disconnectSource{cache: newFeedCache(time.Hour, disconnectFetch("http://nope"))}
|
||||
r := s.Query(context.Background(), "tracker.com", "tracker.com", sdk.CheckerOptions{"enable_disconnect": false})[0]
|
||||
if r.Enabled {
|
||||
t.Errorf("expected disabled result, got %+v", r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisconnectSource_HTTPError(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
@ -120,7 +110,7 @@ func TestDisconnectSource_HTTPError(t *testing.T) {
|
|||
defer srv.Close()
|
||||
|
||||
s := newDisconnectTestSource(srv)
|
||||
r := s.Query(context.Background(), "tracker.com", "tracker.com", sdk.CheckerOptions{"enable_disconnect": true})[0]
|
||||
r := s.Query(context.Background(), "tracker.com", "tracker.com", nil)[0]
|
||||
if r.Error == "" {
|
||||
t.Errorf("expected error on HTTP 500, got empty error")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue