From: sangwan.kwon Date: Mon, 8 May 2017 04:34:10 +0000 (+0900) Subject: Detach SSL testcases from internal testcases X-Git-Tag: submit/tizen/20170623.014003~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1afe799e694a4655e1d2f638a6714aa7efb3f6c7;p=platform%2Fcore%2Fsecurity%2Ftrust-anchor.git Detach SSL testcases from internal testcases Change-Id: I5193a8933592a0d8d1bcbf97ee6038ed91bfe943 Signed-off-by: sangwan.kwon --- diff --git a/packaging/trust-anchor.spec b/packaging/trust-anchor.spec index 7a4d9ee..3bd67f7 100644 --- a/packaging/trust-anchor.spec +++ b/packaging/trust-anchor.spec @@ -114,6 +114,7 @@ Testcases for trust anchor library %{_bindir}/%{lib_name}-test-launcher %{_bindir}/%{lib_name}-test-clauncher %{_bindir}/%{lib_name}-test-internal +%{_bindir}/%{lib_name}-test-ssl %{_bindir}/%{lib_name}-test-init.sh %{tanchor_test} %{tanchor_test}/certs diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 869a38d..289ef72 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -55,21 +55,24 @@ SET(CAPI_LAUNCHER_SRCS main.cpp test-util.cpp test-capi-launcher.cpp) SET(INTERNAL_SRCS main.cpp - test-curl.cpp test-util.cpp test-certificate.cpp - ${TANCHOR_SRC}/certificate.cpp) +SET(SSL_SRCS main.cpp + test-curl.cpp + test-util.cpp) SET(TEST_INSTALLER ${TARGET_TANCHOR_TEST}-installer) SET(TEST_LAUNCHER ${TARGET_TANCHOR_TEST}-launcher) SET(TEST_CLAUNCHER ${TARGET_TANCHOR_TEST}-clauncher) SET(TEST_INTERNAL ${TARGET_TANCHOR_TEST}-internal) +SET(TEST_SSL ${TARGET_TANCHOR_TEST}-ssl) BUILD_TEST(${TEST_INSTALLER} "${INSTALLER_SRCS}") BUILD_TEST(${TEST_LAUNCHER} "${LAUNCHER_SRCS}") BUILD_TEST(${TEST_CLAUNCHER} "${CAPI_LAUNCHER_SRCS}") BUILD_TEST(${TEST_INTERNAL} "${INTERNAL_SRCS}") +BUILD_TEST(${TEST_SSL} "${SSL_SRCS}") ADD_SUBDIRECTORY(res) ADD_SUBDIRECTORY(script) diff --git a/tests/test-curl.cpp b/tests/test-curl.cpp index 580695f..ecc325e 100644 --- a/tests/test-curl.cpp +++ b/tests/test-curl.cpp @@ -20,10 +20,13 @@ * @brief Unit test program of Curl */ +#include + #include +#include + #include -#include #include "test-util.hxx" #include "test-resource.hxx" @@ -36,3 +39,77 @@ TESTCASE(CONNECT_SSL) if (ret != 0) std::cout << "Check wifi connection.." << std::endl; } + +TESTCASE(TRUST_ANCHOR_LAUNCH) +{ + tanchor::TrustAnchor ta(DUMMY_PKG_ID, APP_CERTS_DIR); + int ret = ta.install(false); + TEST_EXPECT(true, ret == 0); + + std::cout << "##########################################" << std::endl; + std::cout << "## Before trust-anchor launch#############" << std::endl; + std::cout << "##########################################" << std::endl; + ret = test::util::connectSSL("https://google.com"); + TEST_EXPECT(true, ret == 0); + + // pre-condition + int pid = fork(); + TEST_EXPECT(true, pid >= 0); + + if (pid == 0) { + ret = ta.launch(false); + TEST_EXPECT(true, ret == 0); + + // check SSL communication + std::cout << "##########################################" << std::endl; + std::cout << "## After trust-anchor launch(APP)#########" << std::endl; + std::cout << "##########################################" << std::endl; + ret = test::util::connectSSL("https://google.com"); + TEST_EXPECT(false, ret == 0); + + exit(0); + } else { + std::cout << "##########################################" << std::endl; + std::cout << "## After trust-anchor launch(parent)######" << std::endl; + std::cout << "##########################################" << std::endl; + ret = test::util::connectSSL("https://google.com"); + TEST_EXPECT(true, ret == 0); + } +} + +TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS) +{ + tanchor::TrustAnchor ta(DUMMY_PKG_ID, APP_CERTS_DIR); + int ret = ta.install(true); + TEST_EXPECT(true, ret == 0); + + std::cout << "##########################################" << std::endl; + std::cout << "## Before trust-anchor launch#############" << std::endl; + std::cout << "##########################################" << std::endl; + ret = test::util::connectSSL("https://google.com"); + TEST_EXPECT(true, ret == 0); + + // pre-condition + int pid = fork(); + TEST_EXPECT(true, pid >= 0); + + if (pid == 0) { + ret = ta.launch(true); + TEST_EXPECT(true, ret == 0); + + // check SSL communication + std::cout << "###########################################" << std::endl; + std::cout << "## After trust-anchor launch(APP) with SYS#" << std::endl; + std::cout << "###########################################" << std::endl; + ret = test::util::connectSSL("https://google.com"); + TEST_EXPECT(true, ret == 0); + + exit(0); + } else { + std::cout << "##########################################" << std::endl; + std::cout << "## After trust-anchor launch(parent)######" << std::endl; + std::cout << "##########################################" << std::endl; + ret = test::util::connectSSL("https://google.com"); + TEST_EXPECT(true, ret == 0); + } +} diff --git a/tests/test-launcher.cpp b/tests/test-launcher.cpp index ec8f4bc..1e44923 100644 --- a/tests/test-launcher.cpp +++ b/tests/test-launcher.cpp @@ -39,11 +39,6 @@ TESTCASE(TRUST_ANCHOR_LAUNCH) tanchor::TrustAnchor ta(DUMMY_PKG_ID, APP_CERTS_DIR); int ret = ta.install(false); - - std::cout << "##########################################" << std::endl; - std::cout << "## Before trust-anchor launch#############" << std::endl; - std::cout << "##########################################" << std::endl; - ret = test::util::connectSSL("https://google.com"); TEST_EXPECT(true, ret == 0); // pre-condition @@ -63,13 +58,6 @@ TESTCASE(TRUST_ANCHOR_LAUNCH) auto afterCatChild = test::util::cat(TZ_SYS_RO_CA_BUNDLE); TEST_EXPECT(true, beforeCat != afterCatChild); - // check SSL communication - std::cout << "##########################################" << std::endl; - std::cout << "## After trust-anchor launch(APP)#########" << std::endl; - std::cout << "##########################################" << std::endl; - ret = test::util::connectSSL("https://google.com"); - TEST_EXPECT(false, ret == 0); - exit(0); } else { auto afterLsParent = test::util::ls(TZ_SYS_RO_CA_CERTS); @@ -77,12 +65,6 @@ TESTCASE(TRUST_ANCHOR_LAUNCH) auto afterCatParent = test::util::cat(TZ_SYS_RO_CA_BUNDLE); TEST_EXPECT(true, beforeCat == afterCatParent); - - std::cout << "##########################################" << std::endl; - std::cout << "## After trust-anchor launch(parent)######" << std::endl; - std::cout << "##########################################" << std::endl; - ret = test::util::connectSSL("https://google.com"); - TEST_EXPECT(true, ret == 0); } } @@ -93,11 +75,6 @@ TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS) tanchor::TrustAnchor ta(DUMMY_PKG_ID, APP_CERTS_DIR); int ret = ta.install(true); - - std::cout << "##########################################" << std::endl; - std::cout << "## Before trust-anchor launch#############" << std::endl; - std::cout << "##########################################" << std::endl; - ret = test::util::connectSSL("https://google.com"); TEST_EXPECT(true, ret == 0); // pre-condition @@ -117,13 +94,6 @@ TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS) auto afterCatChild = test::util::cat(TZ_SYS_RO_CA_BUNDLE); TEST_EXPECT(true, beforeCat != afterCatChild); - // check SSL communication - std::cout << "###########################################" << std::endl; - std::cout << "## After trust-anchor launch(APP) with SYS#" << std::endl; - std::cout << "###########################################" << std::endl; - ret = test::util::connectSSL("https://google.com"); - TEST_EXPECT(true, ret == 0); - exit(0); } else { auto afterLsParent = test::util::ls(TZ_SYS_RO_CA_CERTS); @@ -131,11 +101,5 @@ TESTCASE(TRUST_ANCHOR_LAUNCH_WITH_SYS) auto afterCatParent = test::util::cat(TZ_SYS_RO_CA_BUNDLE); TEST_EXPECT(true, beforeCat == afterCatParent); - - std::cout << "##########################################" << std::endl; - std::cout << "## After trust-anchor launch(parent)######" << std::endl; - std::cout << "##########################################" << std::endl; - ret = test::util::connectSSL("https://google.com"); - TEST_EXPECT(true, ret == 0); } } diff --git a/tests/test-util.cpp b/tests/test-util.cpp index e7710dc..7a17f43 100644 --- a/tests/test-util.cpp +++ b/tests/test-util.cpp @@ -83,7 +83,7 @@ int connectSSL(const std::string &addr) curl_easy_setopt(curl.get(), CURLOPT_URL, addr.c_str()); CURLcode res = curl_easy_perform(curl.get()); - if(res != CURLE_OK) { + if (res != CURLE_OK) { std::cout << "Failed to connect failed: " << curl_easy_strerror(res) << std::endl; return -1;