@@ -1612,6 +1612,82 @@ public function testBasicHttpAuthSuccess()
1612
1612
$ this ->assertEquals ($ password2 , $ get_2 ->response ->password );
1613
1613
}
1614
1614
1615
+ public function testDigestHttpAuthSuccess ()
1616
+ {
1617
+ $ username = 'myusername ' ;
1618
+ $ password = 'mypassword ' ;
1619
+ $ invalid_password = 'anotherpassword ' ;
1620
+
1621
+ // Ensure that http digest returns canceled when not using any http digest authentication.
1622
+ $ multi_curl = new MultiCurl ();
1623
+ $ multi_curl ->setHeader ('X-DEBUG-TEST ' , 'http_digest_auth ' );
1624
+
1625
+ $ get_1 = $ multi_curl ->addGet (Test::TEST_URL );
1626
+ $ get_1 ->complete (function ($ instance ) {
1627
+ PHPUnit_Framework_Assert::assertEquals ('canceled ' , $ instance ->response );
1628
+ PHPUnit_Framework_Assert::assertEquals (401 , $ instance ->httpStatusCode );
1629
+ });
1630
+
1631
+ $ multi_curl ->start ();
1632
+
1633
+ // Ensure that http digest returns invalid when using incorrect http digest authentication.
1634
+ $ multi_curl = new MultiCurl ();
1635
+ $ multi_curl ->setHeader ('X-DEBUG-TEST ' , 'http_digest_auth ' );
1636
+ $ multi_curl ->setDigestAuthentication ($ username , $ invalid_password );
1637
+ $ this ->assertEquals (CURLAUTH_DIGEST , $ multi_curl ->getOpt (CURLOPT_HTTPAUTH ));
1638
+
1639
+ $ get_1 = $ multi_curl ->addGet (Test::TEST_URL );
1640
+ $ get_1 ->complete (function ($ instance ) {
1641
+ PHPUnit_Framework_Assert::assertEquals (CURLAUTH_DIGEST , $ instance ->getOpt (CURLOPT_HTTPAUTH ));
1642
+ PHPUnit_Framework_Assert::assertEquals ('invalid ' , $ instance ->response );
1643
+ PHPUnit_Framework_Assert::assertEquals (401 , $ instance ->httpStatusCode );
1644
+ });
1645
+
1646
+ $ multi_curl ->start ();
1647
+
1648
+ // Ensure that http digest returns valid when using correct http digest authentication.
1649
+ $ multi_curl = new MultiCurl ();
1650
+ $ multi_curl ->setHeader ('X-DEBUG-TEST ' , 'http_digest_auth ' );
1651
+ $ multi_curl ->setDigestAuthentication ($ username , $ password );
1652
+ $ this ->assertEquals (CURLAUTH_DIGEST , $ multi_curl ->getOpt (CURLOPT_HTTPAUTH ));
1653
+
1654
+ $ get_1 = $ multi_curl ->addGet (Test::TEST_URL );
1655
+ $ get_1 ->complete (function ($ instance ) {
1656
+ PHPUnit_Framework_Assert::assertEquals (CURLAUTH_DIGEST , $ instance ->getOpt (CURLOPT_HTTPAUTH ));
1657
+ PHPUnit_Framework_Assert::assertEquals ('valid ' , $ instance ->response );
1658
+ PHPUnit_Framework_Assert::assertEquals (200 , $ instance ->httpStatusCode );
1659
+ });
1660
+
1661
+ $ multi_curl ->start ();
1662
+
1663
+ // Ensure that http digest can return both invalid and valid when using
1664
+ // incorrect and correct authentication in the same MultiCurl.
1665
+ $ multi_curl = new MultiCurl ();
1666
+ $ multi_curl ->setHeader ('X-DEBUG-TEST ' , 'http_digest_auth ' );
1667
+ $ multi_curl ->setDigestAuthentication ($ username , $ password );
1668
+ $ this ->assertEquals (CURLAUTH_DIGEST , $ multi_curl ->getOpt (CURLOPT_HTTPAUTH ));
1669
+
1670
+ $ get_1 = $ multi_curl ->addGet (Test::TEST_URL );
1671
+ $ get_1 ->beforeSend (function ($ instance ) use ($ username , $ invalid_password ) {
1672
+ $ instance ->setDigestAuthentication ($ username , $ invalid_password );
1673
+ PHPUnit_Framework_Assert::assertEquals (CURLAUTH_DIGEST , $ instance ->getOpt (CURLOPT_HTTPAUTH ));
1674
+ });
1675
+ $ get_1 ->complete (function ($ instance ) {
1676
+ PHPUnit_Framework_Assert::assertEquals (CURLAUTH_DIGEST , $ instance ->getOpt (CURLOPT_HTTPAUTH ));
1677
+ PHPUnit_Framework_Assert::assertEquals ('invalid ' , $ instance ->response );
1678
+ PHPUnit_Framework_Assert::assertEquals (401 , $ instance ->httpStatusCode );
1679
+ });
1680
+
1681
+ $ get_2 = $ multi_curl ->addGet (Test::TEST_URL );
1682
+ $ get_2 ->complete (function ($ instance ) {
1683
+ PHPUnit_Framework_Assert::assertEquals (CURLAUTH_DIGEST , $ instance ->getOpt (CURLOPT_HTTPAUTH ));
1684
+ PHPUnit_Framework_Assert::assertEquals ('valid ' , $ instance ->response );
1685
+ PHPUnit_Framework_Assert::assertEquals (200 , $ instance ->httpStatusCode );
1686
+ });
1687
+
1688
+ $ multi_curl ->start ();
1689
+ }
1690
+
1615
1691
public function testCookies ()
1616
1692
{
1617
1693
$ data = array ('key ' => 'mycookie ' );
0 commit comments