1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package rubyserver
import (
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
func TestSetHeadersBlocksUnknownMetadata(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
otherKey := "unknown-key"
otherValue := "test-value"
inCtx := metadata.NewIncomingContext(ctx, metadata.Pairs(otherKey, otherValue))
outCtx, err := SetHeaders(inCtx, testRepo)
require.NoError(t, err)
outMd, ok := metadata.FromOutgoingContext(outCtx)
require.True(t, ok, "outgoing context should have metadata")
_, ok = outMd[otherKey]
require.False(t, ok, "outgoing MD should not contain non-whitelisted key")
}
func TestSetHeadersPreservesWhitelistedMetadata(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
key := "gitaly-servers"
require.Contains(t, ProxyHeaderWhitelist, key, "sanity check")
value := "test-value"
inCtx := metadata.NewIncomingContext(ctx, metadata.Pairs(key, value))
outCtx, err := SetHeaders(inCtx, testRepo)
require.NoError(t, err)
outMd, ok := metadata.FromOutgoingContext(outCtx)
require.True(t, ok, "outgoing context should have metadata")
require.Equal(t, []string{value}, outMd[key], "outgoing MD should contain whitelisted key")
}
|