Esempio n. 1
0
func TestUserInjection(t *testing.T) {
	Convey("With a dbUser and a request", t, func() {
		u := &user.DBUser{Id: "name1"}
		r, err := http.NewRequest("GET", "/", bytes.NewBufferString("{}"))
		So(err, ShouldBeNil)

		Convey("the user should possible to set and retrieve", func() {
			plugin.SetUser(u, r)
			So(plugin.GetUser(r), ShouldResemble, u)
		})
	})
}
Esempio n. 2
0
func (hwp *HelloWorldPlugin) GetUIHandler() http.Handler {
	renderer := render.New(render.Options{})
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// this handler returns the Id of the current user, as a sanity check that
		// proves plugins have access to user information.
		userId := "Not Logged In"
		u := plugin.GetUser(r)
		if u != nil {
			userId = u.Id
		}
		renderer.WriteJSON(w, http.StatusOK, struct {
			UserId string
		}{userId})
	})
}