This commit is contained in:
@@ -32,58 +32,59 @@ func TestEndToEnd(t *testing.T) {
|
||||
srv = client.Server{Name: "MyServer", Url: "meow://127.0.0.1"}
|
||||
Me.MessageServers.StoreServer(&srv)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Create an invitation for a friend, I want him/her to know me as Bender //
|
||||
// STEP_1: Create an invitation — only a temp keypair, no full ContactCard //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
fmt.Println("Creating an invitation for the first friend...")
|
||||
peer, err := Me.InvitePeer("Bender", "myfirstfriend", []string{"http://127.0.0.1/meow/", "mqtt://127.0.0.1"}, "welcome, it's me!")
|
||||
initPayload, peer, err := Me.InvitationStep1("Bender", "myfirstfriend", []string{"http://127.0.0.1/meow/", "mqtt://127.0.0.1"}, "welcome, it's me!")
|
||||
if err != nil {
|
||||
println(err)
|
||||
}
|
||||
println(peer.Name)
|
||||
// print my invitation
|
||||
a, _ := json.Marshal(peer.GetMyContact())
|
||||
fmt.Println(string(a))
|
||||
// TODO : Convert invitation to QR Code
|
||||
peer.GetMyContact().WritePng("invitation.png")
|
||||
data, err := peer.GetMyContact().Compress()
|
||||
a, _ := json.Marshal(initPayload)
|
||||
fmt.Println("InvitationInitPayload:", string(a))
|
||||
data, err := initPayload.Compress()
|
||||
if err != nil {
|
||||
println(err)
|
||||
}
|
||||
peer.GetMyContact().WriteQr("qrcode.png")
|
||||
println("Compressed contact card :", len(data))
|
||||
///////////////////////////////////////
|
||||
// Simulate peer invitation response //
|
||||
///////////////////////////////////////
|
||||
fmt.Println("Simulating first friend answer...")
|
||||
var ReceivedContact meowlib.ContactCard
|
||||
initPayload.WriteQr("qrcode.png")
|
||||
println("Compressed init payload :", len(data))
|
||||
|
||||
// Friend simulated invitation
|
||||
FirstFriendContactKp, err := meowlib.NewKeyPair()
|
||||
///////////////////////////////////////////////////////
|
||||
// STEP_2: Simulate friend receiving the payload and answering //
|
||||
///////////////////////////////////////////////////////
|
||||
fmt.Println("Simulating first friend answer (STEP_2)...")
|
||||
friendMe, err := client.CreateIdentity("friendname")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
FirstFriendEncryptionKp, err := meowlib.NewKeyPair()
|
||||
friendPeer, err := friendMe.InvitationStep2("FriendNick", "Bender", []string{}, initPayload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
FirstFriendLookupKp, err := meowlib.NewKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ReceivedContact.Name = "I'm the friend"
|
||||
ReceivedContact.ContactPublicKey = FirstFriendContactKp.Public
|
||||
ReceivedContact.EncryptionPublicKey = FirstFriendEncryptionKp.Public
|
||||
ReceivedContact.LookupPublicKey = FirstFriendLookupKp.Public
|
||||
ReceivedContact.InvitationId = peer.GetMyContact().InvitationId
|
||||
friendCC := friendPeer.GetMyContact()
|
||||
FriendServer1KP, err := meowlib.NewKeyPair()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
FriendServer1 := meowlib.ServerCard{Name: "FriendServer1", Url: "http://myfriend.org/meow/", PublicKey: FriendServer1KP.Public, Description: "Fancy description"}
|
||||
ReceivedContact.PullServers = append(ReceivedContact.PullServers, &FriendServer1)
|
||||
friendCC.PullServers = append(friendCC.PullServers, &FriendServer1)
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// Finalize the contact with the invitation response //
|
||||
///////////////////////////////////////////////////////
|
||||
Me.FinalizeInvitation(&ReceivedContact)
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// STEP_3: Initiator receives friend's CC, generates full keypairs //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
myCC, _, err := Me.InvitationStep3(friendCC)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Println("Initiator ContactCard ready:", myCC.ContactPublicKey != "")
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// STEP_4: Friend finalizes initiator's ContactCard //
|
||||
////////////////////////////////////////////////////
|
||||
err = friendMe.InvitationStep4(myCC)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = Me.Save()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user