diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-07-27 09:45:29 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-07-30 22:28:44 +0300 |
commit | 7727073aabbebc21c5ff7d8c22ef88c4e70b31bb (patch) | |
tree | 9efb9962b45ff5ba13cbdd8c6e82c01ae3ca2b68 /src/testcurl | |
parent | 3d75094b412ac2c6adb1b268166ea836826289bd (diff) | |
download | libmicrohttpd-7727073aabbebc21c5ff7d8c22ef88c4e70b31bb.tar.gz libmicrohttpd-7727073aabbebc21c5ff7d8c22ef88c4e70b31bb.zip |
test_digestauth2: added testing of Auth v2 API
Diffstat (limited to 'src/testcurl')
-rw-r--r-- | src/testcurl/.gitignore | 8 | ||||
-rw-r--r-- | src/testcurl/Makefile.am | 24 | ||||
-rw-r--r-- | src/testcurl/test_digestauth2.c | 96 |
3 files changed, 115 insertions, 13 deletions
diff --git a/src/testcurl/.gitignore b/src/testcurl/.gitignore index e35419ea..70fb27dc 100644 --- a/src/testcurl/.gitignore +++ b/src/testcurl/.gitignore | |||
@@ -158,12 +158,16 @@ core | |||
158 | /test_digestauth_emu_ext | 158 | /test_digestauth_emu_ext |
159 | /test_digestauth_emu_ext_oldapi | 159 | /test_digestauth_emu_ext_oldapi |
160 | /test_digestauth2 | 160 | /test_digestauth2 |
161 | /test_digestauth2_oldapi | 161 | /test_digestauth2_oldapi1 |
162 | /test_digestauth2_oldapi2 | ||
162 | /test_digestauth2_userhash | 163 | /test_digestauth2_userhash |
163 | /test_digestauth2_sha256 | 164 | /test_digestauth2_sha256 |
164 | /test_digestauth2_sha256_userhash | 165 | /test_digestauth2_sha256_userhash |
166 | /test_digestauth2_oldapi2_sha256 | ||
165 | /test_digestauth2_userdigest | 167 | /test_digestauth2_userdigest |
166 | /test_digestauth2_oldapi_userdigest | 168 | /test_digestauth2_oldapi1_userdigest |
169 | /test_digestauth2_oldapi2_userdigest | ||
167 | /test_digestauth2_userhash_userdigest | 170 | /test_digestauth2_userhash_userdigest |
168 | /test_digestauth2_sha256_userdigest | 171 | /test_digestauth2_sha256_userdigest |
172 | /test_digestauth2_oldapi2_sha256_userdigest | ||
169 | /test_digestauth2_sha256_userhash_userdigest | 173 | /test_digestauth2_sha256_userhash_userdigest |
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am index 28fb398d..a9182ea2 100644 --- a/src/testcurl/Makefile.am +++ b/src/testcurl/Makefile.am | |||
@@ -171,14 +171,18 @@ check_PROGRAMS += \ | |||
171 | test_digestauth_emu_ext \ | 171 | test_digestauth_emu_ext \ |
172 | test_digestauth_emu_ext_oldapi \ | 172 | test_digestauth_emu_ext_oldapi \ |
173 | test_digestauth2 \ | 173 | test_digestauth2 \ |
174 | test_digestauth2_oldapi \ | 174 | test_digestauth2_oldapi1 \ |
175 | test_digestauth2_oldapi2 \ | ||
175 | test_digestauth2_userhash \ | 176 | test_digestauth2_userhash \ |
176 | test_digestauth2_sha256 \ | 177 | test_digestauth2_sha256 \ |
177 | test_digestauth2_sha256_userhash \ | 178 | test_digestauth2_sha256_userhash \ |
179 | test_digestauth2_oldapi2_sha256 \ | ||
178 | test_digestauth2_userdigest \ | 180 | test_digestauth2_userdigest \ |
179 | test_digestauth2_oldapi_userdigest \ | 181 | test_digestauth2_oldapi1_userdigest \ |
182 | test_digestauth2_oldapi2_userdigest \ | ||
180 | test_digestauth2_userhash_userdigest \ | 183 | test_digestauth2_userhash_userdigest \ |
181 | test_digestauth2_sha256_userdigest \ | 184 | test_digestauth2_sha256_userdigest \ |
185 | test_digestauth2_oldapi2_sha256_userdigest \ | ||
182 | test_digestauth2_sha256_userhash_userdigest | 186 | test_digestauth2_sha256_userhash_userdigest |
183 | endif | 187 | endif |
184 | 188 | ||
@@ -292,7 +296,10 @@ test_digestauth_emu_ext_oldapi_SOURCES = \ | |||
292 | test_digestauth2_SOURCES = \ | 296 | test_digestauth2_SOURCES = \ |
293 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 297 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
294 | 298 | ||
295 | test_digestauth2_oldapi_SOURCES = \ | 299 | test_digestauth2_oldapi1_SOURCES = \ |
300 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | ||
301 | |||
302 | test_digestauth2_oldapi2_SOURCES = \ | ||
296 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 303 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
297 | 304 | ||
298 | test_digestauth2_userhash_SOURCES = \ | 305 | test_digestauth2_userhash_SOURCES = \ |
@@ -301,13 +308,19 @@ test_digestauth2_userhash_SOURCES = \ | |||
301 | test_digestauth2_sha256_SOURCES = \ | 308 | test_digestauth2_sha256_SOURCES = \ |
302 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 309 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
303 | 310 | ||
311 | test_digestauth2_oldapi2_sha256_SOURCES = \ | ||
312 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | ||
313 | |||
304 | test_digestauth2_sha256_userhash_SOURCES = \ | 314 | test_digestauth2_sha256_userhash_SOURCES = \ |
305 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 315 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
306 | 316 | ||
307 | test_digestauth2_userdigest_SOURCES = \ | 317 | test_digestauth2_userdigest_SOURCES = \ |
308 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 318 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
309 | 319 | ||
310 | test_digestauth2_oldapi_userdigest_SOURCES = \ | 320 | test_digestauth2_oldapi1_userdigest_SOURCES = \ |
321 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | ||
322 | |||
323 | test_digestauth2_oldapi2_userdigest_SOURCES = \ | ||
311 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 324 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
312 | 325 | ||
313 | test_digestauth2_userhash_userdigest_SOURCES = \ | 326 | test_digestauth2_userhash_userdigest_SOURCES = \ |
@@ -316,6 +329,9 @@ test_digestauth2_userhash_userdigest_SOURCES = \ | |||
316 | test_digestauth2_sha256_userdigest_SOURCES = \ | 329 | test_digestauth2_sha256_userdigest_SOURCES = \ |
317 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 330 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
318 | 331 | ||
332 | test_digestauth2_oldapi2_sha256_userdigest_SOURCES = \ | ||
333 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | ||
334 | |||
319 | test_digestauth2_sha256_userhash_userdigest_SOURCES = \ | 335 | test_digestauth2_sha256_userhash_userdigest_SOURCES = \ |
320 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h | 336 | test_digestauth2.c mhd_has_param.h mhd_has_in_name.h |
321 | 337 | ||
diff --git a/src/testcurl/test_digestauth2.c b/src/testcurl/test_digestauth2.c index 29a30113..19ae031f 100644 --- a/src/testcurl/test_digestauth2.c +++ b/src/testcurl/test_digestauth2.c | |||
@@ -735,9 +735,78 @@ ahc_echo (void *cls, | |||
735 | mhdErrorExitDesc ("'MHD_queue_auth_required_response3()' failed"); | 735 | mhdErrorExitDesc ("'MHD_queue_auth_required_response3()' failed"); |
736 | } | 736 | } |
737 | } | 737 | } |
738 | else | 738 | else if (2 == test_oldapi) |
739 | { | ||
740 | /* Use old API v2 */ | ||
741 | char *username; | ||
742 | int check_res; | ||
743 | |||
744 | username = MHD_digest_auth_get_username (connection); | ||
745 | if (NULL != username) | ||
746 | { /* Has a valid username in header */ | ||
747 | if (0 != strcmp (username, username_ptr)) | ||
748 | { | ||
749 | fprintf (stderr, "'username' does not match.\n" | ||
750 | "Expected: '%s'\tRecieved: '%s'. ", | ||
751 | username_ptr, | ||
752 | username); | ||
753 | mhdErrorExitDesc ("Wrong 'username'"); | ||
754 | } | ||
755 | MHD_free (username); | ||
756 | |||
757 | if (! test_userdigest) | ||
758 | check_res = | ||
759 | MHD_digest_auth_check2 (connection, REALM_VAL, username_ptr, | ||
760 | PASSWORD_VALUE, | ||
761 | 50 * TIMEOUTS_VAL, | ||
762 | test_sha256 ? | ||
763 | MHD_DIGEST_ALG_SHA256 : MHD_DIGEST_ALG_MD5); | ||
764 | else | ||
765 | check_res = | ||
766 | MHD_digest_auth_check_digest2 (connection, REALM_VAL, username_ptr, | ||
767 | userdigest_bin, userdigest_bin_size, | ||
768 | 50 * TIMEOUTS_VAL, | ||
769 | test_sha256 ? | ||
770 | MHD_DIGEST_ALG_SHA256 : | ||
771 | MHD_DIGEST_ALG_MD5); | ||
772 | |||
773 | if (MHD_YES != check_res) | ||
774 | { | ||
775 | fprintf (stderr, "'MHD_digest_auth_check[_digest]2()' returned " | ||
776 | "unexpected result: %d. ", check_res); | ||
777 | mhdErrorExitDesc ("Wrong 'MHD_digest_auth_check[_digest]2()' result"); | ||
778 | } | ||
779 | response = | ||
780 | MHD_create_response_from_buffer_static (MHD_STATICSTR_LEN_ (PAGE), | ||
781 | (const void *) PAGE); | ||
782 | if (NULL == response) | ||
783 | mhdErrorExitDesc ("Response creation failed"); | ||
784 | |||
785 | if (MHD_YES != | ||
786 | MHD_queue_response (connection, MHD_HTTP_OK, response)) | ||
787 | mhdErrorExitDesc ("'MHD_queue_response()' failed"); | ||
788 | } | ||
789 | else | ||
790 | { | ||
791 | /* Has no valid username in header */ | ||
792 | response = | ||
793 | MHD_create_response_from_buffer_static (MHD_STATICSTR_LEN_ (DENIED), | ||
794 | (const void *) DENIED); | ||
795 | if (NULL == response) | ||
796 | mhdErrorExitDesc ("Response creation failed"); | ||
797 | |||
798 | res = MHD_queue_auth_fail_response2 (connection, REALM_VAL, OPAQUE_VALUE, | ||
799 | response, 0, | ||
800 | test_sha256 ? | ||
801 | MHD_DIGEST_ALG_SHA256 : | ||
802 | MHD_DIGEST_ALG_MD5); | ||
803 | if (MHD_YES != res) | ||
804 | mhdErrorExitDesc ("'MHD_queue_auth_fail_response()' failed"); | ||
805 | } | ||
806 | } | ||
807 | else if (1 == test_oldapi) | ||
739 | { | 808 | { |
740 | /* Use old API */ | 809 | /* Use old API v1 */ |
741 | char *username; | 810 | char *username; |
742 | int check_res; | 811 | int check_res; |
743 | 812 | ||
@@ -796,6 +865,9 @@ ahc_echo (void *cls, | |||
796 | mhdErrorExitDesc ("'MHD_queue_auth_fail_response()' failed"); | 865 | mhdErrorExitDesc ("'MHD_queue_auth_fail_response()' failed"); |
797 | } | 866 | } |
798 | } | 867 | } |
868 | else | ||
869 | externalErrorExitDesc ("Wrong 'test_oldapi' value"); | ||
870 | |||
799 | MHD_destroy_response (response); | 871 | MHD_destroy_response (response); |
800 | return MHD_YES; | 872 | return MHD_YES; |
801 | } | 873 | } |
@@ -1087,8 +1159,8 @@ main (int argc, char *const *argv) | |||
1087 | { | 1159 | { |
1088 | #if ! CURL_AT_LEAST_VERSION (7,19,1) | 1160 | #if ! CURL_AT_LEAST_VERSION (7,19,1) |
1089 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ | 1161 | (void) argc; (void) argv; /* Unused. Silent compiler warning. */ |
1090 | /* Need version 7.19.1 for separate username and password */ | 1162 | /* Need version 7.19.1 or newer for separate username and password */ |
1091 | fprintf (stderr, "Required libcurl version 7.19.1 at least" | 1163 | fprintf (stderr, "Required libcurl at least version 7.19.1" |
1092 | " to run this test.\n"); | 1164 | " to run this test.\n"); |
1093 | return 77; | 1165 | return 77; |
1094 | #else /* CURL_AT_LEAST_VERSION(7,19,1) */ | 1166 | #else /* CURL_AT_LEAST_VERSION(7,19,1) */ |
@@ -1103,14 +1175,24 @@ main (int argc, char *const *argv) | |||
1103 | has_param (argc, argv, "--quiet") || | 1175 | has_param (argc, argv, "--quiet") || |
1104 | has_param (argc, argv, "-s") || | 1176 | has_param (argc, argv, "-s") || |
1105 | has_param (argc, argv, "--silent")); | 1177 | has_param (argc, argv, "--silent")); |
1106 | test_oldapi = has_in_name (argv[0], "_oldapi"); | 1178 | test_oldapi = 0; |
1179 | if (has_in_name (argv[0], "_oldapi1")) | ||
1180 | test_oldapi = 1; | ||
1181 | if (has_in_name (argv[0], "_oldapi2")) | ||
1182 | test_oldapi = 2; | ||
1107 | test_userhash = has_in_name (argv[0], "_userhash"); | 1183 | test_userhash = has_in_name (argv[0], "_userhash"); |
1108 | test_userdigest = has_in_name (argv[0], "_userdigest"); | 1184 | test_userdigest = has_in_name (argv[0], "_userdigest"); |
1109 | test_sha256 = has_in_name (argv[0], "_sha256"); | 1185 | test_sha256 = has_in_name (argv[0], "_sha256"); |
1110 | 1186 | ||
1187 | /* Wrong test types combinations */ | ||
1188 | if (1 == test_oldapi) | ||
1189 | { | ||
1190 | if (test_sha256) | ||
1191 | return 99; | ||
1192 | } | ||
1111 | if (test_oldapi) | 1193 | if (test_oldapi) |
1112 | { /* Wrong test types combination */ | 1194 | { |
1113 | if (test_userhash || test_sha256) | 1195 | if (test_userhash) |
1114 | return 99; | 1196 | return 99; |
1115 | } | 1197 | } |
1116 | 1198 | ||