@@ -921,10 +921,11 @@ func Test_shareObject(t *testing.T) {
921
921
shareFunc func (ctx context.Context , versionID string , expires time.Duration ) (string , * probe.Error )
922
922
}
923
923
tests := []struct {
924
- test string
925
- args args
926
- wantError error
927
- expected string
924
+ test string
925
+ args args
926
+ setEnvVars func ()
927
+ wantError error
928
+ expected string
928
929
}{
929
930
{
930
931
test : "return sharefunc url base64 encoded with host name" ,
@@ -1023,11 +1024,52 @@ func Test_shareObject(t *testing.T) {
1023
1024
wantError : nil ,
1024
1025
expected : "http://localhost:9090/api/v1/download-shared-object/aHR0cHM6Ly8xMjcuMC4wLjE6OTAwMC9jZXN0ZXN0L0F1ZGlvJTIwaWNvbi5zdmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTY=" ,
1025
1026
},
1027
+ {
1028
+ test : "returns redirect url with share link if redirect url env variable set" ,
1029
+ setEnvVars : func () {
1030
+ t .Setenv (ConsoleBrowserRedirectURL , "http://proxy-url.com:9012/console/subpath" )
1031
+ },
1032
+ args : args {
1033
+ r : & http.Request {
1034
+ TLS : nil ,
1035
+ Host : "localhost:9090" ,
1036
+ },
1037
+ versionID : "2121434" ,
1038
+ expires : "30s" ,
1039
+ shareFunc : func (_ context.Context , _ string , _ time.Duration ) (string , * probe.Error ) {
1040
+ return "http://someurl" , nil
1041
+ },
1042
+ },
1043
+ wantError : nil ,
1044
+ expected : "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=" ,
1045
+ },
1046
+ {
1047
+ test : "returns redirect url with share link if redirect url env variable set with trailing slash" ,
1048
+ setEnvVars : func () {
1049
+ t .Setenv (ConsoleBrowserRedirectURL , "http://proxy-url.com:9012/console/subpath/" )
1050
+ },
1051
+ args : args {
1052
+ r : & http.Request {
1053
+ TLS : nil ,
1054
+ Host : "localhost:9090" ,
1055
+ },
1056
+ versionID : "2121434" ,
1057
+ expires : "30s" ,
1058
+ shareFunc : func (_ context.Context , _ string , _ time.Duration ) (string , * probe.Error ) {
1059
+ return "http://someurl" , nil
1060
+ },
1061
+ },
1062
+ wantError : nil ,
1063
+ expected : "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=" ,
1064
+ },
1026
1065
}
1027
1066
1028
1067
for _ , tt := range tests {
1029
1068
t .Run (tt .test , func (_ * testing.T ) {
1030
1069
mcShareDownloadMock = tt .args .shareFunc
1070
+ if tt .setEnvVars != nil {
1071
+ tt .setEnvVars ()
1072
+ }
1031
1073
url , err := getShareObjectURL (ctx , client , tt .args .r , tt .args .versionID , tt .args .expires )
1032
1074
if tt .wantError != nil {
1033
1075
if ! reflect .DeepEqual (err , tt .wantError ) {
0 commit comments