2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-05 19:50:57 +00:00
|
|
|
|
|
|
|
import (
|
2016-09-08 01:24:11 +00:00
|
|
|
"bytes"
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-09-05 19:50:57 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2016-09-08 01:24:11 +00:00
|
|
|
func TestDecodeLoginRequest(t *testing.T) {
|
|
|
|
router := mux.NewRouter()
|
2021-02-10 20:13:11 +00:00
|
|
|
router.HandleFunc("/api/v1/fleet/login", func(writer http.ResponseWriter, request *http.Request) {
|
2016-09-08 01:24:11 +00:00
|
|
|
r, err := decodeLoginRequest(context.Background(), request)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
params := r.(loginRequest)
|
2021-06-24 20:42:29 +00:00
|
|
|
assert.Equal(t, "foo", params.Email)
|
2016-09-08 01:24:11 +00:00
|
|
|
assert.Equal(t, "bar", params.Password)
|
|
|
|
}).Methods("POST")
|
2021-06-24 20:42:29 +00:00
|
|
|
t.Run("lowercase email", func(t *testing.T) {
|
2016-10-12 16:35:34 +00:00
|
|
|
var body bytes.Buffer
|
|
|
|
body.Write([]byte(`{
|
2021-06-24 20:42:29 +00:00
|
|
|
"email": "foo",
|
2016-09-08 01:24:11 +00:00
|
|
|
"password": "bar"
|
|
|
|
}`))
|
|
|
|
|
2016-10-12 16:35:34 +00:00
|
|
|
router.ServeHTTP(
|
|
|
|
httptest.NewRecorder(),
|
2021-02-10 20:13:11 +00:00
|
|
|
httptest.NewRequest("POST", "/api/v1/fleet/login", &body),
|
2016-10-12 16:35:34 +00:00
|
|
|
)
|
|
|
|
})
|
2021-06-24 20:42:29 +00:00
|
|
|
t.Run("uppercase email", func(t *testing.T) {
|
2016-10-12 16:35:34 +00:00
|
|
|
var body bytes.Buffer
|
|
|
|
body.Write([]byte(`{
|
2021-06-24 20:42:29 +00:00
|
|
|
"email": "Foo",
|
2016-10-12 16:35:34 +00:00
|
|
|
"password": "bar"
|
|
|
|
}`))
|
|
|
|
|
|
|
|
router.ServeHTTP(
|
|
|
|
httptest.NewRecorder(),
|
2021-02-10 20:13:11 +00:00
|
|
|
httptest.NewRequest("POST", "/api/v1/fleet/login", &body),
|
2016-10-12 16:35:34 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2016-09-08 01:24:11 +00:00
|
|
|
}
|