summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2016-07-27 16:54:50 +0900
committerkyungwook tak <k.tak@samsung.com>2016-08-02 21:45:45 -0700
commitcc76acebe224f4b8a273752b2400190ab0aab679 (patch)
tree9f131a30f794d8a11174a3ef06c18c91976a8bd6 /tests
parenta025df2ca4ae9a4e13b5b803674da4dd1bd133e9 (diff)
downloadlibwebappenc-cc76acebe224f4b8a273752b2400190ab0aab679.tar.gz
libwebappenc-cc76acebe224f4b8a273752b2400190ab0aab679.tar.bz2
libwebappenc-cc76acebe224f4b8a273752b2400190ab0aab679.zip
[API changed] Add uid parametersubmit/tizen/20160811.013634
Installer will be run as system (from user) so we cannot retrieve user id from client credential(by key-manager). Change-Id: I1e091bfc0b88fce418cd209a7a1adab021b6c0d2 Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/internals.cpp12
-rw-r--r--tests/non-normals.cpp3
-rw-r--r--tests/normals.cpp3
-rw-r--r--tests/test-helper.cpp77
-rw-r--r--tests/test-helper.h2
5 files changed, 68 insertions, 29 deletions
diff --git a/tests/internals.cpp b/tests/internals.cpp
index b5c106d..1fa9aff 100644
--- a/tests/internals.cpp
+++ b/tests/internals.cpp
@@ -310,8 +310,8 @@ BOOST_AUTO_TEST_CASE(get_create_preloaded_app_dek_2)
_get_preloaded_app_dek_file_path(pkg_id2, sizeof(path2), path2);
// remove old test data
- remove_app_ce(pkg_id1, WAE_PRELOADED_APP);
- remove_app_ce(pkg_id2, WAE_PRELOADED_APP);
+ remove_app_ce(0, pkg_id1, WAE_PRELOADED_APP);
+ remove_app_ce(0, pkg_id2, WAE_PRELOADED_APP);
unlink(path1);
unlink(path2);
@@ -331,20 +331,20 @@ BOOST_AUTO_TEST_CASE(get_create_preloaded_app_dek_2)
"Failed to load_preloaded_app_deks. ec: " << ret);
const crypto_element_s *readed1 = nullptr;
- ret = get_app_ce(pkg_id1, WAE_PRELOADED_APP, false, &readed1);
+ ret = get_app_ce(0, pkg_id1, WAE_PRELOADED_APP, false, &readed1);
BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to get_app_dek. ec: " << ret);
const crypto_element_s *readed2 = nullptr;
- ret = get_app_ce(pkg_id2, WAE_PRELOADED_APP, false, &readed2);
+ ret = get_app_ce(0, pkg_id2, WAE_PRELOADED_APP, false, &readed2);
BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to get_app_dek. ec: " << ret);
BOOST_REQUIRE_MESSAGE(readed1 == ce1, "cached ce and actual address is different!");
BOOST_REQUIRE_MESSAGE(readed2 == ce2, "cached ce and actual address is different!");
- ret = remove_app_ce(pkg_id1, WAE_PRELOADED_APP);
+ ret = remove_app_ce(0, pkg_id1, WAE_PRELOADED_APP);
BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed remove app ce. ec: " << ret);
- ret = remove_app_ce(pkg_id2, WAE_PRELOADED_APP);
+ ret = remove_app_ce(0, pkg_id2, WAE_PRELOADED_APP);
BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed remove app ce. ec: " << ret);
}
diff --git a/tests/non-normals.cpp b/tests/non-normals.cpp
index 81c0173..78c2197 100644
--- a/tests/non-normals.cpp
+++ b/tests/non-normals.cpp
@@ -20,10 +20,9 @@
* @version 2.0
* @brief API test for preloaded/global apps
*/
-#include "web_app_enc.h"
-
#include <boost/test/unit_test.hpp>
+#include "types.h"
#include "test-helper.h"
BOOST_AUTO_TEST_SUITE(SYSTEM)
diff --git a/tests/normals.cpp b/tests/normals.cpp
index 5d67910..fad04f1 100644
--- a/tests/normals.cpp
+++ b/tests/normals.cpp
@@ -20,10 +20,9 @@
* @version 2.0
* @brief test for normal downloaded app
*/
-#include "web_app_enc.h"
-
#include <boost/test/unit_test.hpp>
+#include "types.h"
#include "test-helper.h"
BOOST_AUTO_TEST_SUITE(USER)
diff --git a/tests/test-helper.cpp b/tests/test-helper.cpp
index f303b75..d0ca263 100644
--- a/tests/test-helper.cpp
+++ b/tests/test-helper.cpp
@@ -23,6 +23,7 @@
#include <cstring>
#include <vector>
+#include "web_app_enc.h"
#include "key_handler.h"
#include "crypto_service.h"
#include "types.h"
@@ -32,32 +33,39 @@
namespace Wae {
namespace Test {
+namespace {
+
+const uid_t UID_OWNER = 5001;
+
+} // namespace anonymous
void add_get_remove_ce(wae_app_type_e app_type)
{
const char *pkg_id = "TEST_PKG_ID";
const crypto_element_s *ce = nullptr;
- int tmp = create_app_ce(pkg_id, app_type, &ce);
+ uid_t uid = app_type == WAE_DOWNLOADED_NORMAL_APP ? UID_OWNER : 0;
+
+ int tmp = create_app_ce(uid, pkg_id, app_type, &ce);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to create_app_ce. ec: " << tmp);
const crypto_element_s *stored_ce = nullptr;
- tmp = get_app_ce(pkg_id, app_type, true, &stored_ce);
+ tmp = get_app_ce(uid, pkg_id, app_type, true, &stored_ce);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to get_app_ce. ec: " << tmp);
BOOST_REQUIRE_MESSAGE(ce == stored_ce,
"ce(" << ce << ") and cached ce(" << stored_ce << ") pointer addr is different!");
- tmp = remove_app_ce(pkg_id, app_type);
+ tmp = remove_app_ce(uid, pkg_id, app_type);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to remove_app_ce. ec: " << tmp);
if (app_type == WAE_DOWNLOADED_GLOBAL_APP) {
- tmp = get_app_ce(pkg_id, app_type, true, &stored_ce);
+ tmp = get_app_ce(uid, pkg_id, app_type, true, &stored_ce);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE && stored_ce->is_migrated_app,
"when getting app ce which is there isn't, it should be migrated case! "
"ret("<< tmp << ") and is_migrated_app(" << stored_ce->is_migrated_app << ")");
} else {
- tmp = get_app_ce(pkg_id, app_type, false, &stored_ce);
+ tmp = get_app_ce(uid, pkg_id, app_type, false, &stored_ce);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NO_KEY,
"removed app ce is still remaining. ret(" << tmp << ")");
}
@@ -65,28 +73,30 @@ void add_get_remove_ce(wae_app_type_e app_type)
void create_app_ce(wae_app_type_e app_type)
{
+ uid_t uid = app_type == WAE_DOWNLOADED_NORMAL_APP ? UID_OWNER : 0;
const char *pkg_id = "TEST_PKG_ID";
- remove_app_ce(pkg_id, app_type);
+ remove_app_ce(uid, pkg_id, app_type);
const crypto_element_s *ce = nullptr;
- int tmp = create_app_ce(pkg_id, app_type, &ce);
+ int tmp = create_app_ce(uid, pkg_id, app_type, &ce);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to create_app_ce. ec: " << tmp);
const crypto_element_s *stored_ce = nullptr;
- tmp = get_app_ce(pkg_id, app_type, false, &stored_ce);
+ tmp = get_app_ce(uid, pkg_id, app_type, false, &stored_ce);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to get_app_ce. ec: " << tmp);
BOOST_REQUIRE_MESSAGE(ce == stored_ce,
"ce(" << ce << ") and cached ce(" << stored_ce << ") pointer addr is different!");
- tmp = remove_app_ce(pkg_id, app_type);
+ tmp = remove_app_ce(uid, pkg_id, app_type);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to remove_app_ce. ec: " << tmp);
}
void encrypt_decrypt_web_app(wae_app_type_e app_type)
{
+ uid_t uid = app_type == WAE_DOWNLOADED_NORMAL_APP ? UID_OWNER : 0;
const char *pkg_id1 = "testpkg_for_normal";
const char *pkg_id2 = "testpkg_for_global";
const char *pkg_id3 = "testpkg_for_preloaded";
@@ -108,7 +118,10 @@ void encrypt_decrypt_web_app(wae_app_type_e app_type)
}
// remove old test data
- wae_remove_app_dek(pkg_id, app_type);
+ if (app_type == WAE_DOWNLOADED_NORMAL_APP)
+ wae_remove_app_dek(uid, pkg_id);
+ else
+ wae_remove_global_app_dek(pkg_id, app_type == WAE_PRELOADED_APP);
if (app_type == WAE_PRELOADED_APP)
clear_app_deks_loaded_from_key_manager();
@@ -121,30 +134,55 @@ void encrypt_decrypt_web_app(wae_app_type_e app_type)
// test for downloaded web application
unsigned char *_encrypted = nullptr;
size_t _enc_len = 0;
- int tmp = wae_encrypt_web_application(pkg_id, app_type, plaintext.data(),
- plaintext.size(), &_encrypted, &_enc_len);
+ int tmp = 0;
+ if (app_type == WAE_DOWNLOADED_NORMAL_APP)
+ tmp = wae_encrypt_web_application(uid, pkg_id, plaintext.data(), plaintext.size(),
+ &_encrypted, &_enc_len);
+ else
+ tmp = wae_encrypt_global_web_application(pkg_id, app_type == WAE_PRELOADED_APP,
+ plaintext.data(), plaintext.size(),
+ &_encrypted, &_enc_len);
+
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
"Failed to wae_encrypt_web_application. ec: " << tmp);
free(_encrypted);
// encrypt test twice
- tmp = wae_encrypt_web_application(pkg_id, app_type, plaintext.data(),
- plaintext.size(), &_encrypted, &_enc_len);
+ if (app_type == WAE_DOWNLOADED_NORMAL_APP)
+ tmp = wae_encrypt_web_application(uid, pkg_id, plaintext.data(),
+ plaintext.size(), &_encrypted, &_enc_len);
+ else
+ tmp = wae_encrypt_global_web_application(pkg_id, app_type == WAE_PRELOADED_APP,
+ plaintext.data(), plaintext.size(),
+ &_encrypted, &_enc_len);
+
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
"Failed to wae_encrypt_web_application second time. ec: " << tmp);
auto encrypted = bytearr_to_vec(_encrypted, _enc_len);
free(_encrypted);
- _remove_app_ce_from_cache(pkg_id);
+ if (app_type == WAE_DOWNLOADED_NORMAL_APP) {
+ char *key_per_user = _create_map_key(uid, pkg_id);
+ _remove_app_ce_from_cache(key_per_user);
+ free(key_per_user);
+ } else {
+ _remove_app_ce_from_cache(pkg_id);
+ }
if (app_type == WAE_PRELOADED_APP)
load_preloaded_app_deks(true);
unsigned char *_decrypted = nullptr;
size_t _dec_len = 0;
- tmp = wae_decrypt_web_application(pkg_id, app_type, encrypted.data(),
- encrypted.size(), &_decrypted, &_dec_len);
+ if (app_type == WAE_DOWNLOADED_NORMAL_APP)
+ tmp = wae_decrypt_web_application(uid, pkg_id, encrypted.data(), encrypted.size(),
+ &_decrypted, &_dec_len);
+ else
+ tmp = wae_decrypt_global_web_application(pkg_id, app_type == WAE_PRELOADED_APP,
+ encrypted.data(), encrypted.size(),
+ &_decrypted, &_dec_len);
+
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
"Failed to wae_decrypt_web_application. ec: " << tmp);
@@ -155,7 +193,10 @@ void encrypt_decrypt_web_app(wae_app_type_e app_type)
"plaintext(" << bytes_to_hex(plaintext) << ") "
"decrypted(" << bytes_to_hex(decrypted) << ")");
- tmp = wae_remove_app_dek(pkg_id, app_type);
+ if (app_type == WAE_DOWNLOADED_NORMAL_APP)
+ tmp = wae_remove_app_dek(uid, pkg_id);
+ else
+ tmp = wae_remove_global_app_dek(pkg_id, app_type == WAE_PRELOADED_APP);
BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
"Failed to wae_remove_app_dek. ec: " << tmp);
}
diff --git a/tests/test-helper.h b/tests/test-helper.h
index c0c77f6..b4d1f42 100644
--- a/tests/test-helper.h
+++ b/tests/test-helper.h
@@ -20,7 +20,7 @@
*/
#pragma once
-#include "web_app_enc.h"
+#include "types.h"
namespace Wae {
namespace Test {