mirror of
https://github.com/minio/minio.git
synced 2025-11-10 14:09:48 -05:00
Migrate this project to minio micro services code
This commit is contained in:
88
vendor/github.com/rs/cors/bench_test.go
generated
vendored
88
vendor/github.com/rs/cors/bench_test.go
generated
vendored
@@ -1,88 +0,0 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type FakeResponse struct {
|
||||
header http.Header
|
||||
}
|
||||
|
||||
func (r FakeResponse) Header() http.Header {
|
||||
return r.header
|
||||
}
|
||||
|
||||
func (r FakeResponse) WriteHeader(n int) {
|
||||
}
|
||||
|
||||
func (r FakeResponse) Write(b []byte) (n int, err error) {
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func BenchmarkWithout(b *testing.B) {
|
||||
res := FakeResponse{http.Header{}}
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
testHandler.ServeHTTP(res, req)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDefault(b *testing.B) {
|
||||
res := FakeResponse{http.Header{}}
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "somedomain.com")
|
||||
handler := Default().Handler(testHandler)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
handler.ServeHTTP(res, req)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAllowedOrigin(b *testing.B) {
|
||||
res := FakeResponse{http.Header{}}
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "somedomain.com")
|
||||
c := New(Options{
|
||||
AllowedOrigins: []string{"somedomain.com"},
|
||||
})
|
||||
handler := c.Handler(testHandler)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
handler.ServeHTTP(res, req)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPreflight(b *testing.B) {
|
||||
res := FakeResponse{http.Header{}}
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
handler := Default().Handler(testHandler)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
handler.ServeHTTP(res, req)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPreflightHeader(b *testing.B) {
|
||||
res := FakeResponse{http.Header{}}
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
req.Header.Add("Access-Control-Request-Headers", "Accept")
|
||||
handler := Default().Handler(testHandler)
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
handler.ServeHTTP(res, req)
|
||||
}
|
||||
}
|
||||
371
vendor/github.com/rs/cors/cors_test.go
generated
vendored
371
vendor/github.com/rs/cors/cors_test.go
generated
vendored
@@ -1,371 +0,0 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("bar"))
|
||||
})
|
||||
|
||||
func assertHeaders(t *testing.T, resHeaders http.Header, reqHeaders map[string]string) {
|
||||
for name, value := range reqHeaders {
|
||||
if actual := strings.Join(resHeaders[name], ", "); actual != value {
|
||||
t.Errorf("Invalid header `%s', wanted `%s', got `%s'", name, value, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoConfig(t *testing.T) {
|
||||
s := New(Options{
|
||||
// Intentionally left blank.
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestMatchAllOrigin(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestAllowedOrigin(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestWildcardOrigin(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://*.bar.com"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foo.bar.com")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "http://foo.bar.com",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestDisallowedOrigin(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://barbaz.com")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestDisallowedWildcardOrigin(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://*.bar.com"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foo.baz.com")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestAllowedOriginFunc(t *testing.T) {
|
||||
r, _ := regexp.Compile("^http://foo")
|
||||
s := New(Options{
|
||||
AllowOriginFunc: func(o string) bool {
|
||||
return r.MatchString(o)
|
||||
},
|
||||
})
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req.Header.Set("Origin", "http://foobar.com")
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
})
|
||||
|
||||
res = httptest.NewRecorder()
|
||||
req.Header.Set("Origin", "http://barfoo.com")
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Access-Control-Allow-Origin": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestAllowedMethod(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
AllowedMethods: []string{"PUT", "DELETE"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "PUT")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "PUT",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestDisallowedMethod(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
AllowedMethods: []string{"PUT", "DELETE"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "PATCH")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestAllowedHeader(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
AllowedHeaders: []string{"X-Header-1", "x-header-2"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
req.Header.Add("Access-Control-Request-Headers", "X-Header-2, X-HEADER-1")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "GET",
|
||||
"Access-Control-Allow-Headers": "X-Header-2, X-Header-1",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestAllowedWildcardHeader(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
AllowedHeaders: []string{"*"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
req.Header.Add("Access-Control-Request-Headers", "X-Header-2, X-HEADER-1")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "GET",
|
||||
"Access-Control-Allow-Headers": "X-Header-2, X-Header-1",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestDisallowedHeader(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
AllowedHeaders: []string{"X-Header-1", "x-header-2"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
req.Header.Add("Access-Control-Request-Headers", "X-Header-3, X-Header-1")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOriginHeader(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
req.Header.Add("Access-Control-Request-Headers", "origin")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "GET",
|
||||
"Access-Control-Allow-Headers": "Origin",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
|
||||
func TestExposedHeader(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
ExposedHeaders: []string{"X-Header-1", "x-header-2"},
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "X-Header-1, X-Header-2",
|
||||
})
|
||||
}
|
||||
|
||||
func TestAllowedCredentials(t *testing.T) {
|
||||
s := New(Options{
|
||||
AllowedOrigins: []string{"http://foobar.com"},
|
||||
AllowCredentials: true,
|
||||
})
|
||||
|
||||
res := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("OPTIONS", "http://example.com/foo", nil)
|
||||
req.Header.Add("Origin", "http://foobar.com")
|
||||
req.Header.Add("Access-Control-Request-Method", "GET")
|
||||
|
||||
s.Handler(testHandler).ServeHTTP(res, req)
|
||||
|
||||
assertHeaders(t, res.Header(), map[string]string{
|
||||
"Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
"Access-Control-Allow-Origin": "http://foobar.com",
|
||||
"Access-Control-Allow-Methods": "GET",
|
||||
"Access-Control-Allow-Headers": "",
|
||||
"Access-Control-Allow-Credentials": "true",
|
||||
"Access-Control-Max-Age": "",
|
||||
"Access-Control-Expose-Headers": "",
|
||||
})
|
||||
}
|
||||
70
vendor/github.com/rs/cors/utils_test.go
generated
vendored
70
vendor/github.com/rs/cors/utils_test.go
generated
vendored
@@ -1,70 +0,0 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWildcard(t *testing.T) {
|
||||
w := wildcard{"foo", "bar"}
|
||||
if !w.match("foobar") {
|
||||
t.Error("foo*bar should match foobar")
|
||||
}
|
||||
if !w.match("foobazbar") {
|
||||
t.Error("foo*bar should match foobazbar")
|
||||
}
|
||||
if w.match("foobaz") {
|
||||
t.Error("foo*bar should not match foobaz")
|
||||
}
|
||||
|
||||
w = wildcard{"foo", "oof"}
|
||||
if w.match("foof") {
|
||||
t.Error("foo*oof should not match foof")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
s := convert([]string{"A", "b", "C"}, strings.ToLower)
|
||||
e := []string{"a", "b", "c"}
|
||||
if s[0] != e[0] || s[1] != e[1] || s[2] != e[2] {
|
||||
t.Errorf("%v != %v", s, e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHeaderList(t *testing.T) {
|
||||
h := parseHeaderList("header, second-header, THIRD-HEADER, Numb3r3d-H34d3r")
|
||||
e := []string{"Header", "Second-Header", "Third-Header", "Numb3r3d-H34d3r"}
|
||||
if h[0] != e[0] || h[1] != e[1] || h[2] != e[2] {
|
||||
t.Errorf("%v != %v", h, e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHeaderListEmpty(t *testing.T) {
|
||||
if len(parseHeaderList("")) != 0 {
|
||||
t.Error("should be empty sclice")
|
||||
}
|
||||
if len(parseHeaderList(" , ")) != 0 {
|
||||
t.Error("should be empty sclice")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseHeaderList(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
parseHeaderList("header, second-header, THIRD-HEADER")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseHeaderListSingle(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
parseHeaderList("header")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseHeaderListNormalized(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
parseHeaderList("Header1, Header2, Third-Header")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user