summaryrefslogtreecommitdiff
path: root/src/tests/eet/eet_suite.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-20 21:30:25 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2012-12-20 21:30:25 +0000
commit6f816da47f2fa17a28c00cf175dd837e5a13727a (patch)
tree4f31b233d1b04d98a6fe4131c94a422464ccdd81 /src/tests/eet/eet_suite.c
parent55845c5a3ed0d867e204f5a311e5c7c3f370963b (diff)
efl/eet_suite: fix handling of certificate.
- do not chdir() during test, that's bad! - try exhaustively to find the pem. SVN revision: 81486
Diffstat (limited to 'src/tests/eet/eet_suite.c')
-rw-r--r--src/tests/eet/eet_suite.c72
1 files changed, 56 insertions, 16 deletions
diff --git a/src/tests/eet/eet_suite.c b/src/tests/eet/eet_suite.c
index dd2fbc5676..44ca9e7c72 100644
--- a/src/tests/eet/eet_suite.c
+++ b/src/tests/eet/eet_suite.c
@@ -24,7 +24,11 @@
24 24
25#include "eet_suite.h" 25#include "eet_suite.h"
26 26
27#define CERT_DIR ((*TESTS_SRC_DIR == '/') ? TESTS_SRC_DIR"/src/tests/eet/" : "src/tests/eet/") 27static char _key_pem[PATH_MAX] = "";
28static char _cert_pem[PATH_MAX] = "";
29static char _key_enc[PATH_MAX] = "";
30static char _key_enc_pem[PATH_MAX] = "";
31static char _key_enc_none_pem[PATH_MAX] = "";
28 32
29START_TEST(eet_test_init) 33START_TEST(eet_test_init)
30{ 34{
@@ -1642,7 +1646,6 @@ START_TEST(eet_identity_simple)
1642 eet_init(); 1646 eet_init();
1643 1647
1644 fail_if(!(file = tmpnam(file))); 1648 fail_if(!(file = tmpnam(file)));
1645 fail_if(chdir(CERT_DIR));
1646 fail_if(!(noread = fopen("/dev/null", "w"))); 1649 fail_if(!(noread = fopen("/dev/null", "w")));
1647 1650
1648 /* Sign an eet file. */ 1651 /* Sign an eet file. */
@@ -1651,7 +1654,7 @@ START_TEST(eet_identity_simple)
1651 1654
1652 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0)); 1655 fail_if(!eet_write(ef, "keys/tests", buffer, strlen(buffer) + 1, 0));
1653 1656
1654 k = eet_identity_open("cert.pem", "key.pem", NULL); 1657 k = eet_identity_open(_cert_pem, _key_pem, NULL);
1655 fail_if(!k); 1658 fail_if(!k);
1656 1659
1657 fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE); 1660 fail_if(eet_identity_set(ef, k) != EET_ERROR_NONE);
@@ -1709,9 +1712,7 @@ START_TEST(eet_identity_open_simple)
1709 1712
1710 eet_init(); 1713 eet_init();
1711 1714
1712 fail_if(chdir(CERT_DIR)); 1715 k = eet_identity_open(_cert_pem, _key_pem, NULL);
1713
1714 k = eet_identity_open("cert.pem", "key.pem", NULL);
1715 fail_if(!k); 1716 fail_if(!k);
1716 1717
1717 if (k) 1718 if (k)
@@ -1727,9 +1728,7 @@ START_TEST(eet_identity_open_pkcs8)
1727 1728
1728 eet_init(); 1729 eet_init();
1729 1730
1730 fail_if(chdir(CERT_DIR)); 1731 k = eet_identity_open(_cert_pem, _key_enc_none_pem, NULL);
1731
1732 k = eet_identity_open("cert.pem", "key_enc_none.pem", NULL);
1733 fail_if(!k); 1732 fail_if(!k);
1734 1733
1735 if (k) 1734 if (k)
@@ -1776,21 +1775,19 @@ START_TEST(eet_identity_open_pkcs8_enc)
1776 1775
1777 eet_init(); 1776 eet_init();
1778 1777
1779 fail_if(chdir(CERT_DIR)); 1778 k = eet_identity_open(_cert_pem, _key_enc_pem, NULL);
1780
1781 k = eet_identity_open("cert.pem", "key_enc.pem", NULL);
1782 fail_if(k); 1779 fail_if(k);
1783 1780
1784 if (k) 1781 if (k)
1785 eet_identity_close(k); 1782 eet_identity_close(k);
1786 1783
1787 k = eet_identity_open("cert.pem", "key_enc.pem", &badpass_get); 1784 k = eet_identity_open(_cert_pem, _key_enc_pem, &badpass_get);
1788 fail_if(k); 1785 fail_if(k);
1789 1786
1790 if (k) 1787 if (k)
1791 eet_identity_close(k); 1788 eet_identity_close(k);
1792 1789
1793 k = eet_identity_open("cert.pem", "key_enc.pem", &pass_get); 1790 k = eet_identity_open(_cert_pem, _key_enc_pem, &pass_get);
1794 fail_if(!k); 1791 fail_if(!k);
1795 1792
1796 if (k) 1793 if (k)
@@ -1812,7 +1809,6 @@ START_TEST(eet_cipher_decipher_simple)
1812 eet_init(); 1809 eet_init();
1813 1810
1814 fail_if(!(file = tmpnam(file))); 1811 fail_if(!(file = tmpnam(file)));
1815 fail_if(chdir(CERT_DIR));
1816 1812
1817 /* Crypt an eet file. */ 1813 /* Crypt an eet file. */
1818 ef = eet_open(file, EET_FILE_MODE_WRITE); 1814 ef = eet_open(file, EET_FILE_MODE_WRITE);
@@ -2761,12 +2757,56 @@ eet_suite(void)
2761 return s; 2757 return s;
2762} /* eet_suite */ 2758} /* eet_suite */
2763 2759
2760static const char *_cert_dir_find(const char *argv0)
2761{
2762 static char base[PATH_MAX] = "";
2763 char path[PATH_MAX];
2764 struct stat st;
2765
2766 eina_strlcpy(base, TESTS_SRC_DIR, sizeof(base));
2767 eina_str_join(path, sizeof(path), '/', base, "key.pem");
2768 if (stat(path, &st) == 0)
2769 return base;
2770
2771 if (base[0] != '/')
2772 {
2773 snprintf(base, sizeof(base), "%s/%s", TESTS_WD, TESTS_SRC_DIR);
2774 eina_str_join(path, sizeof(path), '/', base, "key.pem");
2775 if (stat(path, &st) == 0)
2776 return base;
2777 }
2778
2779 eina_strlcpy(base, argv0, sizeof(base));
2780 do
2781 {
2782 char *p = strrchr(base, '/');
2783 if (!p)
2784 {
2785 base[0] = '\0';
2786 break;
2787 }
2788 *p = '\0';
2789 eina_str_join(path, sizeof(path), '/', base, "key.pem");
2790 }
2791 while (stat(path, &st) != 0);
2792
2793 return base;
2794}
2795
2764int 2796int
2765main(void) 2797main(int argc EINA_UNUSED, char *argv[])
2766{ 2798{
2767 Suite *s; 2799 Suite *s;
2768 SRunner *sr; 2800 SRunner *sr;
2769 int failed_count; 2801 int failed_count;
2802 const char *base = _cert_dir_find(argv[0]);
2803
2804 eina_str_join(_key_pem, sizeof(_key_pem), '/', base, "key.pem");
2805 eina_str_join(_cert_pem, sizeof(_cert_pem), '/', base,"cert.pem");
2806 eina_str_join(_key_enc, sizeof(_key_enc), '/', base, "key.enc");
2807 eina_str_join(_key_enc_pem, sizeof(_key_enc_pem), '/', base, "key_enc.pem");
2808 eina_str_join(_key_enc_none_pem, sizeof(_key_enc_none_pem), '/',
2809 base, "key_enc_none.pem");
2770 2810
2771 s = eet_suite(); 2811 s = eet_suite();
2772 sr = srunner_create(s); 2812 sr = srunner_create(s);