4cddfcf2f3
Backend Tests / Tests (other) (push) Failing after 1s
Backend Tests / Static Checks (push) Failing after 2s
Backend Tests / Tests (internal) (push) Failing after 2s
Backend Tests / Tests (server) (push) Failing after 1s
Backend Tests / Tests (store) (push) Failing after 1s
Build Canary Image / build-frontend (push) Failing after 1s
Frontend Tests / Lint (push) Failing after 1s
Build Canary Image / build-push (linux/amd64) (push) Has been skipped
Build Canary Image / build-push (linux/arm64) (push) Has been skipped
Build Canary Image / merge (push) Has been skipped
Frontend Tests / Build (push) Failing after 1s
Release Please / release-please (push) Failing after 0s
Proto Linter / Lint Protos (push) Failing after 2s
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"connectrpc.com/connect"
|
|
"google.golang.org/grpc/metadata"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
func TestMetadataInterceptorForwardsSecurityHeaders(t *testing.T) {
|
|
interceptor := NewMetadataInterceptor()
|
|
req := connect.NewRequest(&emptypb.Empty{})
|
|
req.Header().Set("Origin", "https://memos.example")
|
|
req.Header().Set("X-Forwarded-Proto", "https")
|
|
req.Header().Set("Forwarded", "for=203.0.113.1;proto=https")
|
|
|
|
handler := interceptor.WrapUnary(func(ctx context.Context, _ connect.AnyRequest) (connect.AnyResponse, error) {
|
|
md, ok := metadata.FromIncomingContext(ctx)
|
|
if !ok {
|
|
t.Fatal("expected metadata in context")
|
|
}
|
|
if got := md.Get("origin"); len(got) != 1 || got[0] != "https://memos.example" {
|
|
t.Fatalf("unexpected origin metadata: %v", got)
|
|
}
|
|
if got := md.Get("x-forwarded-proto"); len(got) != 1 || got[0] != "https" {
|
|
t.Fatalf("unexpected x-forwarded-proto metadata: %v", got)
|
|
}
|
|
if got := md.Get("forwarded"); len(got) != 1 || got[0] != "for=203.0.113.1;proto=https" {
|
|
t.Fatalf("unexpected forwarded metadata: %v", got)
|
|
}
|
|
return connect.NewResponse(&emptypb.Empty{}), nil
|
|
})
|
|
|
|
if _, err := handler(context.Background(), req); err != nil {
|
|
t.Fatalf("metadata interceptor returned error: %v", err)
|
|
}
|
|
}
|