Beispiel #1
0
func TestTokenId(t *testing.T) {
	defer log.AfterTest(t)
	t1 := &sda.Token{
		RosterID: sda.RosterID(uuid.NewV1()),
		TreeID:   sda.TreeID(uuid.NewV1()),
		ProtoID:  sda.ProtocolID(uuid.NewV1()),
		RoundID:  sda.RoundID(uuid.NewV1()),
	}
	id1 := t1.ID()
	t2 := &sda.Token{
		RosterID: sda.RosterID(uuid.NewV1()),
		TreeID:   sda.TreeID(uuid.NewV1()),
		ProtoID:  sda.ProtocolID(uuid.NewV1()),
		RoundID:  sda.RoundID(uuid.NewV1()),
	}
	id2 := t2.ID()
	if uuid.Equal(uuid.UUID(id1), uuid.UUID(id2)) {
		t.Fatal("Both token are the same")
	}
	if !uuid.Equal(uuid.UUID(id1), uuid.UUID(t1.ID())) {
		t.Fatal("Twice the Id of the same token should be equal")
	}
	t3 := t1.ChangeTreeNodeID(sda.TreeNodeID(uuid.NewV1()))
	if t1.TreeNodeID.Equal(t3.TreeNodeID) {
		t.Fatal("OtherToken should modify copy")
	}
}
Beispiel #2
0
// Test propagation of tree - both known and unknown
func TestTreePropagation(t *testing.T) {
	defer log.AfterTest(t)
	local := sda.NewLocalTest()
	hosts, el, tree := local.GenTree(2, true, false, false)
	defer local.CloseAll()
	h1 := hosts[0]
	h2 := hosts[1]
	// Suppose both hosts have the list available, but not the tree
	h1.AddRoster(el)
	h2.AddRoster(el)
	h2.StartProcessMessages()

	// Check that h2 sends back an empty tree if it is unknown
	err := h1.SendRaw(h2.ServerIdentity, &sda.RequestTree{TreeID: tree.ID})
	if err != nil {
		t.Fatal("Couldn't send message to h2:", err)
	}
	msg := h1.Receive()
	if msg.MsgType != sda.SendTreeMessageID {
		network.DumpTypes()
		t.Fatal("h1 didn't receive SendTree type:", msg.MsgType)
	}
	if msg.Msg.(sda.TreeMarshal).RosterID != sda.RosterID(uuid.Nil) {
		t.Fatal("List should be empty")
	}

	// Now add the list to h2 and try again
	h2.AddTree(tree)
	err = h1.SendRaw(h2.ServerIdentity, &sda.RequestTree{TreeID: tree.ID})
	if err != nil {
		t.Fatal("Couldn't send message to h2:", err)
	}
	msg = h1.Receive()
	if msg.MsgType != sda.SendTreeMessageID {
		t.Fatal("h1 didn't receive Tree-type")
	}
	if msg.Msg.(sda.TreeMarshal).TreeID != tree.ID {
		t.Fatal("Tree should be equal to original tree")
	}

	// And test whether it gets stored correctly
	h1.StartProcessMessages()
	err = h1.SendRaw(h2.ServerIdentity, &sda.RequestTree{TreeID: tree.ID})
	if err != nil {
		t.Fatal("Couldn't send message to h2:", err)
	}
	time.Sleep(time.Second)
	tree2, ok := h1.GetTree(tree.ID)
	if !ok {
		t.Fatal("List-id not found")
	}
	if !tree.Equal(tree2) {
		t.Fatal("Trees do not match")
	}
}
Beispiel #3
0
// Test propagation of peer-lists - both known and unknown
func TestPeerListPropagation(t *testing.T) {
	defer log.AfterTest(t)
	local := sda.NewLocalTest()
	hosts, el, _ := local.GenTree(2, false, false, false)
	defer local.CloseAll()
	h1 := hosts[0]
	h2 := hosts[1]
	h2.StartProcessMessages()

	// Check that h2 sends back an empty list if it is unknown
	err := h1.SendRaw(h2.ServerIdentity, &sda.RequestRoster{
		RosterID: el.ID})
	if err != nil {
		t.Fatal("Couldn't send message to h2:", err)
	}
	msg := h1.Receive()
	if msg.MsgType != sda.SendRosterMessageID {
		t.Fatal("h1 didn't receive Roster type, but", msg.MsgType)
	}
	if msg.Msg.(sda.Roster).ID != sda.RosterID(uuid.Nil) {
		t.Fatal("List should be empty")
	}

	// Now add the list to h2 and try again
	h2.AddRoster(el)
	err = h1.SendRaw(h2.ServerIdentity, &sda.RequestRoster{RosterID: el.ID})
	if err != nil {
		t.Fatal("Couldn't send message to h2:", err)
	}
	msg = h1.Receive()
	if msg.MsgType != sda.SendRosterMessageID {
		t.Fatal("h1 didn't receive Roster type")
	}
	if msg.Msg.(sda.Roster).ID != el.ID {
		t.Fatal("List should be equal to original list")
	}

	// And test whether it gets stored correctly
	h1.StartProcessMessages()
	err = h1.SendRaw(h2.ServerIdentity, &sda.RequestRoster{RosterID: el.ID})
	if err != nil {
		t.Fatal("Couldn't send message to h2:", err)
	}
	time.Sleep(time.Second)
	list, ok := h1.Roster(el.ID)
	if !ok {
		t.Fatal("List-id not found")
	}
	if list.ID != el.ID {
		t.Fatal("IDs do not match")
	}
}