Beispiel #1
0
func PrepareTestAccountDaemon(name string, rootDir string, denameConfig *denameClient.Config, serverAddr string, serverPk *[32]byte, t testing.TB) *Daemon {
	dnmClient, err := denameClient.NewClient(denameConfig, nil, nil)

	//get port from serverAddr
	addr, portStr, err := net.SplitHostPort(serverAddr)
	if err != nil {
		t.Fatal(err)
	}
	var port int
	if _, err := fmt.Sscanf(portStr, "%d", &port); err != nil {
		t.Fatal(err)
	}

	//create the accounts with Init
	torAddr := "DANGEROUS_NO_TOR"
	err = Init(rootDir, name, addr, port, serverPk, torAddr)
	if err != nil {
		t.Fatal(err)
	}

	//initialize daemon with Load
	theDaemon, err := Load(rootDir, denameConfig)
	if err != nil {
		t.Fatal(err)
	}

	cbProfile := new(proto.Profile)
	if err := persistence.UnmarshalFromFile(theDaemon.OurChatterboxProfilePath(), cbProfile); err != nil {
		t.Fatal(err)
	}

	chatProfileBytes, err := protobuf.Marshal(cbProfile)
	if err != nil {
		t.Fatal(err)
	}

	denameProfile, sk, err := denameClient.NewProfile(nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	if err := denameClient.SetProfileField(denameProfile, cbClient.PROFILE_FIELD_ID, chatProfileBytes); err != nil {
		t.Fatal(err)
	}

	err = dnmClient.Register(sk, name, denameProfile, testutil2.MakeToken())
	if err != nil {
		t.Fatal(err)
	}

	return theDaemon
}
func createNewUser(name string, t *testing.T, config *client.Config) (*[32]byte, *client.Client) {
	newClient, err := client.NewClient(config, nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	//TODO: All these names are horrible, please change them
	pkAuth, skAuth, err := box.GenerateKey(rand.Reader)

	chatProfile := &proto.Profile{
		ServerAddressTCP:  "",
		ServerPortTCP:     -1,
		ServerTransportPK: (proto.Byte32)([32]byte{}),
		UserIDAtServer:    (proto.Byte32)([32]byte{}),
		KeySigningKey:     (proto.Byte32)([32]byte{}),
		MessageAuthKey:    (proto.Byte32)(*pkAuth),
	}

	chatProfileBytes, err := protobuf.Marshal(chatProfile)
	if err != nil {
		t.Fatal(err)
	}

	profile, sk, err := client.NewProfile(nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	client.SetProfileField(profile, PROFILE_FIELD_ID, chatProfileBytes)

	err = newClient.Register(sk, name, profile, testutil2.MakeToken())
	if err != nil {
		t.Fatal(err)
	}

	//Remove this outside of the test
	profile2, err := newClient.Lookup(name)
	if !profile.Equal(profile2) {
		t.Error("Correct profile not added to server.")
		fmt.Printf("profile: %v\n", profile)
		fmt.Printf("profile2: %v\n", profile2)
	}

	return skAuth, newClient
}
Beispiel #3
0
func CreateTestDenameAccount(name string, denameClient *client.Client, secretConfig *proto.LocalAccountConfig, serverAddr string, serverPk *[32]byte, t testing.TB) {
	//TODO: move this to test?
	//TODO: All these names are horrible, please change them
	addr, portStr, err := net.SplitHostPort(serverAddr)
	if err != nil {
		t.Fatal(err)
	}
	var port int32
	if _, err := fmt.Sscanf(portStr, "%d", &port); err != nil {
		t.Fatal(err)
	}

	chatProfile := &proto.Profile{
		ServerAddressTCP:  addr,
		ServerPortTCP:     port,
		ServerTransportPK: (proto.Byte32)(*serverPk),
	}

	if err := GenerateLongTermKeys(secretConfig, chatProfile, rand.Reader); err != nil {
		t.Fatal(err)
	}

	chatProfileBytes, err := protobuf.Marshal(chatProfile)
	if err != nil {
		t.Fatal(err)
	}

	profile, sk, err := client.NewProfile(nil, nil)
	if err != nil {
		t.Fatal(err)
	}

	client.SetProfileField(profile, PROFILE_FIELD_ID, chatProfileBytes)

	err = denameClient.Register(sk, name, profile, testutil2.MakeToken())
	if err != nil {
		t.Fatal(err)
	}
}