示例#1
0
文件: ticket_test.go 项目: reth-/mole
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)
	}
}
示例#2
0
文件: ticket_test.go 项目: reth-/mole
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
	}
}
示例#3
0
文件: ticket_test.go 项目: reth-/mole
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)
	}
}
示例#4
0
文件: ticket_test.go 项目: reth-/mole
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")
	}
}
示例#5
0
文件: ticket_test.go 项目: reth-/mole
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")
	}
}