@@ -153,7 +153,7 @@ func TestDownloadObject(t *testing.T) {
153153}
154154
155155func TestDownloadAfterPublicHostChange (t * testing.T ) {
156- server , err := NewServerWithOptions (Options {PublicHost : "127.0.0.1" , InitialObjects : []Object {
156+ server , err := NewServerWithOptions (Options {PublicHost : "127.0.0.1:80 " , InitialObjects : []Object {
157157 {ObjectAttrs : ObjectAttrs {BucketName : "some-bucket" , Name : "files/txt/text-01.txt" }, Content : []byte ("something" )},
158158 }})
159159 if err != nil {
@@ -173,10 +173,10 @@ func TestDownloadAfterPublicHostChange(t *testing.T) {
173173 }
174174 defer resp .Body .Close ()
175175
176- // This first request should fail because we have specified a PublicHost of 127.0.0.1, which does
177- // not include the port generated by the test server .
176+ // First request fails because the port configured in PublicHost
177+ // doesn't match .
178178 if resp .StatusCode != http .StatusNotFound {
179- t .Errorf ("wrong status returned\n want %d\n got %d" , http .StatusNotFound , resp .StatusCode )
179+ t .Fatalf ("wrong status returned\n want %d\n got %d" , http .StatusNotFound , resp .StatusCode )
180180 }
181181
182182 // Now set the public host to match the httptest.Server and try again.
@@ -202,6 +202,64 @@ func TestDownloadAfterPublicHostChange(t *testing.T) {
202202 }
203203}
204204
205+ func TestDownloadPartialPublicHostMatch (t * testing.T ) {
206+ server , err := NewServerWithOptions (Options {PublicHost : "127.0.0.1" , InitialObjects : []Object {
207+ {ObjectAttrs : ObjectAttrs {BucketName : "some-bucket" , Name : "files/txt/text-01.txt" }, Content : []byte ("something" )},
208+ }})
209+ if err != nil {
210+ t .Fatal (err )
211+ }
212+
213+ client := server .HTTPClient ()
214+ requestURL := server .URL () + "/some-bucket/files/txt/text-01.txt"
215+
216+ req , err := http .NewRequest (http .MethodGet , requestURL , nil )
217+ if err != nil {
218+ t .Fatal (err )
219+ }
220+ resp , err := client .Do (req )
221+ if err != nil {
222+ t .Fatal (err )
223+ }
224+ defer resp .Body .Close ()
225+
226+ if resp .StatusCode != http .StatusOK {
227+ t .Errorf ("wrong status returned\n want %d\n got %d" , http .StatusOK , resp .StatusCode )
228+ }
229+ }
230+
231+ func TestDownloadPartialHostValidationShouldntValidatePortPartially (t * testing.T ) {
232+ server , err := NewServerWithOptions (Options {PublicHost : "127.0.0.1" , InitialObjects : []Object {
233+ {ObjectAttrs : ObjectAttrs {BucketName : "some-bucket" , Name : "files/txt/text-01.txt" }, Content : []byte ("something" )},
234+ }})
235+ if err != nil {
236+ t .Fatal (err )
237+ }
238+
239+ client := server .HTTPClient ()
240+ requestURL := server .URL () + "/some-bucket/files/txt/text-01.txt"
241+
242+ serverURL , err := url .Parse (server .URL ())
243+ if err != nil {
244+ t .Fatal (err )
245+ }
246+ server .publicHost = serverURL .Hostname () + ":" + serverURL .Port ()[:2 ]
247+
248+ req , err := http .NewRequest (http .MethodGet , requestURL , nil )
249+ if err != nil {
250+ t .Fatal (err )
251+ }
252+ resp , err := client .Do (req )
253+ if err != nil {
254+ t .Fatal (err )
255+ }
256+ defer resp .Body .Close ()
257+
258+ if resp .StatusCode != http .StatusNotFound {
259+ t .Errorf ("wrong status returned\n want %d\n got %d" , http .StatusNotFound , resp .StatusCode )
260+ }
261+ }
262+
205263func testDownloadObject (t * testing.T , server * Server ) {
206264 tests := []struct {
207265 name string
0 commit comments