mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
fix: tests pass now
This commit is contained in:
parent
36b091c640
commit
857d0a7ef1
@ -1 +1 @@
|
|||||||
Subproject commit 57f6bbd91bb4b1f2d115b75e8beb850153bb6767
|
Subproject commit 462e2b6808122919141e8636822cbf00f9f587e9
|
@ -1,6 +1,5 @@
|
|||||||
package network.loki.messenger.libsession_util
|
package network.loki.messenger.libsession_util
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import network.loki.messenger.libsession_util.util.KeyPair
|
import network.loki.messenger.libsession_util.util.KeyPair
|
||||||
@ -20,10 +19,11 @@ import org.session.libsignal.utilities.Hex
|
|||||||
class InstrumentedTests {
|
class InstrumentedTests {
|
||||||
|
|
||||||
private val keyPair: KeyPair
|
private val keyPair: KeyPair
|
||||||
get() {
|
get() {
|
||||||
val seed = Hex.fromStringCondensed("0123456789abcdef0123456789abcdef00000000000000000000000000000000")
|
val seed =
|
||||||
return Sodium.ed25519KeyPair(seed)
|
Hex.fromStringCondensed("0123456789abcdef0123456789abcdef00000000000000000000000000000000")
|
||||||
}
|
return Sodium.ed25519KeyPair(seed)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun useAppContext() {
|
fun useAppContext() {
|
||||||
@ -51,8 +51,8 @@ class InstrumentedTests {
|
|||||||
assertNull(userProfile.getName())
|
assertNull(userProfile.getName())
|
||||||
|
|
||||||
// Don't need to push yet so this is just for testing
|
// Don't need to push yet so this is just for testing
|
||||||
val (toPush, seqNo) = userProfile.push()
|
val (_, seqNo) = userProfile.push() // disregarding encrypted
|
||||||
assertEquals("d1:#i0e1:&de1:<le1:=dee", toPush.decodeToString())
|
assertEquals("UserProfile", userProfile.encryptionDomain())
|
||||||
assertEquals(0, seqNo)
|
assertEquals(0, seqNo)
|
||||||
|
|
||||||
// This should also be unset:
|
// This should also be unset:
|
||||||
@ -76,26 +76,37 @@ class InstrumentedTests {
|
|||||||
assertTrue(userProfile.needsDump())
|
assertTrue(userProfile.needsDump())
|
||||||
val (newToPush, newSeqNo) = userProfile.push()
|
val (newToPush, newSeqNo) = userProfile.push()
|
||||||
|
|
||||||
val expHash0 = Hex.fromStringCondensed("ea173b57beca8af18c3519a7bbf69c3e7a05d1c049fa9558341d8ebb48b0c965")
|
val expHash0 =
|
||||||
val expectedPush1 = ("d" +
|
Hex.fromStringCondensed("ea173b57beca8af18c3519a7bbf69c3e7a05d1c049fa9558341d8ebb48b0c965")
|
||||||
"1:#" + "i1e"+
|
|
||||||
"1:&" + "d"+
|
val expectedPush1Decrypted = ("d" +
|
||||||
"1:n" + "6:Kallie"+
|
"1:#" + "i1e"+
|
||||||
"1:p" + "34:http://example.org/omg-pic-123.bmp"+
|
"1:&" + "d"+
|
||||||
"1:q" + "6:secret"+
|
"1:n" + "6:Kallie"+
|
||||||
"e"+
|
"1:p" + "34:http://example.org/omg-pic-123.bmp"+
|
||||||
"1:<" + "l"+
|
"1:q" + "6:secret"+
|
||||||
"l" + "i0e" + "32:").encodeToByteArray() + expHash0 + ("de" + "e" +
|
"e"+
|
||||||
"e" +
|
"1:<" + "l"+
|
||||||
"1:=" + "d" +
|
"l" + "i0e" + "32:").encodeToByteArray() + expHash0 + ("de" + "e" +
|
||||||
"1:n" + "0:" +
|
"e" +
|
||||||
"1:p" + "0:" +
|
"1:=" + "d" +
|
||||||
"1:q" + "0:" +
|
"1:n" + "0:" +
|
||||||
"e" +
|
"1:p" + "0:" +
|
||||||
"e").encodeToByteArray()
|
"1:q" + "0:" +
|
||||||
|
"e" +
|
||||||
|
"e").encodeToByteArray()
|
||||||
|
|
||||||
|
val expectedPush1Encrypted = Hex.fromStringCondensed(
|
||||||
|
"a2952190dcb9797bc48e48f6dc7b3254d004bde9091cfc9ec3433cbc5939a3726deb04f58a546d7d79e6f8" +
|
||||||
|
"0ea185d43bf93278398556304998ae882304075c77f15c67f9914c4d10005a661f29ff7a79e0a9de7f2172" +
|
||||||
|
"5ba3b5a6c19eaa3797671b8fa4008d62e9af2744629cbb46664c4d8048e2867f66ed9254120371bdb24e95" +
|
||||||
|
"b2d92341fa3b1f695046113a768ceb7522269f937ead5591bfa8a5eeee3010474002f2db9de043f0f0d1cf" +
|
||||||
|
"b1066a03e7b5d6cfb70a8f84a20cd2df5a510cd3d175708015a52dd4a105886d916db0005dbea5706e5a5d" +
|
||||||
|
"c37ffd0a0ca2824b524da2e2ad181a48bb38e21ed9abe136014a4ee1e472cb2f53102db2a46afa9d68"
|
||||||
|
)
|
||||||
|
|
||||||
assertEquals(1, newSeqNo)
|
assertEquals(1, newSeqNo)
|
||||||
assertArrayEquals(expectedPush1, newToPush)
|
assertArrayEquals(expectedPush1Encrypted, newToPush)
|
||||||
// We haven't dumped, so still need to dump:
|
// We haven't dumped, so still need to dump:
|
||||||
assertTrue(userProfile.needsDump())
|
assertTrue(userProfile.needsDump())
|
||||||
// We did call push but we haven't confirmed it as stored yet, so this will still return true:
|
// We did call push but we haven't confirmed it as stored yet, so this will still return true:
|
||||||
@ -106,8 +117,8 @@ class InstrumentedTests {
|
|||||||
assertFalse(userProfile.needsDump())
|
assertFalse(userProfile.needsDump())
|
||||||
val expectedDump = ("d" +
|
val expectedDump = ("d" +
|
||||||
"1:!i2e" +
|
"1:!i2e" +
|
||||||
"1:$").encodeToByteArray() + expectedPush1.size.toString().encodeToByteArray() +
|
"1:$").encodeToByteArray() + expectedPush1Decrypted.size.toString().encodeToByteArray() +
|
||||||
":".encodeToByteArray() + expectedPush1 +
|
":".encodeToByteArray() + expectedPush1Decrypted +
|
||||||
"e".encodeToByteArray()
|
"e".encodeToByteArray()
|
||||||
|
|
||||||
assertArrayEquals(expectedDump, dump)
|
assertArrayEquals(expectedDump, dump)
|
||||||
|
@ -129,7 +129,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getPic(JNIEnv *env, job
|
|||||||
auto pic = profile->get_profile_pic();
|
auto pic = profile->get_profile_pic();
|
||||||
if (pic == std::nullopt) return nullptr;
|
if (pic == std::nullopt) return nullptr;
|
||||||
// return nullptr if either parameter is null as per profile class
|
// return nullptr if either parameter is null as per profile class
|
||||||
jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/UserPic");
|
jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic");
|
||||||
jmethodID constructor = env->GetMethodID(returnObjectClass, "<init>", "(Ljava/lang/String;[B)V");
|
jmethodID constructor = env->GetMethodID(returnObjectClass, "<init>", "(Ljava/lang/String;[B)V");
|
||||||
jstring url = env->NewStringUTF(pic->url.data());
|
jstring url = env->NewStringUTF(pic->url.data());
|
||||||
jbyteArray byteArray = bytes_from_ustring(env, pic->key);
|
jbyteArray byteArray = bytes_from_ustring(env, pic->key);
|
||||||
@ -141,7 +141,7 @@ JNIEXPORT void JNICALL
|
|||||||
Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, jobject thiz,
|
Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, jobject thiz,
|
||||||
jobject user_pic) {
|
jobject user_pic) {
|
||||||
auto profile = ptrToProfile(env, thiz);
|
auto profile = ptrToProfile(env, thiz);
|
||||||
jclass userPicClass = env->FindClass("network/loki/messenger/libsession_util/UserPic");
|
jclass userPicClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic");
|
||||||
jfieldID picField = env->GetFieldID(userPicClass, "url", "Ljava/lang/String;");
|
jfieldID picField = env->GetFieldID(userPicClass, "url", "Ljava/lang/String;");
|
||||||
jfieldID keyField = env->GetFieldID(userPicClass, "key", "[B");
|
jfieldID keyField = env->GetFieldID(userPicClass, "key", "[B");
|
||||||
auto pic = (jstring)env->GetObjectField(user_pic, picField);
|
auto pic = (jstring)env->GetObjectField(user_pic, picField);
|
||||||
@ -167,14 +167,28 @@ Java_network_loki_messenger_libsession_1util_util_Sodium_ed25519KeyPair(JNIEnv *
|
|||||||
std::array<unsigned char, 32> ed_pk;
|
std::array<unsigned char, 32> ed_pk;
|
||||||
std::array<unsigned char, 64> ed_sk;
|
std::array<unsigned char, 64> ed_sk;
|
||||||
auto seed_bytes = ustring_from_bytes(env, seed);
|
auto seed_bytes = ustring_from_bytes(env, seed);
|
||||||
crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.c_str());
|
crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.data());
|
||||||
|
|
||||||
jclass kp_class = env->FindClass("network/loki/messenger/libsession_util/util/KeyPair");
|
jclass kp_class = env->FindClass("network/loki/messenger/libsession_util/util/KeyPair");
|
||||||
jmethodID kp_constructor = env->GetMethodID(kp_class, "<init>", "([B[B)V");
|
jmethodID kp_constructor = env->GetMethodID(kp_class, "<init>", "([B[B)V");
|
||||||
|
|
||||||
jbyteArray pk_jarray = bytes_from_ustring(env, ed_pk.data());
|
jbyteArray pk_jarray = bytes_from_ustring(env, session::ustring_view {ed_pk.data(), ed_pk.size()});
|
||||||
jbyteArray sk_jarray = bytes_from_ustring(env, ed_sk.data());
|
jbyteArray sk_jarray = bytes_from_ustring(env, session::ustring_view {ed_sk.data(), ed_sk.size()});
|
||||||
|
|
||||||
jobject return_obj = env->NewObject(kp_class, kp_constructor, pk_jarray, sk_jarray);
|
jobject return_obj = env->NewObject(kp_class, kp_constructor, pk_jarray, sk_jarray);
|
||||||
return return_obj;
|
return return_obj;
|
||||||
}
|
}
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jstring JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_ConfigBase_encryptionDomain(JNIEnv *env,
|
||||||
|
jobject thiz) {
|
||||||
|
auto conf = ptrToConfigBase(env, thiz);
|
||||||
|
return env->NewStringUTF(conf->encryption_domain());
|
||||||
|
}
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jbyteArray JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_ConfigBase_decrypt(JNIEnv *env, jobject thiz,
|
||||||
|
jbyteArray encrypted) {
|
||||||
|
auto profile = ptrToProfile(env, thiz);
|
||||||
|
auto encrypted_bytes = ustring_from_bytes(env, encrypted);
|
||||||
|
}
|
@ -15,6 +15,8 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
|||||||
external fun needsDump(): Boolean
|
external fun needsDump(): Boolean
|
||||||
external fun push(): ConfigWithSeqNo
|
external fun push(): ConfigWithSeqNo
|
||||||
external fun dump(): ByteArray
|
external fun dump(): ByteArray
|
||||||
|
external fun encryptionDomain(): String
|
||||||
|
external fun decrypt(encrypted: ByteArray): ByteArray
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserProfile(pointer: Long): ConfigBase(pointer) {
|
class UserProfile(pointer: Long): ConfigBase(pointer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user