func TestAuthenticateUser(t *testing.T) { certs, err := auth.GenerateTestCerts() if err != nil { t.Errorf("error generating test certs %v", err) } store := users.NewUserStoreLocal() store.Create(NewUser()) ws := NewAuthResource(store, nil, certs) req := newFormRequest("POST", "http://api.his.com/users", bytes.NewBufferString("login=wolfeidau&password=Somewh3r3 there is a cow!")) recorder, resp := newResponse() ws.authenticateUser(req, resp) if recorder.Code != 200 { t.Errorf("expected 200 got %d %s", recorder.Code, recorder.Body.String()) } if recorder.Header().Get("Authorization") == "" { t.Errorf("expected authorization header to exist") } }
func setupResourceAndStore() (users.UserStore, *UserResource) { store := users.NewUserStoreLocal() store.Create(NewUser()) ws := NewUserResource(store, nil) return store, ws }
func TestCreateUser(t *testing.T) { ws := NewUserResource(users.NewUserStoreLocal(), nil) req := newRequest("POST", "http://api.his.com/users", bytes.NewBufferString(newUserJSON)) recorder, resp := newResponse() ws.createUser(req, resp) if recorder.Code != 201 { t.Errorf("expected 201 got %d %s", recorder.Code, recorder.Body.String()) } }