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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package rubyserver
import (
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"google.golang.org/grpc/metadata"
)
func TestSetHeadersBlocksUnknownMetadata(t *testing.T) {
cfg, repo, _ := testcfg.BuildWithRepo(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, config.NewLocator(cfg), repo)
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-allowlisted key")
}
func TestSetHeadersPreservesAllowlistedMetadata(t *testing.T) {
cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx, cancel := testhelper.Context()
defer cancel()
key := "gitaly-servers"
value := "test-value"
inCtx := metadata.NewIncomingContext(ctx, metadata.Pairs(key, value))
outCtx, err := SetHeaders(inCtx, config.NewLocator(cfg), repo)
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 allowlisted key")
}
func TestRubyFeatureHeaders(t *testing.T) {
cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx, cancel := testhelper.Context()
defer cancel()
key := "gitaly-feature-ruby-test-feature"
value := "true"
inCtx := metadata.NewIncomingContext(ctx, metadata.Pairs(key, value))
outCtx, err := SetHeaders(inCtx, config.NewLocator(cfg), repo)
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 allowlisted feature key")
}
|