diff options
| -rw-r--r-- | handlers.go | 39 | ||||
| -rw-r--r-- | handlers_test.go | 21 |
2 files changed, 0 insertions, 60 deletions
diff --git a/handlers.go b/handlers.go index df1794a..8f3d460 100644 --- a/handlers.go +++ b/handlers.go @@ -17,7 +17,6 @@ var frontendEmbed embed.FS func registerHandlers(r *mux.Router, db *sql.DB) { r.Handle("/api/version", version(db)) - r.Handle("/api/registration", ApiRegistration(db)) r.Handle("/api/authentication", ApiAuthentication(db)) // frontend must come last to make sure /api takes precedence @@ -34,44 +33,6 @@ func version(db *sql.DB) http.Handler { }) } -func ApiRegistration(db *sql.DB) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var data struct { - Username string - Password string - } - - dec := json.NewDecoder(r.Body) - dec.DisallowUnknownFields() - - err := dec.Decode(&data) - if err != nil { - log.Printf("Failed to decode: %v", err) - w.WriteHeader(http.StatusBadRequest) - return - } - - if data.Username == "" { - log.Print("Got registration request with empty username") - w.WriteHeader(http.StatusBadRequest) - return - } - - if data.Password == "" { - log.Print("Got registration request with empty password") - w.WriteHeader(http.StatusBadRequest) - return - } - - err = Register(db, data.Username, data.Password) - if err != nil { - log.Printf("Failed to register new user: %v", err) - w.WriteHeader(http.StatusInternalServerError) - return - } - }) -} - func ApiAuthentication(db *sql.DB) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var data struct { diff --git a/handlers_test.go b/handlers_test.go index f24bde4..c3bdabf 100644 --- a/handlers_test.go +++ b/handlers_test.go @@ -64,27 +64,6 @@ func TestHTTPVersion(t *testing.T) { testHandler(t, version, cases, setup) } -func TestHTTPRegister(t *testing.T) { - cases := []httpCase{ - {"basic", "POST", `{"username":"testuser","password":"mypass"}`, "", http.StatusOK}, - {"missing-password", "POST", `{"username":"testuser"}`, "", http.StatusBadRequest}, - {"missing-username", "POST", `{"password":"mypass"}`, "", http.StatusBadRequest}, - {"unknown-field", "POST", `{"username":"testuser","password":"mypass","foo":"bar"}`, "", http.StatusBadRequest}, - {"invalid-json", "POST", `{username":"testuser","password":"mypass"}`, "", http.StatusBadRequest}, - } - - setup := func(t *testing.T) *sql.DB { - db, _ := emptyDB(t) - err := MigrateToLatest(db) - if err != nil { - t.Fatalf("Could not migrate test database: %v", err) - } - return db - } - - testHandler(t, ApiRegistration, cases, setup) -} - func TestHTTPAuthenticate(t *testing.T) { cases := []httpCase{ {"basic", "POST", `{"username":"testuser","password":"mypass"}`, "", http.StatusOK}, |
