|
|
@ -17,6 +17,7 @@ |
|
|
|
package cmd |
|
|
|
package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
@ -38,6 +39,12 @@ func (p postHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
|
|
io.Copy(w, r.Body) |
|
|
|
io.Copy(w, r.Body) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type errorHandler struct{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e errorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
http.Error(w, fmt.Sprintf("Unexpected method %s", r.Method), http.StatusBadRequest) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests web hook initialization.
|
|
|
|
// Tests web hook initialization.
|
|
|
|
func TestNewWebHookNotify(t *testing.T) { |
|
|
|
func TestNewWebHookNotify(t *testing.T) { |
|
|
|
root, err := newTestConfig(globalMinioDefaultRegion) |
|
|
|
root, err := newTestConfig(globalMinioDefaultRegion) |
|
|
@ -53,8 +60,8 @@ func TestNewWebHookNotify(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
serverConfig.Notify.SetWebhookByID("10", webhookNotify{Enable: true, Endpoint: "http://127.0.0.1:xxx"}) |
|
|
|
serverConfig.Notify.SetWebhookByID("10", webhookNotify{Enable: true, Endpoint: "http://127.0.0.1:xxx"}) |
|
|
|
_, err = newWebhookNotify("10") |
|
|
|
_, err = newWebhookNotify("10") |
|
|
|
if err == nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal("Unexpected should fail with lookupHost") |
|
|
|
t.Fatal("Unexpected should not fail with lookupEndpoint", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
serverConfig.Notify.SetWebhookByID("15", webhookNotify{Enable: true, Endpoint: "http://%"}) |
|
|
|
serverConfig.Notify.SetWebhookByID("15", webhookNotify{Enable: true, Endpoint: "http://%"}) |
|
|
@ -77,3 +84,35 @@ func TestNewWebHookNotify(t *testing.T) { |
|
|
|
"EventType": "s3:ObjectCreated:Put", |
|
|
|
"EventType": "s3:ObjectCreated:Put", |
|
|
|
}).Info() |
|
|
|
}).Info() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add tests for lookup endpoint.
|
|
|
|
|
|
|
|
func TestLookupEndpoint(t *testing.T) { |
|
|
|
|
|
|
|
server := httptest.NewServer(errorHandler{}) |
|
|
|
|
|
|
|
defer server.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testCases := []struct { |
|
|
|
|
|
|
|
endpoint string |
|
|
|
|
|
|
|
err error |
|
|
|
|
|
|
|
}{ |
|
|
|
|
|
|
|
// Ignore endpoints which don't exist.
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
endpoint: "http://unknown", |
|
|
|
|
|
|
|
err: nil, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
endpoint: "%%%", |
|
|
|
|
|
|
|
err: errors.New("parse %%%: invalid URL escape \"%%%\""), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
endpoint: server.URL, |
|
|
|
|
|
|
|
err: fmt.Errorf("Unexpected response from webhook server %s: (400 Bad Request)", server.URL), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, test := range testCases { |
|
|
|
|
|
|
|
if err := lookupEndpoint(test.endpoint); err != nil { |
|
|
|
|
|
|
|
if err.Error() != test.err.Error() { |
|
|
|
|
|
|
|
t.Errorf("Expected %s, got %s", test.err, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|