mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-08-03 09:48:08 -04:00
style: apply structpack & goimport (#469)
* refactor: reorder import statements in fetch.go and fetch_test.go Signed-off-by: Jason Cameron <git@jasoncameron.dev> * fix: optimize struct field alignment to reduce memory usage Signed-off-by: Jason Cameron <git@jasoncameron.dev> --------- Signed-off-by: Jason Cameron <git@jasoncameron.dev>
This commit is contained in:
parent
8c7640aa09
commit
529f65674e
@ -159,11 +159,11 @@ func TestGetOGTagsWithHostConsideration(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
ogCacheConsiderHost bool
|
||||
requests []struct {
|
||||
host string
|
||||
expectedLoadCount int // Expected load count *after* this request
|
||||
expectedLoadCount int
|
||||
}
|
||||
ogCacheConsiderHost bool // Expected load count *after* this request
|
||||
}{
|
||||
{
|
||||
name: "Host Not Considered - Same Host",
|
||||
|
@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"golang.org/x/net/html"
|
||||
"io"
|
||||
"log/slog"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -2,7 +2,6 @@ package ogtags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"golang.org/x/net/html"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@ -10,6 +9,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
func TestFetchHTMLDocument(t *testing.T) {
|
||||
|
@ -56,10 +56,10 @@ func TestIntegrationGetOGTags(t *testing.T) {
|
||||
|
||||
// Test with different configurations
|
||||
testCases := []struct {
|
||||
expectedTags map[string]string
|
||||
name string
|
||||
path string
|
||||
query string
|
||||
expectedTags map[string]string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
|
@ -20,12 +20,12 @@ const (
|
||||
type OGTagCache struct {
|
||||
cache *decaymap.Impl[string, map[string]string]
|
||||
targetURL *url.URL
|
||||
ogCacheConsiderHost bool
|
||||
ogPassthrough bool
|
||||
ogTimeToLive time.Duration
|
||||
client *http.Client
|
||||
approvedTags []string
|
||||
approvedPrefixes []string
|
||||
client *http.Client
|
||||
ogTimeToLive time.Duration
|
||||
ogCacheConsiderHost bool
|
||||
ogPassthrough bool
|
||||
}
|
||||
|
||||
func NewOGTagCache(target string, ogPassthrough bool, ogTimeToLive time.Duration, ogTagsConsiderHost bool) *OGTagCache {
|
||||
|
@ -18,9 +18,9 @@ func TestExtractOGTags(t *testing.T) {
|
||||
testCache.approvedPrefixes = []string{"og:"}
|
||||
|
||||
tests := []struct {
|
||||
expected map[string]string
|
||||
name string
|
||||
htmlStr string
|
||||
expected map[string]string
|
||||
}{
|
||||
{
|
||||
name: "Basic OG tags", // Includes standard 'description' meta tag
|
||||
|
@ -106,8 +106,9 @@ type action string
|
||||
type testCase struct {
|
||||
name string
|
||||
action action
|
||||
realIP string
|
||||
userAgent string
|
||||
isHard bool
|
||||
realIP, userAgent string
|
||||
}
|
||||
|
||||
func doesNPXExist(t *testing.T) {
|
||||
|
@ -65,12 +65,12 @@ func TestXForwardedForUpdateAddToChain(t *testing.T) {
|
||||
|
||||
func TestComputeXFFHeader(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
err error
|
||||
name string
|
||||
remoteAddr string
|
||||
origXFFHeader string
|
||||
pref XFFComputePreferences
|
||||
result string
|
||||
err error
|
||||
pref XFFComputePreferences
|
||||
}{
|
||||
{
|
||||
name: "StripPrivate",
|
||||
|
@ -58,14 +58,14 @@ var (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
mux *http.ServeMux
|
||||
next http.Handler
|
||||
priv ed25519.PrivateKey
|
||||
pub ed25519.PublicKey
|
||||
mux *http.ServeMux
|
||||
policy *policy.ParsedConfig
|
||||
opts Options
|
||||
DNSBLCache *decaymap.Impl[string, dnsbl.DroneBLResponse]
|
||||
OGTags *ogtags.OGTagCache
|
||||
priv ed25519.PrivateKey
|
||||
pub ed25519.PublicKey
|
||||
opts Options
|
||||
}
|
||||
|
||||
func (s *Server) challengeFor(r *http.Request, difficulty int) string {
|
||||
@ -232,8 +232,8 @@ func (s *Server) MakeChallenge(w http.ResponseWriter, r *http.Request) {
|
||||
challenge := s.challengeFor(r, rule.Challenge.Difficulty)
|
||||
|
||||
err = encoder.Encode(struct {
|
||||
Challenge string `json:"challenge"`
|
||||
Rules *config.ChallengeRules `json:"rules"`
|
||||
Challenge string `json:"challenge"`
|
||||
}{
|
||||
Challenge: challenge,
|
||||
Rules: rule.Challenge,
|
||||
|
@ -25,22 +25,19 @@ import (
|
||||
type Options struct {
|
||||
Next http.Handler
|
||||
Policy *policy.ParsedConfig
|
||||
RedirectDomains []string
|
||||
ServeRobotsTXT bool
|
||||
PrivateKey ed25519.PrivateKey
|
||||
|
||||
CookieExpiration time.Duration
|
||||
Target string
|
||||
CookieDomain string
|
||||
CookieName string
|
||||
CookiePartitioned bool
|
||||
|
||||
OGPassthrough bool
|
||||
BasePrefix string
|
||||
WebmasterEmail string
|
||||
RedirectDomains []string
|
||||
PrivateKey ed25519.PrivateKey
|
||||
CookieExpiration time.Duration
|
||||
OGTimeToLive time.Duration
|
||||
OGCacheConsidersHost bool
|
||||
Target string
|
||||
|
||||
WebmasterEmail string
|
||||
BasePrefix string
|
||||
OGPassthrough bool
|
||||
CookiePartitioned bool
|
||||
ServeRobotsTXT bool
|
||||
}
|
||||
|
||||
func LoadPoliciesOrDefault(fname string, defaultDifficulty int) (*policy.ParsedConfig, error) {
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
type Bot struct {
|
||||
Rules Checker
|
||||
Challenge *config.ChallengeRules
|
||||
Name string
|
||||
Action config.Rule
|
||||
Challenge *config.ChallengeRules
|
||||
Rules Checker
|
||||
}
|
||||
|
||||
func (b Bot) Hash() string {
|
||||
|
@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
type CELChecker struct {
|
||||
src string
|
||||
program cel.Program
|
||||
src string
|
||||
}
|
||||
|
||||
func NewCELChecker(cfg *config.ExpressionOrList) (*CELChecker, error) {
|
||||
|
@ -8,11 +8,11 @@ import (
|
||||
|
||||
func TestRemoteAddrChecker(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
cidrs []string
|
||||
ip string
|
||||
ok bool
|
||||
err error
|
||||
name string
|
||||
ip string
|
||||
cidrs []string
|
||||
ok bool
|
||||
}{
|
||||
{
|
||||
name: "match_ipv4",
|
||||
@ -86,13 +86,13 @@ func TestRemoteAddrChecker(t *testing.T) {
|
||||
|
||||
func TestHeaderMatchesChecker(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
err error
|
||||
name string
|
||||
header string
|
||||
rexStr string
|
||||
reqHeaderKey string
|
||||
reqHeaderValue string
|
||||
ok bool
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "match",
|
||||
|
@ -51,15 +51,14 @@ const (
|
||||
)
|
||||
|
||||
type BotConfig struct {
|
||||
Name string `json:"name"`
|
||||
UserAgentRegex *string `json:"user_agent_regex"`
|
||||
PathRegex *string `json:"path_regex"`
|
||||
HeadersRegex map[string]string `json:"headers_regex"`
|
||||
RemoteAddr []string `json:"remote_addresses"`
|
||||
Expression *ExpressionOrList `json:"expression"`
|
||||
|
||||
Action Rule `json:"action"`
|
||||
Challenge *ChallengeRules `json:"challenge,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Action Rule `json:"action"`
|
||||
RemoteAddr []string `json:"remote_addresses"`
|
||||
}
|
||||
|
||||
func (b BotConfig) Zero() bool {
|
||||
@ -171,9 +170,9 @@ func (b BotConfig) Valid() error {
|
||||
}
|
||||
|
||||
type ChallengeRules struct {
|
||||
Algorithm Algorithm `json:"algorithm"`
|
||||
Difficulty int `json:"difficulty"`
|
||||
ReportAs int `json:"report_as"`
|
||||
Algorithm Algorithm `json:"algorithm"`
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -15,9 +15,9 @@ func p[V any](v V) *V { return &v }
|
||||
|
||||
func TestBotValid(t *testing.T) {
|
||||
var tests = []struct {
|
||||
err error
|
||||
name string
|
||||
bot BotConfig
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "simple user agent",
|
||||
@ -239,9 +239,9 @@ func TestConfigValidKnownGood(t *testing.T) {
|
||||
|
||||
func TestImportStatement(t *testing.T) {
|
||||
type testCase struct {
|
||||
err error
|
||||
name string
|
||||
importPath string
|
||||
err error
|
||||
}
|
||||
|
||||
var tests []testCase
|
||||
|
@ -8,11 +8,11 @@ import (
|
||||
|
||||
func TestExpressionOrListUnmarshal(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
inp string
|
||||
err error
|
||||
validErr error
|
||||
result *ExpressionOrList
|
||||
name string
|
||||
inp string
|
||||
}{
|
||||
{
|
||||
name: "simple",
|
||||
|
@ -14,11 +14,11 @@ func TestJoin(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
clauses []string
|
||||
op JoinOperator
|
||||
err error
|
||||
name string
|
||||
op JoinOperator
|
||||
resultStr string
|
||||
clauses []string
|
||||
}{
|
||||
{
|
||||
name: "no-clauses",
|
||||
|
@ -12,8 +12,8 @@ func Base(title string, body templ.Component) templ.Component {
|
||||
|
||||
func BaseWithChallengeAndOGTags(title string, body templ.Component, challenge string, rules *config.ChallengeRules, ogTags map[string]string) (templ.Component, error) {
|
||||
return base(title, body, struct {
|
||||
Challenge string `json:"challenge"`
|
||||
Rules *config.ChallengeRules `json:"rules"`
|
||||
Challenge string `json:"challenge"`
|
||||
}{
|
||||
Challenge: challenge,
|
||||
Rules: rules,
|
||||
|
Loading…
x
Reference in New Issue
Block a user