func TestPANDA(t *testing.T) { t.Parallel() server, err := NewTestServer(t) if err != nil { t.Fatal(err) } defer server.Close() client1, err := NewTestClient(t, "client1", nil) if err != nil { t.Fatal(err) } defer client1.Close() client2, err := NewTestClient(t, "client2", nil) if err != nil { t.Fatal(err) } defer client2.Close() mpShutdownChan := make(chan bool) mp := panda.NewSimpleMeetingPlace(mpShutdownChan) newMeetingPlace := func() panda.MeetingPlace { return mp } client1.newMeetingPlace = newMeetingPlace client2.newMeetingPlace = newMeetingPlace startPANDAKeyExchange(t, client1, server, "client2", "shared secret") mpShutdownChan <- true client1.ReloadWithMeetingPlace(mp) startPANDAKeyExchange(t, client2, server, "client1", "shared secret") var wg sync.WaitGroup wg.Add(2) go func() { client1.AdvanceTo(uiStatePANDAComplete) wg.Done() }() go func() { client2.AdvanceTo(uiStatePANDAComplete) wg.Done() }() wg.Wait() var client2FromClient1 *Contact for _, contact := range client1.contacts { client2FromClient1 = contact break } var client1FromClient2 *Contact for _, contact := range client2.contacts { client1FromClient2 = contact break } if g := client2FromClient1.generation; g != client2.generation { t.Errorf("Generation mismatch %d vs %d", g, client1.generation) } if g := client1FromClient2.generation; g != client1.generation { t.Errorf("Generation mismatch %d vs %d", g, client1.generation) } }
func TestDelete(t *testing.T) { // Test that deleting contacts works. if parallel { t.Parallel() } server, err := NewTestServer(t) if err != nil { t.Fatal(err) } defer server.Close() client1, err := NewTestClient(t, "client1", nil) if err != nil { t.Fatal(err) } defer client1.Close() client2, err := NewTestClient(t, "client2", nil) if err != nil { t.Fatal(err) } defer client2.Close() // Setup a normal pair of clients. proceedToPaired(t, client1, client2, server) const testMsg = "test message" sendMessage(client1, "client2", testMsg) from, _ := fetchMessage(client2) if from != "client1" { t.Fatalf("message from %s, expected client1", from) } // Start an incomplete, manual exchange. proceedToKeyExchange(t, client1, server, "client3") // Start a PANDA exchange. mp := panda.NewSimpleMeetingPlace() newMeetingPlace := func() panda.MeetingPlace { return mp } client1.newMeetingPlace = newMeetingPlace startPANDAKeyExchange(t, client1, server, "client4", "secret") client1.AdvanceTo(uiStateShowContact) clickOnContact(client1, "client2") client1.gui.events <- Click{name: "delete"} client1.gui.events <- Click{name: "delete"} client1.AdvanceTo(uiStateRevocationComplete) if len(client1.inbox) > 0 { t.Errorf("still entries in inbox") } for _, msg := range client1.outbox { if !msg.revocation { t.Errorf("still entries in outbox") break } } clickOnContact(client1, "client3") client1.gui.events <- Click{name: "abort"} client1.AdvanceTo(uiStateRevocationComplete) clickOnContact(client1, "client4") client1.gui.events <- Click{name: "delete"} client1.gui.events <- Click{name: "delete"} client1.AdvanceTo(uiStateRevocationComplete) if len(client1.contacts) > 0 { t.Errorf("still contacts") } client1.Reload() client1.AdvanceTo(uiStateMain) }