diff options
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r-- | auto_tests/encryptsave_test.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index a239bcee..d187e352 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -55,8 +55,8 @@ END_TEST | |||
55 | 55 | ||
56 | START_TEST(test_save_friend) | 56 | START_TEST(test_save_friend) |
57 | { | 57 | { |
58 | Tox *tox1 = tox_new(0, 0, 0, 0); | 58 | Tox *tox1 = tox_new(0, 0); |
59 | Tox *tox2 = tox_new(0, 0, 0, 0); | 59 | Tox *tox2 = tox_new(0, 0); |
60 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); | 60 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); |
61 | uint32_t to_compare = 974536; | 61 | uint32_t to_compare = 974536; |
62 | tox_callback_friend_request(tox2, accept_friend_request, &to_compare); | 62 | tox_callback_friend_request(tox2, accept_friend_request, &to_compare); |
@@ -75,15 +75,23 @@ START_TEST(test_save_friend) | |||
75 | ck_assert_msg(ret, "failed to encrypted save: %u", error1); | 75 | ck_assert_msg(ret, "failed to encrypted save: %u", error1); |
76 | ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); | 76 | ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); |
77 | 77 | ||
78 | struct Tox_Options options; | ||
79 | tox_options_default(&options); | ||
80 | options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; | ||
81 | options.savedata_data = enc_data; | ||
82 | options.savedata_length = size2; | ||
83 | |||
78 | TOX_ERR_NEW err2; | 84 | TOX_ERR_NEW err2; |
79 | Tox *tox3 = tox_new(0, enc_data, size2, &err2); | 85 | Tox *tox3 = tox_new(&options, &err2); |
80 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, | 86 | ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2, |
81 | TOX_ERR_NEW_LOAD_ENCRYPTED); | 87 | TOX_ERR_NEW_LOAD_ENCRYPTED); |
82 | uint8_t dec_data[size]; | 88 | uint8_t dec_data[size]; |
83 | TOX_ERR_DECRYPTION err3; | 89 | TOX_ERR_DECRYPTION err3; |
84 | ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); | 90 | ret = tox_pass_decrypt(enc_data, size2, "correcthorsebatterystaple", 25, dec_data, &err3); |
85 | ck_assert_msg(ret, "failed to decrypt save: %u", err3); | 91 | ck_assert_msg(ret, "failed to decrypt save: %u", err3); |
86 | tox3 = tox_new(0, dec_data, size, &err2); | 92 | options.savedata_data = dec_data; |
93 | options.savedata_length = size; | ||
94 | tox3 = tox_new(&options, &err2); | ||
87 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); | 95 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2); |
88 | uint8_t address2[TOX_PUBLIC_KEY_SIZE]; | 96 | uint8_t address2[TOX_PUBLIC_KEY_SIZE]; |
89 | ret = tox_friend_get_public_key(tox3, 0, address2, 0); | 97 | ret = tox_friend_get_public_key(tox3, 0, address2, 0); |
@@ -111,7 +119,9 @@ START_TEST(test_save_friend) | |||
111 | 119 | ||
112 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste | 120 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste |
113 | // to remove the manual check now that it's there) | 121 | // to remove the manual check now that it's there) |
114 | Tox *tox4 = tox_new(0, out1, size, &err2); | 122 | options.savedata_data = out1; |
123 | options.savedata_length = size; | ||
124 | Tox *tox4 = tox_new(&options, &err2); | ||
115 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); | 125 | ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third"); |
116 | uint8_t address5[TOX_PUBLIC_KEY_SIZE]; | 126 | uint8_t address5[TOX_PUBLIC_KEY_SIZE]; |
117 | ret = tox_friend_get_public_key(tox4, 0, address5, 0); | 127 | ret = tox_friend_get_public_key(tox4, 0, address5, 0); |
@@ -154,6 +164,10 @@ START_TEST(test_keys) | |||
154 | ck_assert_msg(ret, "generic failure 5: %u", decerr); | 164 | ck_assert_msg(ret, "generic failure 5: %u", decerr); |
155 | ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); | 165 | ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); |
156 | 166 | ||
167 | ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, NULL, 0, out2, &decerr); | ||
168 | ck_assert_msg(!ret, "Decrypt succeeded with wrong pass"); | ||
169 | ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %u", decerr); | ||
170 | |||
157 | // test that pass_decrypt can decrypt things from pass_key_encrypt | 171 | // test that pass_decrypt can decrypt things from pass_key_encrypt |
158 | ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, "123qweasdzxc", 12, out1, &decerr); | 172 | ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, "123qweasdzxc", 12, out1, &decerr); |
159 | ck_assert_msg(ret, "generic failure 6: %u", decerr); | 173 | ck_assert_msg(ret, "generic failure 6: %u", decerr); |