Add bad request status code for wrong action

This commit is contained in:
Peter Stuifzand 2018-12-09 17:46:47 +01:00
parent 7d61179ee1
commit 226a35fb43
Signed by: peter
GPG Key ID: 374322D56E5209E8
2 changed files with 17 additions and 1 deletions

View File

@ -108,7 +108,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
cons := newConsumer(conn)
h.backend.AddEventListener(cons)
} else {
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 400)
return
}
return

View File

@ -1,6 +1,7 @@
package server
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
@ -131,3 +132,18 @@ func TestServer_Search(t *testing.T) {
assert.Equal(t, "test", feeds[0].Description)
}
}
func TestServer_UnknownAction(t *testing.T) {
server, c := createServerClient()
defer server.Close()
u := c.MicrosubEndpoint
q := u.Query()
q.Add("action", "missing")
u.RawQuery = q.Encode()
resp, err := http.Get(u.String())
if assert.NoError(t, err) {
assert.Equal(t, 400, resp.StatusCode)
}
}