Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d9631a8fc |
No files matched your search
@@ -36,8 +36,8 @@ P2: security: per-origin rate limiting
|
|||||||
`MaxBytes` is the one value for the disk cache limit, and 0 turns the disk
|
`MaxBytes` is the one value for the disk cache limit, and 0 turns the disk
|
||||||
cache off. For an omitted `cache_max_bytes`, `internal/providers` works out
|
cache off. For an omitted `cache_max_bytes`, `internal/providers` works out
|
||||||
`config.DefaultCacheMaxBytes` before it builds the cache. `internal/app` and
|
`config.DefaultCacheMaxBytes` before it builds the cache. `internal/app` and
|
||||||
the server tests build the parts below with `providers.Option`; the image
|
the server tests build the parts below with `providers.Constructors()`; the
|
||||||
proxy test replaces only the fetcher's dial function.
|
image proxy test replaces only the fetcher's dial function.
|
||||||
- Built by the providers in `internal/providers`, and given to
|
- Built by the providers in `internal/providers`, and given to
|
||||||
`handlers.New`:
|
`handlers.New`:
|
||||||
- the cache
|
- the cache
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ func run(_ *cobra.Command, _ []string) {
|
|||||||
// The registry /metrics serves
|
// The registry /metrics serves
|
||||||
func() prometheus.Registerer { return prometheus.DefaultRegisterer },
|
func() prometheus.Registerer { return prometheus.DefaultRegisterer },
|
||||||
),
|
),
|
||||||
providers.Option,
|
fx.Provide(providers.Constructors()...),
|
||||||
fx.Invoke(
|
fx.Invoke(
|
||||||
func(log *logger.Logger) { log.Identify() },
|
func(log *logger.Logger) { log.Identify() },
|
||||||
func(*server.Server) {},
|
func(*server.Server) {},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package app
|
package providers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -20,20 +20,16 @@ import (
|
|||||||
"sneak.berlin/go/pixa/internal/handlers"
|
"sneak.berlin/go/pixa/internal/handlers"
|
||||||
"sneak.berlin/go/pixa/internal/healthcheck"
|
"sneak.berlin/go/pixa/internal/healthcheck"
|
||||||
"sneak.berlin/go/pixa/internal/logger"
|
"sneak.berlin/go/pixa/internal/logger"
|
||||||
"sneak.berlin/go/pixa/internal/providers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// testSigningKey is a throwaway signing key.
|
|
||||||
const testSigningKey = "test-signing-key-0123456789abcdef"
|
|
||||||
|
|
||||||
// TestFetcherFromConfigRefusesBlockedNetworks builds the handlers as pixad
|
// TestFetcherFromConfigRefusesBlockedNetworks builds the handlers as pixad
|
||||||
// does, in an fx app with the providers of pixad's fx app, and requests an
|
// does, in an fx app with the providers of pixad's fx app, and requests an
|
||||||
// image from 192.0.2.10, which is on the allowlist and in blocked_networks.
|
// image from 192.0.2.10, which is on the allowlist and in blocked_networks.
|
||||||
// The URL check accepts that address; only the dialer that refuses internal
|
// The URL check accepts that address; only the dialer that refuses internal
|
||||||
// addresses checks blocked_networks, so the answer is 403 only if the
|
// addresses checks blocked_networks, so the answer is 403 only if the
|
||||||
// fetcher providers.Option builds from the config connects with that
|
// fetcher this package builds from the config connects with that dialer.
|
||||||
// dialer. Any other dialer would try to connect until the upstream fetch
|
// Any other dialer would try to connect until the upstream fetch timeout,
|
||||||
// timeout, which is short so that the test then fails quickly.
|
// which is short so that the test then fails quickly.
|
||||||
func TestFetcherFromConfigRefusesBlockedNetworks(t *testing.T) {
|
func TestFetcherFromConfigRefusesBlockedNetworks(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -61,7 +57,7 @@ func TestFetcherFromConfigRefusesBlockedNetworks(t *testing.T) {
|
|||||||
fx.Provide(globals.New, logger.New, database.New, healthcheck.New,
|
fx.Provide(globals.New, logger.New, database.New, healthcheck.New,
|
||||||
handlers.New,
|
handlers.New,
|
||||||
func() prometheus.Registerer { return prometheus.NewRegistry() }),
|
func() prometheus.Registerer { return prometheus.NewRegistry() }),
|
||||||
providers.Option,
|
fx.Provide(Constructors()...),
|
||||||
fx.Populate(&h),
|
fx.Populate(&h),
|
||||||
)
|
)
|
||||||
app.RequireStart()
|
app.RequireStart()
|
||||||
@@ -30,19 +30,20 @@ import (
|
|||||||
"sneak.berlin/go/pixa/internal/session"
|
"sneak.berlin/go/pixa/internal/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option provides the parts this package builds. The fx graph must also
|
// Constructors returns the constructors of the parts this package builds,
|
||||||
// provide the prometheus.Registerer the cache registers its counters on.
|
// for fx.Provide. The fx graph must also provide the prometheus.Registerer
|
||||||
//
|
// the cache registers its counters on.
|
||||||
//nolint:gochecknoglobals // an fx option, built once and never changed
|
func Constructors() []any {
|
||||||
var Option = fx.Provide(
|
return []any{
|
||||||
newCache,
|
newCache,
|
||||||
newFetcherConfig,
|
newFetcherConfig,
|
||||||
httpfetcher.New,
|
httpfetcher.New,
|
||||||
newProcessor,
|
newProcessor,
|
||||||
newImageService,
|
newImageService,
|
||||||
newSessionManager,
|
newSessionManager,
|
||||||
newEncryptedURLGenerator,
|
newEncryptedURLGenerator,
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// cacheParams defines dependencies for newCache.
|
// cacheParams defines dependencies for newCache.
|
||||||
type cacheParams struct {
|
type cacheParams struct {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ func startImageProxy(
|
|||||||
middleware.New,
|
middleware.New,
|
||||||
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
||||||
),
|
),
|
||||||
providers.Option,
|
fx.Provide(providers.Constructors()...),
|
||||||
fx.Decorate(func(fetcherConfig *httpfetcher.Config) *httpfetcher.Config {
|
fx.Decorate(func(fetcherConfig *httpfetcher.Config) *httpfetcher.Config {
|
||||||
fetcherConfig.DialContext = dialUpstream
|
fetcherConfig.DialContext = dialUpstream
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ func startImageProxyWithBlockedNetworks(
|
|||||||
middleware.New,
|
middleware.New,
|
||||||
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
||||||
),
|
),
|
||||||
providers.Option,
|
fx.Provide(providers.Constructors()...),
|
||||||
fx.Populate(&h, &mw),
|
fx.Populate(&h, &mw),
|
||||||
)
|
)
|
||||||
app.RequireStart()
|
app.RequireStart()
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func startPixa(t *testing.T, cfg *config.Config) *Server {
|
|||||||
middleware.New,
|
middleware.New,
|
||||||
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
func() prometheus.Registerer { return prometheus.NewRegistry() },
|
||||||
),
|
),
|
||||||
providers.Option,
|
fx.Provide(providers.Constructors()...),
|
||||||
fx.Populate(&h, &mw),
|
fx.Populate(&h, &mw),
|
||||||
)
|
)
|
||||||
app.RequireStart()
|
app.RequireStart()
|
||||||
|
|||||||
Reference in new issue
Block a user