Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,7 @@ func getConsoleDevMode() bool {
func getConsoleAnimatedLogin() bool {
return strings.ToLower(env.Get(ConsoleAnimatedLogin, "on")) == "on"
}

func getConsoleBrowserRedirectURL() string {
return env.Get(ConsoleBrowserRedirectURL, "")
}
1 change: 1 addition & 0 deletions api/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
ConsoleMaxConcurrentDownloads = "CONSOLE_MAX_CONCURRENT_DOWNLOADS"
ConsoleDevMode = "CONSOLE_DEV_MODE"
ConsoleAnimatedLogin = "CONSOLE_ANIMATED_LOGIN"
ConsoleBrowserRedirectURL = "CONSOLE_BROWSER_REDIRECT_URL"
LogSearchQueryAuthToken = "LOGSEARCH_QUERY_AUTH_TOKEN"
SlashSeparator = "/"
LocalAddress = "127.0.0.1"
Expand Down
5 changes: 5 additions & 0 deletions api/user_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@ func getRequestURLWithScheme(r *http.Request) string {
scheme = "https"
}

redirectURL := getConsoleBrowserRedirectURL()
if redirectURL != "" {
return strings.TrimSuffix(redirectURL, "/")
}

return fmt.Sprintf("%s://%s", scheme, r.Host)
}

Expand Down
50 changes: 46 additions & 4 deletions api/user_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,11 @@ func Test_shareObject(t *testing.T) {
shareFunc func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error)
}
tests := []struct {
test string
args args
wantError error
expected string
test string
args args
setEnvVars func()
wantError error
expected string
}{
{
test: "return sharefunc url base64 encoded with host name",
Expand Down Expand Up @@ -1023,11 +1024,52 @@ func Test_shareObject(t *testing.T) {
wantError: nil,
expected: "http://localhost:9090/api/v1/download-shared-object/aHR0cHM6Ly8xMjcuMC4wLjE6OTAwMC9jZXN0ZXN0L0F1ZGlvJTIwaWNvbi5zdmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTY=",
},
{
test: "returns redirect url with share link if redirect url env variable set",
setEnvVars: func() {
t.Setenv(ConsoleBrowserRedirectURL, "http://proxy-url.com:9012/console/subpath")
},
args: args{
r: &http.Request{
TLS: nil,
Host: "localhost:9090",
},
versionID: "2121434",
expires: "30s",
shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
return "http://someurl", nil
},
},
wantError: nil,
expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
},
{
test: "returns redirect url with share link if redirect url env variable set with trailing slash",
setEnvVars: func() {
t.Setenv(ConsoleBrowserRedirectURL, "http://proxy-url.com:9012/console/subpath/")
},
args: args{
r: &http.Request{
TLS: nil,
Host: "localhost:9090",
},
versionID: "2121434",
expires: "30s",
shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
return "http://someurl", nil
},
},
wantError: nil,
expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
},
}

for _, tt := range tests {
t.Run(tt.test, func(_ *testing.T) {
mcShareDownloadMock = tt.args.shareFunc
if tt.setEnvVars != nil {
tt.setEnvVars()
}
url, err := getShareObjectURL(ctx, client, tt.args.r, tt.args.versionID, tt.args.expires)
if tt.wantError != nil {
if !reflect.DeepEqual(err, tt.wantError) {
Expand Down