Detach SSL testcases from internal testcases 09/128209/2
authorsangwan.kwon <sangwan.kwon@samsung.com>
Mon, 8 May 2017 04:34:10 +0000 (13:34 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Mon, 8 May 2017 04:41:26 +0000 (13:41 +0900)
Change-Id: I5193a8933592a0d8d1bcbf97ee6038ed91bfe943
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
packaging/trust-anchor.spec
tests/CMakeLists.txt
tests/test-curl.cpp
tests/test-launcher.cpp
tests/test-util.cpp

index 7a4d9ee..3bd67f7 100644 (file)
@@ -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
index 869a38d..289ef72 100644 (file)
@@ -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)
index 580695f..ecc325e 100644 (file)
  * @brief       Unit test program of Curl
  */
 
+#include <tanchor/trust-anchor.hxx>
+
 #include <klay/testbench.h>
 
+#include <unistd.h>
+
 #include <iostream>
-#include <stdexcept>
 
 #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);
+       }
+}
index ec8f4bc..1e44923 100644 (file)
@@ -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);
        }
 }
index e7710dc..7a17f43 100644 (file)
@@ -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;