Ejemplo n.º 1
0
func TestTicketExtendValidity(t *testing.T) {
	tic := ticket.Grant("jb", "10.2.3.4", 1234567890)

	user, err := ticket.Verify(tic, "10.2.3.4", 1234567890)
	if user != "jb" {
		t.Errorf("unexpected user %q", user)
	}
	if err != nil {
		t.Errorf("unexpected err %s", err)
	}

	ts, err := ticket.Load(tic)
	if err != nil {
		t.Error(err)
	}
	ts.Validity = 1234567900
	tic = ts.String()

	user, err = ticket.Verify(tic, "10.2.3.4", 1234567895)
	if user != "jb" {
		t.Errorf("unexpected user %q", user)
	}
	if err != nil {
		t.Errorf("unexpected err %s", err)
	}
}
Ejemplo n.º 2
0
func getTicket(req *http.Request) ticket.Ticket {
	ticStr := req.Header.Get("X-Mole-Ticket")
	if ticStr != "" {
		ticp, err := ticket.Load(ticStr)
		if ticp != nil && err == nil {
			return *ticp
		}
	}
	return ticket.Ticket{}
}
Ejemplo n.º 3
0
func parseTicket(rw http.ResponseWriter, req *http.Request) {
	ticStr := req.Header.Get("X-Mole-Ticket")
	tic, err := ticket.Load(ticStr)
	if err != nil {
		rw.WriteHeader(403)
		rw.Write([]byte(err.Error()))
		return
	}

	// Manually create a map with the interesting fields to avoid inadvertently
	// exposing something sensitive such as the Nonce or fields added to the
	// ticket struct in the future.

	exposedFields := map[string]interface{}{
		"user":     tic.User,
		"ips":      tic.IP,
		"validity": tic.Validity,
	}
	json.NewEncoder(rw).Encode(exposedFields)
	return
}