func (c Configuration) User() domain.User { token, err := c.Store.Get("APIToken") handleError(err) user := domain.User{ APIToken: token, } user.SetAuthenticator(NewAPIAuthenticator()) return user }
) 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" Expect(u.IsAuthenticated()).To(BeTrue()) u.APIToken = "" Expect(u.IsAuthenticated()).To(BeFalse())