Repository navigation
Expand file tree
/
Copy pathrequest_test.go
More file actions
64 lines (50 loc) · 1.48 KB
/
Copy pathrequest_test.go
File metadata and controls
64 lines (50 loc) · 1.48 KB
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
package audit_test
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/propagation"
"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/database"
)
func TestBaggage(t *testing.T) {
t.Parallel()
prop := propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
)
expected := audit.WorkspaceBuildBaggage{
IP: "127.0.0.1",
}
ctx, err := audit.BaggageToContext(context.Background(), expected)
require.NoError(t, err)
carrier := propagation.MapCarrier{}
prop.Inject(ctx, carrier)
bCtx := prop.Extract(ctx, carrier)
got := audit.BaggageFromContext(bCtx)
require.Equal(t, expected, got)
}
func TestResourceTarget_ChatTitleNotLeaked(t *testing.T) {
t.Parallel()
chat := database.Chat{
ID: uuid.UUID{1},
Title: "sensitive-project-name",
}
target := audit.ResourceTarget(chat)
require.NotContains(t, target, chat.Title,
"ResourceTarget for Chat must not contain the title; it should use a UUID prefix")
}
func TestResourceTarget_MCPServerConfigSlugFallback(t *testing.T) {
t.Parallel()
config := database.MCPServerConfig{
ID: uuid.UUID{1},
DisplayName: "GitHub MCP",
Slug: "github",
}
require.Equal(t, "GitHub MCP", audit.ResourceTarget(config))
config.DisplayName = ""
require.Equal(t, "github", audit.ResourceTarget(config))
config.Slug = ""
require.Equal(t, config.ID.String(), audit.ResourceTarget(config))
}