Compare commits

..

4 Commits

31 changed files with 115 additions and 134 deletions

View File

@@ -22,9 +22,9 @@ type TestCase struct {
type TestOptions struct { type TestOptions struct {
format string format string
action string action string
crawlDelayWeight int
policyName string policyName string
deniedAction string deniedAction string
crawlDelayWeight int
} }
func TestDataFileConversion(t *testing.T) { func TestDataFileConversion(t *testing.T) {

View File

@@ -13,13 +13,13 @@ func Zilch[T any]() T {
// Impl is a lazy key->value map. It's a wrapper around a map and a mutex. If values exceed their time-to-live, they are pruned at Get time. // Impl is a lazy key->value map. It's a wrapper around a map and a mutex. If values exceed their time-to-live, they are pruned at Get time.
type Impl[K comparable, V any] struct { type Impl[K comparable, V any] struct {
data map[K]decayMapEntry[V] data map[K]decayMapEntry[V]
lock sync.RWMutex
// deleteCh receives decay-deletion requests from readers. // deleteCh receives decay-deletion requests from readers.
deleteCh chan deleteReq[K] deleteCh chan deleteReq[K]
// stopCh stops the background cleanup worker. // stopCh stops the background cleanup worker.
stopCh chan struct{} stopCh chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
lock sync.RWMutex
} }
type decayMapEntry[V any] struct { type decayMapEntry[V any] struct {

View File

@@ -21,7 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow Renovate as an OCI registry client. - Allow Renovate as an OCI registry client.
- Properly handle 4in6 addresses so that IP matching works with those addresses. - Properly handle 4in6 addresses so that IP matching works with those addresses.
- Add support to simple Valkey/Redis cluster mode - Add support to simple Valkey/Redis cluster mode
- Stabilize the CVE-2025-24369 regression test by always submitting an invalid proof instead of relying on random POW failures.
## v1.23.1: Lyse Hext - Echo 1 ## v1.23.1: Lyse Hext - Echo 1

View File

@@ -55,9 +55,8 @@ server {
# proxy all traffic to the target via Anubis. # proxy all traffic to the target via Anubis.
server { server {
# Listen on TCP port 443 with TLS (https) and HTTP/2 # Listen on TCP port 443 with TLS (https) and HTTP/2
listen 443 ssl; listen 443 ssl http2;
listen [::]:443 ssl; listen [::]:443 ssl http2;
http2 on;
location / { location / {
proxy_set_header Host $host; proxy_set_header Host $host;
@@ -114,9 +113,8 @@ Then in a server block:
server { server {
# Listen on 443 with SSL # Listen on 443 with SSL
listen 443 ssl; listen 443 ssl http2;
listen [::]:443 ssl; listen [::]:443 ssl http2;
http2 on;
# Slipstream via Anubis # Slipstream via Anubis
include "conf-anubis.inc"; include "conf-anubis.inc";

View File

@@ -87,7 +87,7 @@ func XForwardedForToXRealIP(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if xffHeader := r.Header.Get("X-Forwarded-For"); r.Header.Get("X-Real-Ip") == "" && xffHeader != "" { if xffHeader := r.Header.Get("X-Forwarded-For"); r.Header.Get("X-Real-Ip") == "" && xffHeader != "" {
ip := xff.Parse(xffHeader) ip := xff.Parse(xffHeader)
slog.Debug("setting X-Real-Ip from X-Forwarded-For", "to", ip, "x-forwarded-for", xffHeader) slog.Debug("setting x-real-ip", "val", ip)
r.Header.Set("X-Real-Ip", ip) r.Header.Set("X-Real-Ip", ip)
} }
@@ -129,8 +129,6 @@ func XForwardedForUpdate(stripPrivate bool, next http.Handler) http.Handler {
} else { } else {
r.Header.Set("X-Forwarded-For", xffHeaderString) r.Header.Set("X-Forwarded-For", xffHeaderString)
} }
slog.Debug("updating X-Forwarded-For", "original", origXFFHeader, "new", xffHeaderString)
}) })
} }

View File

@@ -22,10 +22,9 @@ const (
) )
type OGTagCache struct { type OGTagCache struct {
targetURL *url.URL cache store.JSON[map[string]string]
client *http.Client targetURL *url.URL
ogOverride map[string]string client *http.Client
cache store.JSON[map[string]string]
// Pre-built strings for optimization // Pre-built strings for optimization
unixPrefix string // "http://unix" unixPrefix string // "http://unix"
@@ -34,6 +33,7 @@ type OGTagCache struct {
ogTimeToLive time.Duration ogTimeToLive time.Duration
ogCacheConsiderHost bool ogCacheConsiderHost bool
ogPassthrough bool ogPassthrough bool
ogOverride map[string]string
} }
func NewOGTagCache(target string, conf config.OpenGraph, backend store.Interface) *OGTagCache { func NewOGTagCache(target string, conf config.OpenGraph, backend store.Interface) *OGTagCache {

View File

@@ -68,14 +68,14 @@ var (
type Server struct { type Server struct {
next http.Handler next http.Handler
store store.Interface
mux *http.ServeMux mux *http.ServeMux
policy *policy.ParsedConfig policy *policy.ParsedConfig
OGTags *ogtags.OGTagCache OGTags *ogtags.OGTagCache
logger *slog.Logger
opts Options
ed25519Priv ed25519.PrivateKey ed25519Priv ed25519.PrivateKey
hs512Secret []byte hs512Secret []byte
opts Options
store store.Interface
logger *slog.Logger
} }
func (s *Server) getTokenKeyfunc() jwt.Keyfunc { func (s *Server) getTokenKeyfunc() jwt.Keyfunc {

View File

@@ -152,34 +152,10 @@ func handleChallengeZeroDifficulty(t *testing.T, ts *httptest.Server, cli *http.
return resp return resp
} }
func handleChallengeInvalidProof(t *testing.T, ts *httptest.Server, cli *http.Client, chall challengeResp) *http.Response {
t.Helper()
req, err := http.NewRequest(http.MethodGet, ts.URL+"/.within.website/x/cmd/anubis/api/pass-challenge", nil)
if err != nil {
t.Fatalf("can't make request: %v", err)
}
q := req.URL.Query()
q.Set("response", strings.Repeat("f", 64)) // "hash" that never starts with the nonce
q.Set("nonce", "0")
q.Set("redir", "/")
q.Set("elapsedTime", "0")
q.Set("id", chall.ID)
req.URL.RawQuery = q.Encode()
resp, err := cli.Do(req)
if err != nil {
t.Fatalf("can't do request: %v", err)
}
return resp
}
type loggingCookieJar struct { type loggingCookieJar struct {
t *testing.T t *testing.T
cookies map[string][]*http.Cookie
lock sync.Mutex lock sync.Mutex
cookies map[string][]*http.Cookie
} }
func (lcj *loggingCookieJar) Cookies(u *url.URL) []*http.Cookie { func (lcj *loggingCookieJar) Cookies(u *url.URL) []*http.Cookie {
@@ -271,7 +247,7 @@ func TestCVE2025_24369(t *testing.T) {
cli := httpClient(t) cli := httpClient(t)
chall := makeChallenge(t, ts, cli) chall := makeChallenge(t, ts, cli)
resp := handleChallengeInvalidProof(t, ts, cli, chall) resp := handleChallengeZeroDifficulty(t, ts, cli, chall)
if resp.StatusCode == http.StatusFound { if resp.StatusCode == http.StatusFound {
t.Log("Regression on CVE-2025-24369") t.Log("Regression on CVE-2025-24369")
@@ -771,9 +747,9 @@ func TestStripBasePrefixFromRequest(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
basePrefix string basePrefix string
stripBasePrefix bool
requestPath string requestPath string
expectedPath string expectedPath string
stripBasePrefix bool
}{ }{
{ {
name: "strip disabled - no change", name: "strip disabled - no change",

View File

@@ -4,12 +4,12 @@ import "time"
// Challenge is the metadata about a single challenge issuance. // Challenge is the metadata about a single challenge issuance.
type Challenge struct { type Challenge struct {
IssuedAt time.Time `json:"issuedAt"` ID string `json:"id"` // UUID identifying the challenge
Metadata map[string]string `json:"metadata"` Method string `json:"method"` // Challenge method
ID string `json:"id"` RandomData string `json:"randomData"` // The random data the client processes
Method string `json:"method"` IssuedAt time.Time `json:"issuedAt"` // When the challenge was issued
RandomData string `json:"randomData"` Metadata map[string]string `json:"metadata"` // Challenge metadata such as IP address and user agent
PolicyRuleHash string `json:"policyRuleHash,omitempty"` Spent bool `json:"spent"` // Has the challenge already been solved?
Difficulty int `json:"difficulty,omitempty"` Difficulty int `json:"difficulty,omitempty"` // Difficulty that was in effect when issued
Spent bool `json:"spent"` PolicyRuleHash string `json:"policyRuleHash,omitempty"` // Hash of the policy rule that issued this challenge
} }

View File

@@ -29,24 +29,24 @@ import (
type Options struct { type Options struct {
Next http.Handler Next http.Handler
Policy *policy.ParsedConfig Policy *policy.ParsedConfig
Logger *slog.Logger Target string
OpenGraph config.OpenGraph CookieDynamicDomain bool
PublicUrl string
CookieDomain string CookieDomain string
JWTRestrictionHeader string CookieExpiration time.Duration
CookiePartitioned bool
BasePrefix string BasePrefix string
WebmasterEmail string WebmasterEmail string
Target string
RedirectDomains []string RedirectDomains []string
ED25519PrivateKey ed25519.PrivateKey ED25519PrivateKey ed25519.PrivateKey
HS512Secret []byte HS512Secret []byte
CookieExpiration time.Duration StripBasePrefix bool
CookieSameSite http.SameSite OpenGraph config.OpenGraph
ServeRobotsTXT bool ServeRobotsTXT bool
CookieSecure bool CookieSecure bool
StripBasePrefix bool CookieSameSite http.SameSite
CookiePartitioned bool Logger *slog.Logger
CookieDynamicDomain bool PublicUrl string
JWTRestrictionHeader string
DifficultyInJWT bool DifficultyInJWT bool
} }

View File

@@ -13,9 +13,9 @@ import (
func TestSetCookie(t *testing.T) { func TestSetCookie(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
name string name string
options Options
host string host string
cookieName string cookieName string
options Options
}{ }{
{ {
name: "basic", name: "basic",

View File

@@ -8,9 +8,9 @@ import (
func TestASNsValid(t *testing.T) { func TestASNsValid(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
input *ASNs
name string name string
input *ASNs
err error
}{ }{
{ {
name: "basic valid", name: "basic valid",

View File

@@ -62,11 +62,13 @@ type BotConfig struct {
Expression *ExpressionOrList `json:"expression,omitempty" yaml:"expression,omitempty"` Expression *ExpressionOrList `json:"expression,omitempty" yaml:"expression,omitempty"`
Challenge *ChallengeRules `json:"challenge,omitempty" yaml:"challenge,omitempty"` Challenge *ChallengeRules `json:"challenge,omitempty" yaml:"challenge,omitempty"`
Weight *Weight `json:"weight,omitempty" yaml:"weight,omitempty"` Weight *Weight `json:"weight,omitempty" yaml:"weight,omitempty"`
GeoIP *GeoIP `json:"geoip,omitempty"`
ASNs *ASNs `json:"asns,omitempty"`
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
Action Rule `json:"action" yaml:"action"` Action Rule `json:"action" yaml:"action"`
RemoteAddr []string `json:"remote_addresses,omitempty" yaml:"remote_addresses,omitempty"` RemoteAddr []string `json:"remote_addresses,omitempty" yaml:"remote_addresses,omitempty"`
// Thoth features
GeoIP *GeoIP `json:"geoip,omitempty"`
ASNs *ASNs `json:"asns,omitempty"`
} }
func (b BotConfig) Zero() bool { func (b BotConfig) Zero() bool {
@@ -322,13 +324,13 @@ func (sc StatusCodes) Valid() error {
} }
type fileConfig struct { type fileConfig struct {
Bots []BotOrImport `json:"bots"`
DNSBL bool `json:"dnsbl"`
OpenGraph openGraphFileConfig `json:"openGraph,omitempty"` OpenGraph openGraphFileConfig `json:"openGraph,omitempty"`
Impressum *Impressum `json:"impressum,omitempty"` Impressum *Impressum `json:"impressum,omitempty"`
Store *Store `json:"store"`
Bots []BotOrImport `json:"bots"`
Thresholds []Threshold `json:"thresholds"`
StatusCodes StatusCodes `json:"status_codes"` StatusCodes StatusCodes `json:"status_codes"`
DNSBL bool `json:"dnsbl"` Store *Store `json:"store"`
Thresholds []Threshold `json:"thresholds"`
} }
func (c *fileConfig) Valid() error { func (c *fileConfig) Valid() error {
@@ -460,13 +462,13 @@ func Load(fin io.Reader, fname string) (*Config, error) {
} }
type Config struct { type Config struct {
Impressum *Impressum
Store *Store
OpenGraph OpenGraph
Bots []BotConfig Bots []BotConfig
Thresholds []Threshold Thresholds []Threshold
StatusCodes StatusCodes
DNSBL bool DNSBL bool
Impressum *Impressum
OpenGraph OpenGraph
StatusCodes StatusCodes
Store *Store
} }
func (c Config) Valid() error { func (c Config) Valid() error {

View File

@@ -15,9 +15,9 @@ func p[V any](v V) *V { return &v }
func TestBotValid(t *testing.T) { func TestBotValid(t *testing.T) {
var tests = []struct { var tests = []struct {
bot BotConfig
err error err error
name string name string
bot BotConfig
}{ }{
{ {
name: "simple user agent", name: "simple user agent",

View File

@@ -11,10 +11,10 @@ import (
func TestExpressionOrListMarshalJSON(t *testing.T) { func TestExpressionOrListMarshalJSON(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
input *ExpressionOrList
name string name string
input *ExpressionOrList
output []byte output []byte
err error
}{ }{
{ {
name: "single expression", name: "single expression",
@@ -74,10 +74,10 @@ func TestExpressionOrListMarshalJSON(t *testing.T) {
func TestExpressionOrListMarshalYAML(t *testing.T) { func TestExpressionOrListMarshalYAML(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
input *ExpressionOrList
name string name string
input *ExpressionOrList
output []byte output []byte
err error
}{ }{
{ {
name: "single expression", name: "single expression",
@@ -217,8 +217,8 @@ func TestExpressionOrListUnmarshalJSON(t *testing.T) {
func TestExpressionOrListString(t *testing.T) { func TestExpressionOrListString(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
name string name string
out string
in ExpressionOrList in ExpressionOrList
out string
}{ }{
{ {
name: "single expression", name: "single expression",

View File

@@ -7,9 +7,9 @@ import (
func TestGeoIPValid(t *testing.T) { func TestGeoIPValid(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
input *GeoIP
name string name string
input *GeoIP
err error
}{ }{
{ {
name: "basic valid", name: "basic valid",

View File

@@ -8,9 +8,9 @@ import (
func TestImpressumValid(t *testing.T) { func TestImpressumValid(t *testing.T) {
for _, cs := range []struct { for _, cs := range []struct {
err error
inp Impressum
name string name string
inp Impressum
err error
}{ }{
{ {
name: "basic happy path", name: "basic happy path",

View File

@@ -13,17 +13,17 @@ var (
) )
type openGraphFileConfig struct { type openGraphFileConfig struct {
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
TimeToLive string `json:"ttl" yaml:"ttl"`
Enabled bool `json:"enabled" yaml:"enabled"` Enabled bool `json:"enabled" yaml:"enabled"`
ConsiderHost bool `json:"considerHost" yaml:"enabled"` ConsiderHost bool `json:"considerHost" yaml:"enabled"`
TimeToLive string `json:"ttl" yaml:"ttl"`
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
} }
type OpenGraph struct { type OpenGraph struct {
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
TimeToLive time.Duration `json:"ttl" yaml:"ttl"`
Enabled bool `json:"enabled" yaml:"enabled"` Enabled bool `json:"enabled" yaml:"enabled"`
ConsiderHost bool `json:"considerHost" yaml:"enabled"` ConsiderHost bool `json:"considerHost" yaml:"enabled"`
Override map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
TimeToLive time.Duration `json:"ttl" yaml:"ttl"`
} }
func (og *openGraphFileConfig) Valid() error { func (og *openGraphFileConfig) Valid() error {

View File

@@ -7,9 +7,9 @@ import (
func TestOpenGraphFileConfigValid(t *testing.T) { func TestOpenGraphFileConfigValid(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
input *openGraphFileConfig
name string name string
input *openGraphFileConfig
err error
}{ }{
{ {
name: "basic happy path", name: "basic happy path",

View File

@@ -12,9 +12,9 @@ import (
func TestStoreValid(t *testing.T) { func TestStoreValid(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
name string name string
input config.Store input config.Store
err error
}{ }{
{ {
name: "no backend", name: "no backend",

View File

@@ -31,10 +31,10 @@ var (
) )
type Threshold struct { type Threshold struct {
Expression *ExpressionOrList `json:"expression" yaml:"expression"`
Challenge *ChallengeRules `json:"challenge" yaml:"challenge"`
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
Expression *ExpressionOrList `json:"expression" yaml:"expression"`
Action Rule `json:"action" yaml:"action"` Action Rule `json:"action" yaml:"action"`
Challenge *ChallengeRules `json:"challenge" yaml:"challenge"`
} }
func (t Threshold) Valid() error { func (t Threshold) Valid() error {

View File

@@ -10,9 +10,9 @@ import (
func TestThresholdValid(t *testing.T) { func TestThresholdValid(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
input *Threshold
name string name string
input *Threshold
err error
}{ }{
{ {
name: "basic allow", name: "basic allow",

View File

@@ -14,11 +14,11 @@ func TestBotEnvironment(t *testing.T) {
t.Run("missingHeader", func(t *testing.T) { t.Run("missingHeader", func(t *testing.T) {
tests := []struct { tests := []struct {
headers map[string]string
name string name string
expression string expression string
description string headers map[string]string
expected types.Bool expected types.Bool
description string
}{ }{
{ {
name: "missing-header", name: "missing-header",
@@ -167,10 +167,10 @@ func TestBotEnvironment(t *testing.T) {
t.Run("invalid", func(t *testing.T) { t.Run("invalid", func(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
env any
name string name string
description string description string
expression string expression string
env any
wantFailCompile bool wantFailCompile bool
wantFailEval bool wantFailEval bool
}{ }{
@@ -244,11 +244,11 @@ func TestThresholdEnvironment(t *testing.T) {
} }
tests := []struct { tests := []struct {
variables map[string]interface{}
name string name string
expression string expression string
description string variables map[string]interface{}
expected types.Bool expected types.Bool
description string
shouldCompile bool shouldCompile bool
}{ }{
{ {

View File

@@ -10,8 +10,8 @@ import (
) )
type loadAvg struct { type loadAvg struct {
data *load.AvgStat
lock sync.RWMutex lock sync.RWMutex
data *load.AvgStat
} }
func (l *loadAvg) updateThread(ctx context.Context) { func (l *loadAvg) updateThread(ctx context.Context) {

View File

@@ -29,15 +29,16 @@ var (
) )
type ParsedConfig struct { type ParsedConfig struct {
Store store.Interface orig *config.Config
orig *config.Config
Impressum *config.Impressum
OpenGraph config.OpenGraph
Bots []Bot Bots []Bot
Thresholds []*Threshold Thresholds []*Threshold
StatusCodes config.StatusCodes
DefaultDifficulty int
DNSBL bool DNSBL bool
Impressum *config.Impressum
OpenGraph config.OpenGraph
DefaultDifficulty int
StatusCodes config.StatusCodes
Store store.Interface
} }
func newParsedConfig(orig *config.Config) *ParsedConfig { func newParsedConfig(orig *config.Config) *ParsedConfig {

View File

@@ -13,7 +13,7 @@ import (
func TestRedirectSecurity(t *testing.T) { func TestRedirectSecurity(t *testing.T) {
tests := []struct { tests := []struct {
reqHost string name string
testType string // "constructRedirectURL", "serveHTTPNext", "renderIndex" testType string // "constructRedirectURL", "serveHTTPNext", "renderIndex"
// For constructRedirectURL tests // For constructRedirectURL tests
@@ -23,16 +23,17 @@ func TestRedirectSecurity(t *testing.T) {
// For serveHTTPNext tests // For serveHTTPNext tests
redirParam string redirParam string
name string reqHost string
errorContains string
expectedStatus int
// For renderIndex tests // For renderIndex tests
returnHTTPStatusOnly bool returnHTTPStatusOnly bool
shouldError bool
shouldNotRedirect bool // Expected results
shouldBlock bool expectedStatus int
shouldError bool
shouldNotRedirect bool
shouldBlock bool
errorContains string
}{ }{
// constructRedirectURL tests - X-Forwarded-Proto validation // constructRedirectURL tests - X-Forwarded-Proto validation
{ {

View File

@@ -17,9 +17,9 @@ func TestFactoryValid(t *testing.T) {
t.Run("invalid config", func(t *testing.T) { t.Run("invalid config", func(t *testing.T) {
for _, tt := range []struct { for _, tt := range []struct {
err error
name string name string
cfg Config cfg Config
err error
}{ }{
{ {
name: "missing path", name: "missing path",

View File

@@ -88,8 +88,8 @@ func (Factory) Valid(data json.RawMessage) error {
} }
type Config struct { type Config struct {
BucketName string `json:"bucketName"`
PathStyle bool `json:"pathStyle"` PathStyle bool `json:"pathStyle"`
BucketName string `json:"bucketName"`
} }
func (c Config) Valid() error { func (c Config) Valid() error {

View File

@@ -17,10 +17,10 @@ import (
// mockS3 is an in-memory mock of the methods we use. // mockS3 is an in-memory mock of the methods we use.
type mockS3 struct { type mockS3 struct {
mu sync.RWMutex
bucket string
data map[string][]byte data map[string][]byte
meta map[string]map[string]string meta map[string]map[string]string
bucket string
mu sync.RWMutex
} }
func (m *mockS3) PutObject(ctx context.Context, in *s3.PutObjectInput, _ ...func(*s3.Options)) (*s3.PutObjectOutput, error) { func (m *mockS3) PutObject(ctx context.Context, in *s3.PutObjectInput, _ ...func(*s3.Options)) (*s3.PutObjectOutput, error) {

View File

@@ -21,9 +21,9 @@ func Common(t *testing.T, f store.Factory, config json.RawMessage) {
} }
for _, tt := range []struct { for _, tt := range []struct {
err error
doer func(t *testing.T, s store.Interface) error
name string name string
doer func(t *testing.T, s store.Interface) error
err error
}{ }{
{ {
name: "basic get set delete", name: "basic get set delete",

View File

@@ -2,14 +2,20 @@ package valkey
import ( import (
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"testing" "testing"
"github.com/TecharoHQ/anubis/internal"
"github.com/TecharoHQ/anubis/lib/store/storetest" "github.com/TecharoHQ/anubis/lib/store/storetest"
"github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait" "github.com/testcontainers/testcontainers-go/wait"
) )
func init() {
internal.UnbreakDocker()
}
func TestImpl(t *testing.T) { func TestImpl(t *testing.T) {
if os.Getenv("DONT_USE_NETWORK") != "" { if os.Getenv("DONT_USE_NETWORK") != "" {
t.Skip("test requires network egress") t.Skip("test requires network egress")
@@ -18,26 +24,26 @@ func TestImpl(t *testing.T) {
testcontainers.SkipIfProviderIsNotHealthy(t) testcontainers.SkipIfProviderIsNotHealthy(t)
valkeyC, err := testcontainers.Run( req := testcontainers.ContainerRequest{
t.Context(), "valkey/valkey:8", Image: "valkey/valkey:8",
testcontainers.WithExposedPorts("6379/tcp"), WaitingFor: wait.ForLog("Ready to accept connections"),
testcontainers.WithWaitStrategy( }
wait.ForListeningPort("6379/tcp"), valkeyC, err := testcontainers.GenericContainer(t.Context(), testcontainers.GenericContainerRequest{
wait.ForLog("Ready to accept connections"), ContainerRequest: req,
), Started: true,
) })
testcontainers.CleanupContainer(t, valkeyC) testcontainers.CleanupContainer(t, valkeyC)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
endpoint, err := valkeyC.PortEndpoint(t.Context(), "6379/tcp", "redis") containerIP, err := valkeyC.ContainerIP(t.Context())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
data, err := json.Marshal(Config{ data, err := json.Marshal(Config{
URL: endpoint, URL: fmt.Sprintf("redis://%s:6379/0", containerIP),
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)