diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-09-05 14:53:05 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-09-05 14:53:05 +0300 |
commit | c3680cb737bcac2a4dc14cca5a80af6ca0de21e7 (patch) | |
tree | 79133b01df7634dea51ab6894c4ef2683f0b30b0 /src/testcurl/test_digestauth2.c | |
parent | 2699d2782011e97cf0b2563dab03d7237fb8fdb6 (diff) | |
download | libmicrohttpd-c3680cb737bcac2a4dc14cca5a80af6ca0de21e7.tar.gz libmicrohttpd-c3680cb737bcac2a4dc14cca5a80af6ca0de21e7.zip |
Digest Auth API: do not store 'userhash' in 'username' members
While the 'username' is used to carry 'userhash' in headers, it is
confusing as 'userhash' type of the data is different from type of
the 'username'. To make a clear distinction, use dedicated members
to store 'userhash'.
Diffstat (limited to 'src/testcurl/test_digestauth2.c')
-rw-r--r-- | src/testcurl/test_digestauth2.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/testcurl/test_digestauth2.c b/src/testcurl/test_digestauth2.c index f92d6d14..81a93b5e 100644 --- a/src/testcurl/test_digestauth2.c +++ b/src/testcurl/test_digestauth2.c | |||
@@ -476,8 +476,6 @@ ahc_echo (void *cls, | |||
476 | enum MHD_DigestAuthResult check_res; | 476 | enum MHD_DigestAuthResult check_res; |
477 | enum MHD_DigestAuthResult expect_res; | 477 | enum MHD_DigestAuthResult expect_res; |
478 | 478 | ||
479 | if (NULL == dinfo->username) | ||
480 | mhdErrorExitDesc ("'username' is NULL"); | ||
481 | if (curl_uses_usehash) | 479 | if (curl_uses_usehash) |
482 | { | 480 | { |
483 | if (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH != dinfo->uname_type) | 481 | if (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH != dinfo->uname_type) |
@@ -488,29 +486,33 @@ ahc_echo (void *cls, | |||
488 | (int) dinfo->uname_type); | 486 | (int) dinfo->uname_type); |
489 | mhdErrorExitDesc ("Wrong 'uname_type'"); | 487 | mhdErrorExitDesc ("Wrong 'uname_type'"); |
490 | } | 488 | } |
491 | else if (dinfo->username_len != userhash_hex_len) | 489 | else if (dinfo->userhash_hex_len != userhash_hex_len) |
492 | { | 490 | { |
493 | fprintf (stderr, "'username_len' does not match.\n" | 491 | fprintf (stderr, "'userhash_hex_len' does not match.\n" |
494 | "Expected: %u\tRecieved: %u. ", | 492 | "Expected: %u\tRecieved: %u. ", |
495 | (unsigned) userhash_hex_len, | 493 | (unsigned) userhash_hex_len, |
496 | (unsigned) dinfo->username_len); | 494 | (unsigned) dinfo->userhash_hex_len); |
497 | mhdErrorExitDesc ("Wrong 'username_len'"); | 495 | mhdErrorExitDesc ("Wrong 'userhash_hex_len'"); |
498 | } | 496 | } |
499 | else if (0 != memcmp (dinfo->username, userhash_hex, | 497 | else if (0 != memcmp (dinfo->userhash_hex, userhash_hex, |
500 | dinfo->username_len)) | 498 | dinfo->userhash_hex_len)) |
501 | { | 499 | { |
502 | fprintf (stderr, "'username' does not match.\n" | 500 | fprintf (stderr, "'userhash_hex' does not match.\n" |
503 | "Expected: '%s'\tRecieved: '%.*s'. ", | 501 | "Expected: '%s'\tRecieved: '%.*s'. ", |
504 | userhash_hex, | 502 | userhash_hex, |
505 | (int) dinfo->username_len, | 503 | (int) dinfo->userhash_hex_len, |
506 | dinfo->username); | 504 | dinfo->userhash_hex); |
507 | mhdErrorExitDesc ("Wrong 'username'"); | 505 | mhdErrorExitDesc ("Wrong 'userhash_hex'"); |
508 | } | 506 | } |
509 | else if (NULL == dinfo->userhash_bin) | 507 | else if (NULL == dinfo->userhash_bin) |
510 | mhdErrorExitDesc ("'userhash_bin' is NULL"); | 508 | mhdErrorExitDesc ("'userhash_bin' is NULL"); |
511 | else if (0 != memcmp (dinfo->userhash_bin, userhash_bin, | 509 | else if (0 != memcmp (dinfo->userhash_bin, userhash_bin, |
512 | dinfo->username_len / 2)) | 510 | dinfo->username_len / 2)) |
513 | mhdErrorExitDesc ("Wrong 'userhash_bin'"); | 511 | mhdErrorExitDesc ("Wrong 'userhash_bin'"); |
512 | else if (NULL != dinfo->username) | ||
513 | mhdErrorExitDesc ("'username' is NOT NULL"); | ||
514 | else if (0 != dinfo->username_len) | ||
515 | mhdErrorExitDesc ("'username_len' is NOT zero"); | ||
514 | } | 516 | } |
515 | else | 517 | else |
516 | { | 518 | { |
@@ -522,6 +524,8 @@ ahc_echo (void *cls, | |||
522 | (int) dinfo->uname_type); | 524 | (int) dinfo->uname_type); |
523 | mhdErrorExitDesc ("Wrong 'uname_type'"); | 525 | mhdErrorExitDesc ("Wrong 'uname_type'"); |
524 | } | 526 | } |
527 | else if (NULL == dinfo->username) | ||
528 | mhdErrorExitDesc ("'username' is NULL"); | ||
525 | else if (dinfo->username_len != strlen (username_ptr)) | 529 | else if (dinfo->username_len != strlen (username_ptr)) |
526 | { | 530 | { |
527 | fprintf (stderr, "'username_len' does not match.\n" | 531 | fprintf (stderr, "'username_len' does not match.\n" |
@@ -540,6 +544,10 @@ ahc_echo (void *cls, | |||
540 | dinfo->username); | 544 | dinfo->username); |
541 | mhdErrorExitDesc ("Wrong 'username'"); | 545 | mhdErrorExitDesc ("Wrong 'username'"); |
542 | } | 546 | } |
547 | else if (NULL != dinfo->userhash_hex) | ||
548 | mhdErrorExitDesc ("'userhash_hex' is NOT NULL"); | ||
549 | else if (0 != dinfo->userhash_hex_len) | ||
550 | mhdErrorExitDesc ("'userhash_hex_len' is NOT zero"); | ||
543 | else if (NULL != dinfo->userhash_bin) | 551 | else if (NULL != dinfo->userhash_bin) |
544 | mhdErrorExitDesc ("'userhash_bin' is NOT NULL"); | 552 | mhdErrorExitDesc ("'userhash_bin' is NOT NULL"); |
545 | } | 553 | } |
@@ -620,8 +628,6 @@ ahc_echo (void *cls, | |||
620 | uname = MHD_digest_auth_get_username3 (connection); | 628 | uname = MHD_digest_auth_get_username3 (connection); |
621 | if (NULL == uname) | 629 | if (NULL == uname) |
622 | mhdErrorExitDesc ("MHD_digest_auth_get_username3() returned NULL"); | 630 | mhdErrorExitDesc ("MHD_digest_auth_get_username3() returned NULL"); |
623 | else if (NULL == uname->username) | ||
624 | mhdErrorExitDesc ("'username' is NULL"); | ||
625 | if (curl_uses_usehash) | 631 | if (curl_uses_usehash) |
626 | { | 632 | { |
627 | if (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH != uname->uname_type) | 633 | if (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH != uname->uname_type) |
@@ -632,29 +638,33 @@ ahc_echo (void *cls, | |||
632 | (int) uname->uname_type); | 638 | (int) uname->uname_type); |
633 | mhdErrorExitDesc ("Wrong 'uname_type'"); | 639 | mhdErrorExitDesc ("Wrong 'uname_type'"); |
634 | } | 640 | } |
635 | else if (uname->username_len != userhash_hex_len) | 641 | else if (uname->userhash_hex_len != userhash_hex_len) |
636 | { | 642 | { |
637 | fprintf (stderr, "'username_len' does not match.\n" | 643 | fprintf (stderr, "'userhash_hex_len' does not match.\n" |
638 | "Expected: %u\tRecieved: %u. ", | 644 | "Expected: %u\tRecieved: %u. ", |
639 | (unsigned) userhash_hex_len, | 645 | (unsigned) userhash_hex_len, |
640 | (unsigned) uname->username_len); | 646 | (unsigned) uname->userhash_hex_len); |
641 | mhdErrorExitDesc ("Wrong 'username_len'"); | 647 | mhdErrorExitDesc ("Wrong 'userhash_hex_len'"); |
642 | } | 648 | } |
643 | else if (0 != memcmp (uname->username, userhash_hex, | 649 | else if (0 != memcmp (uname->userhash_hex, userhash_hex, |
644 | uname->username_len)) | 650 | uname->userhash_hex_len)) |
645 | { | 651 | { |
646 | fprintf (stderr, "'username' does not match.\n" | 652 | fprintf (stderr, "'username' does not match.\n" |
647 | "Expected: '%s'\tRecieved: '%.*s'. ", | 653 | "Expected: '%s'\tRecieved: '%.*s'. ", |
648 | userhash_hex, | 654 | userhash_hex, |
649 | (int) uname->username_len, | 655 | (int) uname->userhash_hex_len, |
650 | uname->username); | 656 | uname->userhash_hex); |
651 | mhdErrorExitDesc ("Wrong 'username'"); | 657 | mhdErrorExitDesc ("Wrong 'userhash_hex'"); |
652 | } | 658 | } |
653 | else if (NULL == uname->userhash_bin) | 659 | else if (NULL == uname->userhash_bin) |
654 | mhdErrorExitDesc ("'userhash_bin' is NULL"); | 660 | mhdErrorExitDesc ("'userhash_bin' is NULL"); |
655 | else if (0 != memcmp (uname->userhash_bin, userhash_bin, | 661 | else if (0 != memcmp (uname->userhash_bin, userhash_bin, |
656 | uname->username_len / 2)) | 662 | uname->username_len / 2)) |
657 | mhdErrorExitDesc ("Wrong 'userhash_bin'"); | 663 | mhdErrorExitDesc ("Wrong 'userhash_bin'"); |
664 | else if (NULL != uname->username) | ||
665 | mhdErrorExitDesc ("'username' is NOT NULL"); | ||
666 | else if (0 != uname->username_len) | ||
667 | mhdErrorExitDesc ("'username_len' is NOT zero"); | ||
658 | } | 668 | } |
659 | else | 669 | else |
660 | { | 670 | { |
@@ -666,6 +676,8 @@ ahc_echo (void *cls, | |||
666 | (int) uname->uname_type); | 676 | (int) uname->uname_type); |
667 | mhdErrorExitDesc ("Wrong 'uname_type'"); | 677 | mhdErrorExitDesc ("Wrong 'uname_type'"); |
668 | } | 678 | } |
679 | else if (NULL == uname->username) | ||
680 | mhdErrorExitDesc ("'username' is NULL"); | ||
669 | else if (uname->username_len != strlen (username_ptr)) | 681 | else if (uname->username_len != strlen (username_ptr)) |
670 | { | 682 | { |
671 | fprintf (stderr, "'username_len' does not match.\n" | 683 | fprintf (stderr, "'username_len' does not match.\n" |
@@ -684,6 +696,10 @@ ahc_echo (void *cls, | |||
684 | uname->username); | 696 | uname->username); |
685 | mhdErrorExitDesc ("Wrong 'username'"); | 697 | mhdErrorExitDesc ("Wrong 'username'"); |
686 | } | 698 | } |
699 | else if (NULL != uname->userhash_hex) | ||
700 | mhdErrorExitDesc ("'userhash_hex' is NOT NULL"); | ||
701 | else if (0 != uname->userhash_hex_len) | ||
702 | mhdErrorExitDesc ("'userhash_hex_len' is NOT zero"); | ||
687 | else if (NULL != uname->userhash_bin) | 703 | else if (NULL != uname->userhash_bin) |
688 | mhdErrorExitDesc ("'userhash_bin' is NOT NULL"); | 704 | mhdErrorExitDesc ("'userhash_bin' is NOT NULL"); |
689 | } | 705 | } |