Skip to content

Commit e9c49be

Browse files
committed
test(proxy): add tests for forwardAuthorization flag from env
1 parent 732706b commit e9c49be

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

main_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,65 @@ func TestNewRootCommand_ForwardAuthorizationFlag(t *testing.T) {
549549
t.Fatalf("expected forwardAuthorizationHeader to be true when flag is set")
550550
}
551551
}
552+
553+
func TestNewRootCommand_ForwardAuthorizationFromEnv(t *testing.T) {
554+
t.Setenv("PROXY_FORWARD_AUTHORIZATION", "true")
555+
556+
var forwardAuthorization bool
557+
runner := proxyRunnerFunc(func(listen string,
558+
tlsListen string,
559+
autoTLS bool,
560+
tlsHost string,
561+
tlsDirectoryURL string,
562+
tlsAcceptTOS bool,
563+
tlsCertFile string,
564+
tlsKeyFile string,
565+
dataPath string,
566+
repositoryBackend string,
567+
repositoryDSN string,
568+
externalURL string,
569+
googleClientID string,
570+
googleClientSecret string,
571+
googleAllowedUsers []string,
572+
googleAllowedWorkspaces []string,
573+
githubClientID string,
574+
githubClientSecret string,
575+
githubAllowedUsers []string,
576+
githubAllowedOrgs []string,
577+
oidcConfigurationURL string,
578+
oidcClientID string,
579+
oidcClientSecret string,
580+
oidcScopes []string,
581+
oidcUserIDField string,
582+
oidcProviderName string,
583+
oidcAllowedUsers []string,
584+
oidcAllowedUsersGlob []string,
585+
oidcAllowedAttributes map[string][]string,
586+
oidcAllowedAttributesGlob map[string][]string,
587+
noProviderAutoSelect bool,
588+
password string,
589+
passwordHash string,
590+
trustedProxy []string,
591+
proxyHeaders []string,
592+
proxyBearerToken string,
593+
forwardAuthorizationHeader bool,
594+
proxyTarget []string,
595+
httpStreamingOnly bool,
596+
headerMapping map[string]string,
597+
headerMappingBase string,
598+
) error {
599+
forwardAuthorization = forwardAuthorizationHeader
600+
return nil
601+
})
602+
603+
cmd := newRootCommand(runner)
604+
cmd.SetArgs([]string{"http://backend"})
605+
606+
if err := cmd.Execute(); err != nil {
607+
t.Fatalf("expected command to succeed, got error: %v", err)
608+
}
609+
610+
if !forwardAuthorization {
611+
t.Fatalf("expected forwardAuthorizationHeader to default to true from env var")
612+
}
613+
}

pkg/mcp-proxy/main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestRun_NormalizesExternalURLTrailingSlash(t *testing.T) {
3434
for _, tt := range cases {
3535
t.Run(tt.name, func(t *testing.T) {
3636
var receivedURL string
37-
newProxyRouter = func(externalURL string, proxyHandler http.Handler, publicKey *rsa.PublicKey, proxyHeaders http.Header, httpStreamingOnly bool, headerMapping map[string]string, headerMappingBase string) (*proxy.ProxyRouter, error) {
37+
newProxyRouter = func(externalURL string, proxyHandler http.Handler, publicKey *rsa.PublicKey, proxyHeaders http.Header, httpStreamingOnly bool, forwardAuthorizationHeader bool, headerMapping map[string]string, headerMappingBase string) (*proxy.ProxyRouter, error) {
3838
receivedURL = externalURL
3939
return nil, errors.New("stop early")
4040
}
@@ -46,7 +46,7 @@ func TestRun_NormalizesExternalURLTrailingSlash(t *testing.T) {
4646
"", "", nil, nil,
4747
"", "", nil, nil,
4848
"", "", "", nil, "", "", nil, nil, nil, nil,
49-
false, "", "", nil, nil, "",
49+
false, "", "", nil, nil, "", false,
5050
[]string{"http://example.com"}, false, nil, "/userinfo",
5151
)
5252

@@ -70,7 +70,7 @@ func TestRun_PassesHTTPStreamingOnlyToProxyRouter(t *testing.T) {
7070
})
7171

7272
var streamingOnlyReceived bool
73-
newProxyRouter = func(externalURL string, proxyHandler http.Handler, publicKey *rsa.PublicKey, proxyHeaders http.Header, httpStreamingOnly bool, headerMapping map[string]string, headerMappingBase string) (*proxy.ProxyRouter, error) {
73+
newProxyRouter = func(externalURL string, proxyHandler http.Handler, publicKey *rsa.PublicKey, proxyHeaders http.Header, httpStreamingOnly bool, forwardAuthorizationHeader bool, headerMapping map[string]string, headerMappingBase string) (*proxy.ProxyRouter, error) {
7474
streamingOnlyReceived = httpStreamingOnly
7575
return nil, errors.New("proxy router init failed")
7676
}
@@ -112,6 +112,7 @@ func TestRun_PassesHTTPStreamingOnlyToProxyRouter(t *testing.T) {
112112
nil,
113113
nil,
114114
"",
115+
false,
115116
[]string{"http://example.com"},
116117
true,
117118
nil,

0 commit comments

Comments
 (0)