Ejemplo n.º 1
0
func (c Configuration) User() domain.User {
	token, err := c.Store.Get("APIToken")
	handleError(err)

	user := domain.User{
		APIToken: token,
	}
	user.SetAuthenticator(NewAPIAuthenticator())
	return user
}
Ejemplo n.º 2
0
import (
	. "github.com/pivotal/gumshoe/repos/ginkgo"
	. "github.com/pivotal/gumshoe/repos/gomega"
	"github.com/pivotal/gumshoe/trackerapi/domain"
)

type FakeAuthenticator struct {
	APIToken string
}

func (fa *FakeAuthenticator) Authenticate(user domain.User) (string, error) {
	return fa.APIToken, nil
}

var _ = Describe("User", func() {
	var u domain.User

	BeforeEach(func() {
		u = domain.User{}
		u.SetAuthenticator(&FakeAuthenticator{APIToken: "abcde12345"})
	})

	It("stores the Username and Password", func() {
		u.Login("mister_tee", "sekret")
		Expect(u.Username).To(Equal("mister_tee"))
		Expect(u.Password).To(Equal("sekret"))
	})

	Describe("IsAuthenticated", func() {
		It("returns the authenticated state of the user object", func() {
			u.APIToken = "abcde"