Exemplo 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)
	}
}
Exemplo n.º 2
0
func TestTicketSimilarity(t *testing.T) {
	var t0, t1 string
	for i := 0; i < 100; i++ {
		t1 = ticket.Grant("jb", "10.2.3.4", int64(1234567890+i/10))
		if t0 == t1 {
			t.Errorf("identical keys generated (%q)", t0)
			break
		}
		t0 = t1
	}
}
Exemplo n.º 3
0
func TestGrantVerifyOK(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)
	}
}
Exemplo n.º 4
0
func TestGrantVerifyExpired(t *testing.T) {
	tic := ticket.Grant("jb", "10.2.3.4", 1234567890)

	user, err := ticket.Verify(tic, "10.2.3.4", 1234567891)
	if user != "" {
		t.Errorf("unexpected user %q", user)
	}
	if err == nil {
		t.Errorf("unexpected nil err")
	}
}
Exemplo n.º 5
0
func TestGrantVerifyModified(t *testing.T) {
	tic := ticket.Grant("jb", "10.2.3.4", 1234567890)

	fail := "A" + tic[:len(tic)-1]
	user, err := ticket.Verify(fail, "10.2.3.4", 1234567890)
	if user != "" {
		t.Errorf("unexpected user %q", user)
	}
	if err == nil {
		t.Errorf("unexpected nil err")
	}
}