func (s *ClientTests) testSignedUrl(c *C, b *s3.Bucket, name string) { err := b.Put(name, []byte("test for signed URLs."), "text/plain", s3.Private) c.Assert(err, IsNil) defer b.Del(name) req, err := http.NewRequest("GET", b.URL(name), nil) c.Assert(err, IsNil) resp, err := http.DefaultClient.Do(req) c.Assert(err, IsNil) err = s3.BuildError(resp) c.Check(err, NotNil) c.Check(err.(*s3.Error).Code, Equals, "AccessDenied") url, err := b.SignedURL(name, 24*time.Hour) c.Assert(err, IsNil) req, err = http.NewRequest("GET", url, nil) c.Assert(err, IsNil) resp, err = http.DefaultClient.Do(req) c.Assert(err, IsNil) body, err := ioutil.ReadAll(resp.Body) c.Assert(err, IsNil) c.Check(string(body), Equals, "test for signed URLs.") }
func killBucket(b *s3.Bucket) { var err error for attempt := attempts.Start(); attempt.Next(); { err = b.DelBucket() if err == nil { return } if _, ok := err.(*net.DNSError); ok { return } e, ok := err.(*s3.Error) if ok && e.Code == "NoSuchBucket" { return } if ok && e.Code == "BucketNotEmpty" { // Errors are ignored here. Just retry. resp, err := b.List("", "", "", 1000) if err == nil { for _, key := range resp.Contents { _ = b.Del(key.Key) } } multis, _, _ := b.ListMulti("", "") for _, m := range multis { _ = m.Abort() } } } message := "cannot delete test bucket" if err != nil { message += ": " + err.Error() } panic(message) }