api/PostPolicy: Allow location header fully qualified URL (#4926)
req.Host is used to construct the final object location. Fixes #4910master
parent
c3ff402fcb
commit
4cadb33da2
@ -0,0 +1,74 @@ |
|||||||
|
/* |
||||||
|
* Minio Cloud Storage, (C) 2017 Minio, Inc. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package cmd |
||||||
|
|
||||||
|
import ( |
||||||
|
"testing" |
||||||
|
) |
||||||
|
|
||||||
|
// Tests object location.
|
||||||
|
func TestObjectLocation(t *testing.T) { |
||||||
|
testCases := []struct { |
||||||
|
host, proto, bucket, object string |
||||||
|
expectedLocation string |
||||||
|
}{ |
||||||
|
// Server binding to localhost IP with https.
|
||||||
|
{ |
||||||
|
host: "127.0.0.1:9000", |
||||||
|
proto: httpsScheme, |
||||||
|
bucket: "testbucket1", |
||||||
|
object: "test/1.txt", |
||||||
|
expectedLocation: "https://127.0.0.1:9000/testbucket1/test/1.txt", |
||||||
|
}, |
||||||
|
// Server binding to fqdn.
|
||||||
|
{ |
||||||
|
host: "s3.mybucket.org", |
||||||
|
proto: httpScheme, |
||||||
|
bucket: "mybucket", |
||||||
|
object: "test/1.txt", |
||||||
|
expectedLocation: "http://s3.mybucket.org/mybucket/test/1.txt", |
||||||
|
}, |
||||||
|
// Server binding to fqdn.
|
||||||
|
{ |
||||||
|
host: "mys3.mybucket.org", |
||||||
|
proto: "", |
||||||
|
bucket: "mybucket", |
||||||
|
object: "test/1.txt", |
||||||
|
expectedLocation: "http://mys3.mybucket.org/mybucket/test/1.txt", |
||||||
|
}, |
||||||
|
} |
||||||
|
for i, testCase := range testCases { |
||||||
|
gotLocation := getObjectLocation(testCase.host, testCase.proto, testCase.bucket, testCase.object) |
||||||
|
if testCase.expectedLocation != gotLocation { |
||||||
|
t.Errorf("Test %d: expected %s, got %s", i+1, testCase.expectedLocation, gotLocation) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Tests getURLScheme function behavior.
|
||||||
|
func TestGetURLScheme(t *testing.T) { |
||||||
|
tls := false |
||||||
|
gotScheme := getURLScheme(tls) |
||||||
|
if gotScheme != httpScheme { |
||||||
|
t.Errorf("Expected %s, got %s", httpScheme, gotScheme) |
||||||
|
} |
||||||
|
tls = true |
||||||
|
gotScheme = getURLScheme(tls) |
||||||
|
if gotScheme != httpsScheme { |
||||||
|
t.Errorf("Expected %s, got %s", httpsScheme, gotScheme) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue