0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <cgreen/cgreen.h>
0038 #include <ubf.h>
0039 #include <ndrstandard.h>
0040 #include <string.h>
0041 #include <ndebug.h>
0042 #include <excrypto.h>
0043 #include "test.fd.h"
0044 #include "ubfunit1.h"
0045
0046
0047
0048
0049 Ensure(test_crypto_enc_string)
0050 {
0051 char buf[1024]="";
0052 char buf2[1024]="";
0053 int i;
0054 long len;
0055 #define ENC_TEST_STRING "HELLO STRING _ 123 hello test"
0056
0057 for (i=0; i<100; i++)
0058 {
0059 len=sizeof(buf);
0060 assert_equal(
0061 ndrx_crypto_enc_string(ENC_TEST_STRING, buf, &len),
0062 EXSUCCEED);
0063
0064 assert_equal(strlen(buf)+1, len);
0065
0066 NDRX_LOG(log_debug, "Encrypted string: [%s]", buf);
0067
0068 len=sizeof(buf2);
0069 assert_equal(
0070 ndrx_crypto_dec_string(buf, buf2, &len),
0071 EXSUCCEED);
0072
0073
0074 assert_string_equal(buf2, ENC_TEST_STRING);
0075 assert_equal(strlen(buf2)+1, len);
0076 }
0077 }
0078
0079
0080
0081
0082
0083 Ensure(test_crypto_subst_func)
0084 {
0085 char encdata[PATH_MAX];
0086 char fmt[PATH_MAX];
0087 int i;
0088 long len;
0089
0090 #define ENC_SUBST_STRING "Enduro/X"
0091
0092 assert_equal(setenv("UBFTESTENV", "ENVTEST", EXTRUE), EXSUCCEED);
0093 assert_equal(setenv("UBFTESTENV2", "ENVTEST2", EXTRUE), EXSUCCEED);
0094
0095
0096 for (i=0; i < 100; i++)
0097 {
0098
0099
0100 len=sizeof(encdata);
0101 assert_equal(ndrx_crypto_enc_string(ENC_SUBST_STRING, encdata, &len),
0102 EXSUCCEED);
0103
0104 snprintf(fmt, sizeof(fmt), "Hello ${dec=%s} ${UBFTESTENV} "
0105 "${dec=%s} ${UBFTESTENV2} from C", encdata, encdata);
0106
0107 NDRX_LOG(log_debug, "String with decrypt func: [%s]", fmt);
0108
0109 ndrx_str_env_subs_len(fmt, sizeof(fmt));
0110
0111 assert_string_equal(fmt, "Hello Enduro/X ENVTEST Enduro/X ENVTEST2 from C");
0112 }
0113 }
0114
0115
0116
0117
0118
0119 TestSuite *ubf_nstd_crypto(void)
0120 {
0121 TestSuite *suite = create_test_suite();
0122
0123
0124
0125
0126
0127
0128 add_test(suite, test_crypto_enc_string);
0129 add_test(suite, test_crypto_subst_func);
0130
0131 return suite;
0132 }
0133