Files
archie/internal/app/archied/gateway_test.go
T
sam 0ec4ececd5 feat(gateway): authenticate the gRPC contract and allow off-loopback listeners
The Gateway had no transport boundary: RunGateway refused any non-loopback
listen address and serveGateway registered no interceptor, so archie-ui was
colocation-only while the State Store already had a token-authenticated
equivalent.

gatewayrpc gains a gateway-token metadata credential with constant-time
comparison and both unary and stream interceptors on each side. Stream
coverage is required here and not in staterpc: the Gateway's Stream RPC is
server-streaming. Dial fails closed on a non-loopback target with no token,
mirroring staterpc.Dial. gatewayServerOpts applies the same rule server-side:
loopback stays insecure, non-loopback requires a token, malformed errors.

The daemon resolves [services.gateway].target_token then GATEWAY_TOKEN;
archie-ui passes the token its config projection already carried, so a
distributed dashboard is now possible.

Closes: archie-core-juqx
2026-09-09 00:27:03 +10:00

39 lines
1.2 KiB
Go

package archied
import "testing"
func TestGatewayServerOptsLoopbackIsInsecure(t *testing.T) {
opts, loopback, err := gatewayServerOpts("127.0.0.1:8585", "")
if err != nil {
t.Fatalf("gatewayServerOpts(loopback, no token) error: %v", err)
}
if !loopback {
t.Fatal("loopback listener should report loopback")
}
if len(opts) != 0 {
t.Fatalf("loopback listener should have no server opts, got %d", len(opts))
}
}
func TestGatewayServerOptsNonLoopbackRequiresToken(t *testing.T) {
if _, _, err := gatewayServerOpts("0.0.0.0:8585", ""); err == nil {
t.Fatal("non-loopback listener without a token should fail closed")
}
opts, loopback, err := gatewayServerOpts("0.0.0.0:8585", "secret")
if err != nil {
t.Fatalf("non-loopback listener with a token error: %v", err)
}
if loopback {
t.Fatal("non-loopback listener should not report loopback")
}
if len(opts) != 2 {
t.Fatalf("non-loopback listener should install two server options (unary and stream auth interceptors), got %d", len(opts))
}
}
func TestGatewayServerOptsMalformedListen(t *testing.T) {
if _, _, err := gatewayServerOpts("not-an-address", ""); err == nil {
t.Fatal("malformed listen address should error")
}
}