@@ -807,6 +807,49 @@ test_mongoc_uri_new_with_error (void)
807
807
MONGOC_ERROR_COMMAND ,
808
808
MONGOC_ERROR_COMMAND_INVALID_ARG ,
809
809
"Invalid \"zlibcompressionlevel\" of 10: must be between -1 and 9" );
810
+
811
+ memset (& error , 0 , sizeof (bson_error_t ));
812
+ ASSERT (!mongoc_uri_new_with_error ("mongodb+srv://" , & error ));
813
+ ASSERT_ERROR_CONTAINS (error ,
814
+ MONGOC_ERROR_COMMAND ,
815
+ MONGOC_ERROR_COMMAND_INVALID_ARG ,
816
+ "Missing service name in SRV URI" );
817
+
818
+ memset (& error , 0 , sizeof (bson_error_t ));
819
+ ASSERT (!mongoc_uri_new_with_error ("mongodb+srv://%" , & error ));
820
+ ASSERT_ERROR_CONTAINS (error ,
821
+ MONGOC_ERROR_COMMAND ,
822
+ MONGOC_ERROR_COMMAND_INVALID_ARG ,
823
+ "Invalid service name in URI" );
824
+
825
+ memset (& error , 0 , sizeof (bson_error_t ));
826
+ ASSERT (!mongoc_uri_new_with_error ("mongodb+srv://x" , & error ));
827
+ ASSERT_ERROR_CONTAINS (error ,
828
+ MONGOC_ERROR_COMMAND ,
829
+ MONGOC_ERROR_COMMAND_INVALID_ARG ,
830
+ "Invalid service name in URI" );
831
+
832
+ memset (& error , 0 , sizeof (bson_error_t ));
833
+ ASSERT (!mongoc_uri_new_with_error ("mongodb+srv://x.y" , & error ));
834
+ ASSERT_ERROR_CONTAINS (error ,
835
+ MONGOC_ERROR_COMMAND ,
836
+ MONGOC_ERROR_COMMAND_INVALID_ARG ,
837
+ "Invalid service name in URI" );
838
+
839
+ memset (& error , 0 , sizeof (bson_error_t ));
840
+ ASSERT (!mongoc_uri_new_with_error ("mongodb+srv://a.b.c,d.e.f" , & error ));
841
+ ASSERT_ERROR_CONTAINS (
842
+ error ,
843
+ MONGOC_ERROR_COMMAND ,
844
+ MONGOC_ERROR_COMMAND_INVALID_ARG ,
845
+ "Multiple service names are prohibited in an SRV URI" );
846
+
847
+ memset (& error , 0 , sizeof (bson_error_t ));
848
+ ASSERT (!mongoc_uri_new_with_error ("mongodb+srv://a.b.c:8000" , & error ));
849
+ ASSERT_ERROR_CONTAINS (error ,
850
+ MONGOC_ERROR_COMMAND ,
851
+ MONGOC_ERROR_COMMAND_INVALID_ARG ,
852
+ "Port numbers are prohibited in an SRV URI" );
810
853
}
811
854
812
855
@@ -1576,17 +1619,17 @@ test_mongoc_uri_tls_ssl (const char *tls,
1576
1619
bson_error_t err ;
1577
1620
1578
1621
bson_snprintf (url_buffer ,
1579
- sizeof (url_buffer ),
1580
- "mongodb://CN=client,OU=kerneluser,O=10Gen,L=New York City,"
1581
-
1582
- "%s=true&authMechanism=MONGODB-X509&"
1583
- "%s=tests/x509gen/legacy-x509.pem&"
1584
- "%s=tests/x509gen/legacy-ca.crt&"
1585
- "%s=true" ,
1586
- tls ,
1587
- tlsCertificateKeyFile ,
1588
- tlsCAFile ,
1589
- tlsAllowInvalidHostnames );
1622
+ sizeof (url_buffer ),
1623
+ "mongodb://CN=client,OU=kerneluser,O=10Gen,L=New York City,"
1624
+
1625
+ "%s=true&authMechanism=MONGODB-X509&"
1626
+ "%s=tests/x509gen/legacy-x509.pem&"
1627
+ "%s=tests/x509gen/legacy-ca.crt&"
1628
+ "%s=true" ,
1629
+ tls ,
1630
+ tlsCertificateKeyFile ,
1631
+ tlsCAFile ,
1632
+ tlsAllowInvalidHostnames );
1590
1633
uri = mongoc_uri_new (url_buffer );
1591
1634
1592
1635
ASSERT_CMPSTR (
@@ -1614,11 +1657,11 @@ test_mongoc_uri_tls_ssl (const char *tls,
1614
1657
1615
1658
1616
1659
bson_snprintf (url_buffer ,
1617
- sizeof (url_buffer ),
1618
- "mongodb://localhost/?%s=true&%s=key.pem&%s=ca.pem" ,
1619
- tls ,
1620
- tlsCertificateKeyFile ,
1621
- tlsCAFile );
1660
+ sizeof (url_buffer ),
1661
+ "mongodb://localhost/?%s=true&%s=key.pem&%s=ca.pem" ,
1662
+ tls ,
1663
+ tlsCertificateKeyFile ,
1664
+ tlsCAFile );
1622
1665
uri = mongoc_uri_new (url_buffer );
1623
1666
1624
1667
ASSERT_CMPSTR (mongoc_uri_get_option_as_utf8 (
@@ -1667,11 +1710,11 @@ test_mongoc_uri_tls_ssl (const char *tls,
1667
1710
1668
1711
1669
1712
bson_snprintf (url_buffer ,
1670
- sizeof (url_buffer ),
1671
- "mongodb://localhost/?%s=true&%s=pa$$word!&%s=encrypted.pem" ,
1672
- tls ,
1673
- tlsCertificateKeyPassword ,
1674
- tlsCertificateKeyFile );
1713
+ sizeof (url_buffer ),
1714
+ "mongodb://localhost/?%s=true&%s=pa$$word!&%s=encrypted.pem" ,
1715
+ tls ,
1716
+ tlsCertificateKeyPassword ,
1717
+ tlsCertificateKeyFile );
1675
1718
uri = mongoc_uri_new (url_buffer );
1676
1719
1677
1720
ASSERT_CMPSTR (mongoc_uri_get_option_as_utf8 (
@@ -1700,10 +1743,10 @@ test_mongoc_uri_tls_ssl (const char *tls,
1700
1743
1701
1744
1702
1745
bson_snprintf (url_buffer ,
1703
- sizeof (url_buffer ),
1704
- "mongodb://localhost/?%s=true&%s=true" ,
1705
- tls ,
1706
- tlsAllowInvalidCertificates );
1746
+ sizeof (url_buffer ),
1747
+ "mongodb://localhost/?%s=true&%s=true" ,
1748
+ tls ,
1749
+ tlsAllowInvalidCertificates );
1707
1750
uri = mongoc_uri_new (url_buffer );
1708
1751
1709
1752
ASSERT_CMPSTR (mongoc_uri_get_option_as_utf8 (
@@ -1727,29 +1770,29 @@ test_mongoc_uri_tls_ssl (const char *tls,
1727
1770
1728
1771
1729
1772
bson_snprintf (url_buffer ,
1730
- sizeof (url_buffer ),
1731
- "mongodb://localhost/?%s=foo.pem" ,
1732
- tlsCertificateKeyFile );
1773
+ sizeof (url_buffer ),
1774
+ "mongodb://localhost/?%s=foo.pem" ,
1775
+ tlsCertificateKeyFile );
1733
1776
uri = mongoc_uri_new (url_buffer );
1734
1777
ASSERT (mongoc_uri_get_ssl (uri ));
1735
1778
ASSERT (mongoc_uri_get_tls (uri ));
1736
1779
mongoc_uri_destroy (uri );
1737
1780
1738
1781
1739
1782
bson_snprintf (url_buffer ,
1740
- sizeof (url_buffer ),
1741
- "mongodb://localhost/?%s=foo.pem" ,
1742
- tlsCAFile );
1783
+ sizeof (url_buffer ),
1784
+ "mongodb://localhost/?%s=foo.pem" ,
1785
+ tlsCAFile );
1743
1786
uri = mongoc_uri_new (url_buffer );
1744
1787
ASSERT (mongoc_uri_get_ssl (uri ));
1745
1788
ASSERT (mongoc_uri_get_tls (uri ));
1746
1789
mongoc_uri_destroy (uri );
1747
1790
1748
1791
1749
1792
bson_snprintf (url_buffer ,
1750
- sizeof (url_buffer ),
1751
- "mongodb://localhost/?%s=true" ,
1752
- tlsAllowInvalidCertificates );
1793
+ sizeof (url_buffer ),
1794
+ "mongodb://localhost/?%s=true" ,
1795
+ tlsAllowInvalidCertificates );
1753
1796
uri = mongoc_uri_new (url_buffer );
1754
1797
ASSERT (mongoc_uri_get_ssl (uri ));
1755
1798
ASSERT (mongoc_uri_get_tls (uri ));
@@ -1761,9 +1804,9 @@ test_mongoc_uri_tls_ssl (const char *tls,
1761
1804
1762
1805
1763
1806
bson_snprintf (url_buffer ,
1764
- sizeof (url_buffer ),
1765
- "mongodb://localhost/?%s=true" ,
1766
- tlsAllowInvalidHostnames );
1807
+ sizeof (url_buffer ),
1808
+ "mongodb://localhost/?%s=true" ,
1809
+ tlsAllowInvalidHostnames );
1767
1810
uri = mongoc_uri_new (url_buffer );
1768
1811
ASSERT (mongoc_uri_get_ssl (uri ));
1769
1812
ASSERT (mongoc_uri_get_tls (uri ));
@@ -1775,32 +1818,32 @@ test_mongoc_uri_tls_ssl (const char *tls,
1775
1818
1776
1819
1777
1820
bson_snprintf (url_buffer ,
1778
- sizeof (url_buffer ),
1779
- "mongodb://localhost/?%s=false&%s=foo.pem" ,
1780
- tls ,
1781
- tlsCertificateKeyFile );
1821
+ sizeof (url_buffer ),
1822
+ "mongodb://localhost/?%s=false&%s=foo.pem" ,
1823
+ tls ,
1824
+ tlsCertificateKeyFile );
1782
1825
uri = mongoc_uri_new (url_buffer );
1783
1826
ASSERT (!mongoc_uri_get_ssl (uri ));
1784
1827
ASSERT (!mongoc_uri_get_tls (uri ));
1785
1828
mongoc_uri_destroy (uri );
1786
1829
1787
1830
1788
1831
bson_snprintf (url_buffer ,
1789
- sizeof (url_buffer ),
1790
- "mongodb://localhost/?%s=false&%s=foo.pem" ,
1791
- tls ,
1792
- tlsCertificateKeyFile );
1832
+ sizeof (url_buffer ),
1833
+ "mongodb://localhost/?%s=false&%s=foo.pem" ,
1834
+ tls ,
1835
+ tlsCertificateKeyFile );
1793
1836
uri = mongoc_uri_new (url_buffer );
1794
1837
ASSERT (!mongoc_uri_get_ssl (uri ));
1795
1838
ASSERT (!mongoc_uri_get_tls (uri ));
1796
1839
mongoc_uri_destroy (uri );
1797
1840
1798
1841
1799
1842
bson_snprintf (url_buffer ,
1800
- sizeof (url_buffer ),
1801
- "mongodb://localhost/?%s=false&%s=true" ,
1802
- tls ,
1803
- tlsAllowInvalidCertificates );
1843
+ sizeof (url_buffer ),
1844
+ "mongodb://localhost/?%s=false&%s=true" ,
1845
+ tls ,
1846
+ tlsAllowInvalidCertificates );
1804
1847
uri = mongoc_uri_new (url_buffer );
1805
1848
ASSERT (!mongoc_uri_get_ssl (uri ));
1806
1849
ASSERT (!mongoc_uri_get_tls (uri ));
@@ -1812,10 +1855,10 @@ test_mongoc_uri_tls_ssl (const char *tls,
1812
1855
1813
1856
1814
1857
bson_snprintf (url_buffer ,
1815
- sizeof (url_buffer ),
1816
- "mongodb://localhost/?%s=false&%s=false" ,
1817
- tls ,
1818
- tlsAllowInvalidHostnames );
1858
+ sizeof (url_buffer ),
1859
+ "mongodb://localhost/?%s=false&%s=false" ,
1860
+ tls ,
1861
+ tlsAllowInvalidHostnames );
1819
1862
uri = mongoc_uri_new (url_buffer );
1820
1863
ASSERT (!mongoc_uri_get_ssl (uri ));
1821
1864
ASSERT (!mongoc_uri_get_tls (uri ));
@@ -1834,10 +1877,10 @@ test_mongoc_uri_tls_ssl (const char *tls,
1834
1877
/* Mixing options okay so long as they match */
1835
1878
capture_logs (true);
1836
1879
bson_snprintf (url_buffer ,
1837
- sizeof (url_buffer ),
1838
- "mongodb://localhost/?%s=true&%s=true" ,
1839
- tls ,
1840
- tlsalt );
1880
+ sizeof (url_buffer ),
1881
+ "mongodb://localhost/?%s=true&%s=true" ,
1882
+ tls ,
1883
+ tlsalt );
1841
1884
uri = mongoc_uri_new (url_buffer );
1842
1885
ASSERT (mongoc_uri_get_option_as_bool (uri , tls , false));
1843
1886
ASSERT_NO_CAPTURED_LOGS (url_buffer );
@@ -1846,10 +1889,10 @@ test_mongoc_uri_tls_ssl (const char *tls,
1846
1889
/* Same option with different values okay, latter overrides */
1847
1890
capture_logs (true);
1848
1891
bson_snprintf (url_buffer ,
1849
- sizeof (url_buffer ),
1850
- "mongodb://localhost/?%s=true&%s=false" ,
1851
- tls ,
1852
- tls );
1892
+ sizeof (url_buffer ),
1893
+ "mongodb://localhost/?%s=true&%s=false" ,
1894
+ tls ,
1895
+ tls );
1853
1896
uri = mongoc_uri_new (url_buffer );
1854
1897
ASSERT (!mongoc_uri_get_option_as_bool (uri , tls , true));
1855
1898
if (strcmp (tls , "tls" )) {
@@ -1866,10 +1909,10 @@ test_mongoc_uri_tls_ssl (const char *tls,
1866
1909
/* Mixing options not okay if values differ */
1867
1910
capture_logs (false);
1868
1911
bson_snprintf (url_buffer ,
1869
- sizeof (url_buffer ),
1870
- "mongodb://localhost/?%s=true&%s=false" ,
1871
- tls ,
1872
- tlsalt );
1912
+ sizeof (url_buffer ),
1913
+ "mongodb://localhost/?%s=true&%s=false" ,
1914
+ tls ,
1915
+ tlsalt );
1873
1916
uri = mongoc_uri_new_with_error (url_buffer , & err );
1874
1917
if (strcmp (tls , "tls" )) {
1875
1918
ASSERT_ERROR_CONTAINS (err ,
@@ -1889,9 +1932,9 @@ test_mongoc_uri_tls_ssl (const char *tls,
1889
1932
/* No conflict appears with implicit tls=true via SRV */
1890
1933
capture_logs (false);
1891
1934
bson_snprintf (url_buffer ,
1892
- sizeof (url_buffer ),
1893
- "mongodb+srv://a.b.c/?%s=foo.pem" ,
1894
- tlsCAFile );
1935
+ sizeof (url_buffer ),
1936
+ "mongodb+srv://a.b.c/?%s=foo.pem" ,
1937
+ tlsCAFile );
1895
1938
uri = mongoc_uri_new (url_buffer );
1896
1939
ASSERT (mongoc_uri_get_option_as_bool (uri , tls , false));
1897
1940
mongoc_uri_destroy (uri );
0 commit comments