gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 11/15: test_digestauth2: added testing of Auth v2 API


From: gnunet
Subject: [libmicrohttpd] 11/15: test_digestauth2: added testing of Auth v2 API
Date: Sat, 30 Jul 2022 21:29:33 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 7727073aabbebc21c5ff7d8c22ef88c4e70b31bb
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Jul 27 09:45:29 2022 +0300

    test_digestauth2: added testing of Auth v2 API
---
 src/testcurl/.gitignore         |  8 +++-
 src/testcurl/Makefile.am        | 24 +++++++++--
 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
 /test_digestauth_emu_ext
 /test_digestauth_emu_ext_oldapi
 /test_digestauth2
-/test_digestauth2_oldapi
+/test_digestauth2_oldapi1
+/test_digestauth2_oldapi2
 /test_digestauth2_userhash
 /test_digestauth2_sha256
 /test_digestauth2_sha256_userhash
+/test_digestauth2_oldapi2_sha256
 /test_digestauth2_userdigest
-/test_digestauth2_oldapi_userdigest
+/test_digestauth2_oldapi1_userdigest
+/test_digestauth2_oldapi2_userdigest
 /test_digestauth2_userhash_userdigest
 /test_digestauth2_sha256_userdigest
+/test_digestauth2_oldapi2_sha256_userdigest
 /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 += \
   test_digestauth_emu_ext \
   test_digestauth_emu_ext_oldapi \
   test_digestauth2 \
-  test_digestauth2_oldapi \
+  test_digestauth2_oldapi1 \
+  test_digestauth2_oldapi2 \
   test_digestauth2_userhash \
   test_digestauth2_sha256 \
   test_digestauth2_sha256_userhash \
+  test_digestauth2_oldapi2_sha256 \
   test_digestauth2_userdigest \
-  test_digestauth2_oldapi_userdigest \
+  test_digestauth2_oldapi1_userdigest \
+  test_digestauth2_oldapi2_userdigest \
   test_digestauth2_userhash_userdigest \
   test_digestauth2_sha256_userdigest \
+  test_digestauth2_oldapi2_sha256_userdigest \
   test_digestauth2_sha256_userhash_userdigest
 endif
 
@@ -292,7 +296,10 @@ test_digestauth_emu_ext_oldapi_SOURCES = \
 test_digestauth2_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
-test_digestauth2_oldapi_SOURCES = \
+test_digestauth2_oldapi1_SOURCES = \
+  test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
+
+test_digestauth2_oldapi2_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
 test_digestauth2_userhash_SOURCES = \
@@ -301,13 +308,19 @@ test_digestauth2_userhash_SOURCES = \
 test_digestauth2_sha256_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
+test_digestauth2_oldapi2_sha256_SOURCES = \
+  test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
+
 test_digestauth2_sha256_userhash_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
 test_digestauth2_userdigest_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
-test_digestauth2_oldapi_userdigest_SOURCES = \
+test_digestauth2_oldapi1_userdigest_SOURCES = \
+  test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
+
+test_digestauth2_oldapi2_userdigest_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
 test_digestauth2_userhash_userdigest_SOURCES = \
@@ -316,6 +329,9 @@ test_digestauth2_userhash_userdigest_SOURCES = \
 test_digestauth2_sha256_userdigest_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
+test_digestauth2_oldapi2_sha256_userdigest_SOURCES = \
+  test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
+
 test_digestauth2_sha256_userhash_userdigest_SOURCES = \
   test_digestauth2.c mhd_has_param.h mhd_has_in_name.h
 
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,
         mhdErrorExitDesc ("'MHD_queue_auth_required_response3()' failed");
     }
   }
-  else
+  else if (2 == test_oldapi)
+  {
+    /* Use old API v2 */
+    char *username;
+    int check_res;
+
+    username = MHD_digest_auth_get_username (connection);
+    if (NULL != username)
+    { /* Has a valid username in header */
+      if (0 != strcmp (username, username_ptr))
+      {
+        fprintf (stderr, "'username' does not match.\n"
+                 "Expected: '%s'\tRecieved: '%s'. ",
+                 username_ptr,
+                 username);
+        mhdErrorExitDesc ("Wrong 'username'");
+      }
+      MHD_free (username);
+
+      if (! test_userdigest)
+        check_res =
+          MHD_digest_auth_check2 (connection, REALM_VAL, username_ptr,
+                                  PASSWORD_VALUE,
+                                  50 * TIMEOUTS_VAL,
+                                  test_sha256 ?
+                                  MHD_DIGEST_ALG_SHA256 : MHD_DIGEST_ALG_MD5);
+      else
+        check_res =
+          MHD_digest_auth_check_digest2 (connection, REALM_VAL, username_ptr,
+                                         userdigest_bin, userdigest_bin_size,
+                                         50 * TIMEOUTS_VAL,
+                                         test_sha256 ?
+                                         MHD_DIGEST_ALG_SHA256 :
+                                         MHD_DIGEST_ALG_MD5);
+
+      if (MHD_YES != check_res)
+      {
+        fprintf (stderr, "'MHD_digest_auth_check[_digest]2()' returned "
+                 "unexpected result: %d. ", check_res);
+        mhdErrorExitDesc ("Wrong 'MHD_digest_auth_check[_digest]2()' result");
+      }
+      response =
+        MHD_create_response_from_buffer_static (MHD_STATICSTR_LEN_ (PAGE),
+                                                (const void *) PAGE);
+      if (NULL == response)
+        mhdErrorExitDesc ("Response creation failed");
+
+      if (MHD_YES !=
+          MHD_queue_response (connection, MHD_HTTP_OK, response))
+        mhdErrorExitDesc ("'MHD_queue_response()' failed");
+    }
+    else
+    {
+      /* Has no valid username in header */
+      response =
+        MHD_create_response_from_buffer_static (MHD_STATICSTR_LEN_ (DENIED),
+                                                (const void *) DENIED);
+      if (NULL == response)
+        mhdErrorExitDesc ("Response creation failed");
+
+      res = MHD_queue_auth_fail_response2 (connection, REALM_VAL, OPAQUE_VALUE,
+                                           response, 0,
+                                           test_sha256 ?
+                                           MHD_DIGEST_ALG_SHA256 :
+                                           MHD_DIGEST_ALG_MD5);
+      if (MHD_YES != res)
+        mhdErrorExitDesc ("'MHD_queue_auth_fail_response()' failed");
+    }
+  }
+  else if (1 == test_oldapi)
   {
-    /* Use old API */
+    /* Use old API v1 */
     char *username;
     int check_res;
 
@@ -796,6 +865,9 @@ ahc_echo (void *cls,
         mhdErrorExitDesc ("'MHD_queue_auth_fail_response()' failed");
     }
   }
+  else
+    externalErrorExitDesc ("Wrong 'test_oldapi' value");
+
   MHD_destroy_response (response);
   return MHD_YES;
 }
@@ -1087,8 +1159,8 @@ main (int argc, char *const *argv)
 {
 #if ! CURL_AT_LEAST_VERSION (7,19,1)
   (void) argc; (void) argv; /* Unused. Silent compiler warning. */
-  /* Need version 7.19.1 for separate username and password */
-  fprintf (stderr, "Required libcurl version 7.19.1 at least"
+  /* Need version 7.19.1 or newer for separate username and password */
+  fprintf (stderr, "Required libcurl at least version 7.19.1"
            " to run this test.\n");
   return 77;
 #else  /* CURL_AT_LEAST_VERSION(7,19,1) */
@@ -1103,14 +1175,24 @@ main (int argc, char *const *argv)
                has_param (argc, argv, "--quiet") ||
                has_param (argc, argv, "-s") ||
                has_param (argc, argv, "--silent"));
-  test_oldapi = has_in_name (argv[0], "_oldapi");
+  test_oldapi = 0;
+  if (has_in_name (argv[0], "_oldapi1"))
+    test_oldapi = 1;
+  if (has_in_name (argv[0], "_oldapi2"))
+    test_oldapi = 2;
   test_userhash = has_in_name (argv[0], "_userhash");
   test_userdigest = has_in_name (argv[0], "_userdigest");
   test_sha256 = has_in_name (argv[0], "_sha256");
 
+  /* Wrong test types combinations */
+  if (1 == test_oldapi)
+  {
+    if (test_sha256)
+      return 99;
+  }
   if (test_oldapi)
-  { /* Wrong test types combination */
-    if (test_userhash || test_sha256)
+  {
+    if (test_userhash)
       return 99;
   }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]