2018-02-04 18:30:39 -08:00
|
|
|
package defaults
|
|
|
|
|
|
|
|
import (
|
2018-05-09 07:59:19 -07:00
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
2018-02-04 18:30:39 -08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/volatiletech/authboss"
|
|
|
|
"github.com/volatiletech/authboss/internal/mocks"
|
|
|
|
)
|
|
|
|
|
2018-05-09 07:59:19 -07:00
|
|
|
func TestHTTPBodyReader(t *testing.T) {
|
2018-02-04 18:30:39 -08:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-05-09 07:59:19 -07:00
|
|
|
h := NewHTTPBodyReader(false, false)
|
2018-02-04 18:30:39 -08:00
|
|
|
r := mocks.Request("POST", "email", "john@john.john", "password", "flowers")
|
|
|
|
|
|
|
|
validator, err := h.Read("login", r)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
uv := validator.(authboss.UserValuer)
|
|
|
|
if "john@john.john" != uv.GetPID() {
|
|
|
|
t.Error("wrong e-mail:", uv.GetPID())
|
|
|
|
}
|
|
|
|
if "flowers" != uv.GetPassword() {
|
|
|
|
t.Error("wrong password:", uv.GetPassword())
|
|
|
|
}
|
|
|
|
}
|
2018-05-09 07:59:19 -07:00
|
|
|
|
|
|
|
func TestHTTPBodyReaderJSON(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
h := NewHTTPBodyReader(true, false)
|
|
|
|
r := httptest.NewRequest("POST", "/", strings.NewReader(`{"email":"john@john.john","password":"flowers"}`))
|
|
|
|
|
|
|
|
validator, err := h.Read("login", r)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
uv := validator.(authboss.UserValuer)
|
|
|
|
if "john@john.john" != uv.GetPID() {
|
|
|
|
t.Error("wrong e-mail:", uv.GetPID())
|
|
|
|
}
|
|
|
|
if "flowers" != uv.GetPassword() {
|
|
|
|
t.Error("wrong password:", uv.GetPassword())
|
|
|
|
}
|
|
|
|
}
|