Changeset 922 in openpam
- Timestamp:
- Feb 19, 2017, 7:28:30 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/configure.ac
r917 r922 122 122 AC_SUBST(SYSTEM_LIBPAM) 123 123 124 save_LIBS="${LIBS}" 125 LIBS="" 126 AC_SEARCH_LIBS([cryb_test_version], [cryb-test], [ 127 CRYB_TEST_LIBS="${LIBS}" 128 ], [ 129 CRYB_TEST_LIBS="" 130 AC_MSG_WARN([cryb-test library not available, unit tests disabled]) 131 ]) 132 LIBS="${save_LIBS}" 133 AC_SUBST(CRYB_TEST_LIBS) 134 AM_CONDITIONAL([WITH_TEST], [ test x"$CRYB_TEST_LIBS" != x"" ]) 135 124 136 AC_ARG_ENABLE([developer-warnings], 125 137 AS_HELP_STRING([--enable-developer-warnings], [enable strict warnings (default is NO)]), -
trunk/t/Makefile.am
r907 r922 1 1 # $Id$ 2 3 if WITH_TEST 2 4 3 5 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/libpam … … 6 8 PAM_RETURN_SO=$(abs_top_builddir)/modules/pam_return/.libs/pam_return.so 7 9 8 noinst_HEADERS = t .h t_pam_conv.h10 noinst_HEADERS = t_pam_conv.h 9 11 10 12 # tests … … 18 20 # libt - common support code 19 21 check_LIBRARIES = libt.a 20 libt_a_SOURCES = t_ main.c t_file.c t_pam_conv.c22 libt_a_SOURCES = t_pam_conv.c 21 23 22 # link with libpam and libt23 LDADD = libt.a24 # link with libpam and test framework 25 LDADD = $(CRYB_TEST_LIBS) libt.a 24 26 if WITH_SYSTEM_LIBPAM 25 27 LDADD += $(SYSTEM_LIBPAM) … … 27 29 LDADD += $(top_builddir)/lib/libpam/libpam.la 28 30 endif 31 32 endif -
trunk/t/t_openpam_ctype.c
r890 r922 34 34 #endif 35 35 36 #include <stdint.h> 36 37 #include <stdio.h> 37 38 #include <string.h> 38 39 40 #include <cryb/test.h> 41 39 42 #include "openpam_ctype.h" 40 41 #include "t.h"42 43 43 44 #define OC_DIGIT "0123456789" … … 62 63 63 64 #define T_OC(set) \ 64 T_FUNC(t_oc_##set, "is_" #set) \ 65 static int \ 66 t_oc_##set(char **desc, void *arg) \ 65 67 { \ 66 68 char crib[256]; \ 67 69 unsigned int i, ret; \ 68 70 \ 71 (void)desc; \ 72 (void)arg; \ 69 73 memset(crib, 0, sizeof crib); \ 70 74 for (i = 0; oc_##set[i]; ++i) \ … … 79 83 return (ret == 0); \ 80 84 } 85 #define T_OC_ADD(set) t_add_test(&t_oc_##set, NULL, "is_"#set) 81 86 82 87 T_OC(digit) … … 96 101 */ 97 102 98 static struct t_test *t_plan[] = { 99 T(t_oc_digit), 100 T(t_oc_xdigit), 101 T(t_oc_upper), 102 T(t_oc_lower), 103 T(t_oc_letter), 104 T(t_oc_lws), 105 T(t_oc_ws), 106 T(t_oc_p), 107 T(t_oc_pfcs), 108 NULL 109 }; 110 111 struct t_test ** 103 static int 112 104 t_prepare(int argc, char *argv[]) 113 105 { … … 115 107 (void)argc; 116 108 (void)argv; 117 return (t_plan); 109 T_OC_ADD(digit); 110 T_OC_ADD(xdigit); 111 T_OC_ADD(upper); 112 T_OC_ADD(lower); 113 T_OC_ADD(letter); 114 T_OC_ADD(lws); 115 T_OC_ADD(ws); 116 T_OC_ADD(p); 117 T_OC_ADD(pfcs); 118 return (0); 118 119 } 119 120 120 void 121 t_cleanup(void)121 int 122 main(int argc, char *argv[]) 122 123 { 124 125 t_main(t_prepare, NULL, argc, argv); 123 126 } -
trunk/t/t_openpam_dispatch.c
r913 r922 35 35 36 36 #include <err.h> 37 #include <stdint.h> 37 38 #include <stdio.h> 38 39 #include <stdlib.h> 39 40 #include <string.h> 41 #include <unistd.h> 42 43 #include <cryb/test.h> 40 44 41 45 #include <security/pam_appl.h> … … 43 47 44 48 #include "openpam_impl.h" 45 #include "t.h"46 49 #include "t_pam_conv.h" 50 51 #define T_FUNC(n, d) \ 52 static const char *t_ ## n ## _desc = d; \ 53 static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc), \ 54 OPENPAM_UNUSED(void *arg)) 55 56 #define T(n) \ 57 t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc) 47 58 48 59 const char *pam_return_so; … … 73 84 pam_err = pam_authenticate(pamh, 0); 74 85 t_verbose("pam_authenticate() returned %d\n", pam_err); 75 ret = (pam_err != PAM_SUCCESS);86 ret = (pam_err == PAM_SYSTEM_ERR); 76 87 pam_err = pam_setcred(pamh, 0); 77 88 t_verbose("pam_setcred() returned %d\n", pam_err); 78 ret |= (pam_err != PAM_SUCCESS);89 ret &= (pam_err == PAM_SYSTEM_ERR); 79 90 pam_err = pam_acct_mgmt(pamh, 0); 80 91 t_verbose("pam_acct_mgmt() returned %d\n", pam_err); 81 ret |= (pam_err != PAM_SUCCESS);92 ret &= (pam_err == PAM_SYSTEM_ERR); 82 93 pam_err = pam_chauthtok(pamh, 0); 83 94 t_verbose("pam_chauthtok() returned %d\n", pam_err); 84 ret |= (pam_err != PAM_SUCCESS);95 ret &= (pam_err == PAM_SYSTEM_ERR); 85 96 pam_err = pam_open_session(pamh, 0); 86 97 t_verbose("pam_open_session() returned %d\n", pam_err); 87 ret |= (pam_err != PAM_SUCCESS);98 ret &= (pam_err == PAM_SYSTEM_ERR); 88 99 pam_err = pam_close_session(pamh, 0); 89 100 t_verbose("pam_close_session() returned %d\n", pam_err); 90 ret |= (pam_err != PAM_SUCCESS); 91 pam_err = pam_end(pamh, pam_err); 92 ret |= (pam_err == PAM_SUCCESS); 101 ret &= (pam_err == PAM_SYSTEM_ERR); 102 pam_end(pamh, pam_err); 93 103 t_fclose(tf); 94 104 return (ret); … … 167 177 t_verbose("%s returned %d\n", 168 178 pam_func_name[tc->primitive], pam_err); 179 pam_end(pamh, pam_err); 180 t_verbose("here\n"); 169 181 t_fclose(tf); 170 182 } … … 178 190 */ 179 191 180 static struct t_test *t_plan[] = { 181 T(empty_policy), 182 T(mod_return), 183 184 NULL 185 }; 186 187 struct t_test ** 192 static int 188 193 t_prepare(int argc, char *argv[]) 189 194 { 190 195 191 if ((pam_return_so = getenv("PAM_RETURN_SO")) == NULL) 192 return (NULL); 196 (void)argc; 197 (void)argv; 198 199 if ((pam_return_so = getenv("PAM_RETURN_SO")) == NULL) { 200 t_verbose("define PAM_RETURN_SO before running these tests\n"); 201 return (0); 202 } 193 203 194 204 openpam_set_feature(OPENPAM_RESTRICT_MODULE_NAME, 0); … … 198 208 openpam_set_feature(OPENPAM_FALLBACK_TO_OTHER, 0); 199 209 200 (void)argc; 201 (void)argv; 202 return (t_plan); 203 } 204 205 void 206 t_cleanup(void) 207 { 208 } 210 T(empty_policy); 211 T(mod_return); 212 213 return (0); 214 } 215 216 int 217 main(int argc, char *argv[]) 218 { 219 220 t_main(t_prepare, NULL, argc, argv); 221 } -
trunk/t/t_openpam_readlinev.c
r890 r922 35 35 36 36 #include <err.h> 37 #include <stdint.h> 37 38 #include <stdio.h> 38 39 #include <stdlib.h> 39 40 #include <string.h> 40 41 42 #include <cryb/test.h> 43 41 44 #include <security/pam_appl.h> 42 45 #include <security/openpam.h> 43 46 44 47 #include "openpam_impl.h" 45 #include "t.h" 48 49 #define T_FUNC(n, d) \ 50 static const char *t_ ## n ## _desc = d; \ 51 static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc), \ 52 OPENPAM_UNUSED(void *arg)) 53 54 #define T(n) \ 55 t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc) 46 56 47 57 /* … … 56 66 int expectedc, gotc, i, lineno = 0; 57 67 char **gotv; 58 68 int ret; 69 70 ret = 1; 59 71 expectedc = 0; 60 72 if (expectedv != NULL) … … 66 78 if (expectedv != NULL && gotv == NULL) { 67 79 t_verbose("expected %d words, got nothing\n", expectedc); 68 return (0); 69 } 70 if (expectedv == NULL && gotv != NULL) { 80 ret = 0; 81 } else if (expectedv == NULL && gotv != NULL) { 71 82 t_verbose("expected nothing, got %d words\n", gotc); 72 FREEV(gotc, gotv); 73 return (0); 74 } 75 if (expectedv != NULL && gotv != NULL) { 83 ret = 0; 84 } else if (expectedv != NULL && gotv != NULL) { 76 85 if (expectedc != gotc) { 77 86 t_verbose("expected %d words, got %d\n", 78 87 expectedc, gotc); 79 FREEV(gotc, gotv); 80 return (0); 88 ret = 0; 81 89 } 82 90 for (i = 0; i < gotc; ++i) { … … 84 92 t_verbose("word %d: expected <<%s>>, " 85 93 "got <<%s>>\n", i, expectedv[i], gotv[i]); 86 FREEV(gotc, gotv); 87 return (0); 94 ret = 0; 88 95 } 89 96 } 90 FREEV(gotc, gotv);91 97 } 98 FREEV(gotc, gotv); 92 99 if (lineno != lines) { 93 100 t_verbose("expected to advance %d lines, advanced %d lines\n", 94 101 lines, lineno); 95 ret urn (0);102 ret = 0; 96 103 } 97 104 if (eof && !t_feof(tf)) { 98 105 t_verbose("expected EOF, but didn't get it\n"); 99 return (0); 106 ret = 0; 107 } else if (!eof && t_feof(tf)) { 108 t_verbose("didn't expect EOF, but got it anyway\n"); 109 ret = 0; 100 110 } 101 if (!eof && t_feof(tf)) { 102 t_verbose("didn't expect EOF, but got it anyway\n"); 103 return (0); 104 } 105 return (1); 111 return (ret); 106 112 } 107 113 … … 307 313 */ 308 314 309 static struct t_test *t_plan[] = { 310 T(empty_input), 311 T(empty_line), 312 T(unterminated_empty_line), 313 T(whitespace), 314 T(comment), 315 T(whitespace_before_comment), 316 T(line_continuation_within_whitespace), 317 318 T(one_word), 319 T(two_words), 320 T(many_words), 321 T(unterminated_line), 322 323 NULL 324 }; 325 326 struct t_test ** 315 static int 327 316 t_prepare(int argc, char *argv[]) 328 317 { … … 330 319 (void)argc; 331 320 (void)argv; 332 return (t_plan); 333 } 334 335 void 336 t_cleanup(void) 337 { 338 } 321 322 T(empty_input); 323 T(empty_line); 324 T(unterminated_empty_line); 325 T(whitespace); 326 T(comment); 327 T(whitespace_before_comment); 328 T(line_continuation_within_whitespace); 329 330 T(one_word); 331 T(two_words); 332 T(many_words); 333 T(unterminated_line); 334 335 return (0); 336 } 337 338 int 339 main(int argc, char *argv[]) 340 { 341 342 t_main(t_prepare, NULL, argc, argv); 343 } -
trunk/t/t_openpam_readword.c
r890 r922 40 40 #include <unistd.h> 41 41 42 #include <cryb/test.h> 43 42 44 #include <security/pam_appl.h> 43 45 #include <security/openpam.h> 44 46 45 #include "t.h" 47 #define T_FUNC(n, d) \ 48 static const char *t_ ## n ## _desc = d; \ 49 static int t_ ## n ## _func(OPENPAM_UNUSED(char **desc), \ 50 OPENPAM_UNUSED(void *arg)) 51 52 #define T(n) \ 53 t_add_test(&t_ ## n ## _func, NULL, t_ ## n ## _desc) 46 54 47 55 /* … … 57 65 char *got; 58 66 size_t len; 67 int ret; 59 68 60 69 got = openpam_readword(tf->file, &lineno, &len); 70 ret = 1; 61 71 if (t_ferror(tf)) 62 72 err(1, "%s(): %s", __func__, tf->name); 63 73 if (expected != NULL && got == NULL) { 64 74 t_verbose("expected <<%s>>, got nothing\n", expected); 65 return (0); 75 ret = 0; 76 } else if (expected == NULL && got != NULL) { 77 t_verbose("expected nothing, got <<%s>>\n", got); 78 ret = 0; 79 } else if (expected != NULL && got != NULL && strcmp(expected, got) != 0) { 80 t_verbose("expected <<%s>>, got <<%s>>\n", expected, got); 81 ret = 0; 66 82 } 67 if (expected == NULL && got != NULL) { 68 t_verbose("expected nothing, got <<%s>>\n", got); 69 return (0); 70 } 71 if (expected != NULL && got != NULL && strcmp(expected, got) != 0) { 72 t_verbose("expected <<%s>>, got <<%s>>\n", expected, got); 73 return (0); 74 } 83 free(got); 75 84 if (lineno != lines) { 76 85 t_verbose("expected to advance %d lines, advanced %d lines\n", 77 86 lines, lineno); 78 ret urn (0);87 ret = 0; 79 88 } 80 89 if (eof && !t_feof(tf)) { 81 90 t_verbose("expected EOF, but didn't get it\n"); 82 ret urn (0);91 ret = 0; 83 92 } 84 93 if (!eof && t_feof(tf)) { 85 94 t_verbose("didn't expect EOF, but got it anyway\n"); 86 ret urn (0);95 ret = 0; 87 96 } 88 97 ch = fgetc(tf->file); … … 91 100 if (eol && ch != '\n') { 92 101 t_verbose("expected EOL, but didn't get it\n"); 93 return (0); 94 } 95 if (!eol && ch == '\n') { 102 ret = 0; 103 } else if (!eol && ch == '\n') { 96 104 t_verbose("didn't expect EOL, but got it anyway\n"); 97 ret urn (0);105 ret = 0; 98 106 } 99 107 if (ch != EOF) 100 108 ungetc(ch, tf->file); 101 return ( 1);109 return (ret); 102 110 } 103 111 … … 958 966 */ 959 967 960 static struct t_test *t_plan[] = { 961 T(empty_input), 962 T(empty_line), 963 T(unterminated_line), 964 T(single_whitespace), 965 T(multiple_whitespace), 966 T(comment), 967 T(whitespace_before_comment), 968 T(single_quoted_comment), 969 T(double_quoted_comment), 970 T(comment_at_eof), 971 972 T(single_word), 973 T(single_whitespace_before_word), 974 T(double_whitespace_before_word), 975 T(single_whitespace_after_word), 976 T(double_whitespace_after_word), 977 T(comment_after_word), 978 T(word_containing_hash), 979 T(two_words), 980 981 T(naked_escape), 982 T(escaped_escape), 983 T(escaped_whitespace), 984 T(escaped_newline_before_word), 985 T(escaped_newline_within_word), 986 T(escaped_newline_after_word), 987 T(escaped_letter), 988 T(escaped_comment), 989 T(escape_at_eof), 990 991 T(naked_single_quote), 992 T(naked_double_quote), 993 T(empty_single_quotes), 994 T(empty_double_quotes), 995 T(single_quotes_within_double_quotes), 996 T(double_quotes_within_single_quotes), 997 T(single_quoted_whitespace), 998 T(double_quoted_whitespace), 999 T(single_quoted_words), 1000 T(double_quoted_words), 1001 1002 T(single_quote_before_word), 1003 T(double_quote_before_word), 1004 T(single_quote_within_word), 1005 T(double_quote_within_word), 1006 T(single_quote_after_word), 1007 T(double_quote_after_word), 1008 1009 T(escaped_single_quote), 1010 T(escaped_double_quote), 1011 T(escaped_whitespace_within_single_quotes), 1012 T(escaped_whitespace_within_double_quotes), 1013 T(escaped_letter_within_single_quotes), 1014 T(escaped_letter_within_double_quotes), 1015 T(escaped_escape_within_single_quotes), 1016 T(escaped_escape_within_double_quotes), 1017 T(escaped_single_quote_within_single_quotes), 1018 T(escaped_double_quote_within_single_quotes), 1019 T(escaped_single_quote_within_double_quotes), 1020 T(escaped_double_quote_within_double_quotes), 1021 1022 T(line_continuation_within_whitespace), 1023 T(line_continuation_before_whitespace), 1024 T(line_continuation_after_whitespace), 1025 T(line_continuation_within_word), 1026 1027 NULL 1028 }; 1029 1030 struct t_test ** 968 static int 1031 969 t_prepare(int argc, char *argv[]) 1032 970 { … … 1034 972 (void)argc; 1035 973 (void)argv; 1036 return (t_plan); 1037 } 1038 1039 void 1040 t_cleanup(void) 1041 { 1042 } 974 975 T(empty_input); 976 T(empty_line); 977 T(unterminated_line); 978 T(single_whitespace); 979 T(multiple_whitespace); 980 T(comment); 981 T(whitespace_before_comment); 982 T(single_quoted_comment); 983 T(double_quoted_comment); 984 T(comment_at_eof); 985 986 T(single_word); 987 T(single_whitespace_before_word); 988 T(double_whitespace_before_word); 989 T(single_whitespace_after_word); 990 T(double_whitespace_after_word); 991 T(comment_after_word); 992 T(word_containing_hash); 993 T(two_words); 994 995 T(naked_escape); 996 T(escaped_escape); 997 T(escaped_whitespace); 998 T(escaped_newline_before_word); 999 T(escaped_newline_within_word); 1000 T(escaped_newline_after_word); 1001 T(escaped_letter); 1002 T(escaped_comment); 1003 T(escape_at_eof); 1004 1005 T(naked_single_quote); 1006 T(naked_double_quote); 1007 T(empty_single_quotes); 1008 T(empty_double_quotes); 1009 T(single_quotes_within_double_quotes); 1010 T(double_quotes_within_single_quotes); 1011 T(single_quoted_whitespace); 1012 T(double_quoted_whitespace); 1013 T(single_quoted_words); 1014 T(double_quoted_words); 1015 1016 T(single_quote_before_word); 1017 T(double_quote_before_word); 1018 T(single_quote_within_word); 1019 T(double_quote_within_word); 1020 T(single_quote_after_word); 1021 T(double_quote_after_word); 1022 1023 T(escaped_single_quote); 1024 T(escaped_double_quote); 1025 T(escaped_whitespace_within_single_quotes); 1026 T(escaped_whitespace_within_double_quotes); 1027 T(escaped_letter_within_single_quotes); 1028 T(escaped_letter_within_double_quotes); 1029 T(escaped_escape_within_single_quotes); 1030 T(escaped_escape_within_double_quotes); 1031 T(escaped_single_quote_within_single_quotes); 1032 T(escaped_double_quote_within_single_quotes); 1033 T(escaped_single_quote_within_double_quotes); 1034 T(escaped_double_quote_within_double_quotes); 1035 1036 T(line_continuation_within_whitespace); 1037 T(line_continuation_before_whitespace); 1038 T(line_continuation_after_whitespace); 1039 T(line_continuation_within_word); 1040 1041 return (0); 1042 } 1043 1044 int 1045 main(int argc, char *argv[]) 1046 { 1047 1048 t_main(t_prepare, NULL, argc, argv); 1049 } -
trunk/t/t_pam_conv.c
r863 r922 36 36 #include <err.h> 37 37 #include <errno.h> 38 #include <stdint.h> 38 39 #include <stdio.h> 39 40 #include <stdlib.h> 40 41 #include <string.h> 42 43 #include <cryb/test.h> 41 44 42 45 #include <security/pam_appl.h> … … 45 48 #include "openpam_impl.h" 46 49 #include "openpam_asprintf.h" 47 #include "t.h"48 50 49 51 #include "t_pam_conv.h"
Note: See TracChangeset
for help on using the changeset viewer.