1 #![cfg(not(target_arch = "wasm32"))]
2 
3 #[cfg(all(feature = "__tls", not(feature = "rustls-tls-manual-roots")))]
4 #[tokio::test]
test_badssl_modern()5 async fn test_badssl_modern() {
6     let text = reqwest::Client::builder()
7         .no_proxy()
8         .build()
9         .unwrap()
10         .get("https://mozilla-modern.badssl.com/")
11         .send()
12         .await
13         .unwrap()
14         .text()
15         .await
16         .unwrap();
17 
18     assert!(text.contains("<title>mozilla-modern.badssl.com</title>"));
19 }
20 
21 #[cfg(any(
22     feature = "rustls-tls-webpki-roots",
23     feature = "rustls-tls-native-roots"
24 ))]
25 #[tokio::test]
test_rustls_badssl_modern()26 async fn test_rustls_badssl_modern() {
27     let text = reqwest::Client::builder()
28         .use_rustls_tls()
29         .no_proxy()
30         .build()
31         .unwrap()
32         .get("https://mozilla-modern.badssl.com/")
33         .send()
34         .await
35         .unwrap()
36         .text()
37         .await
38         .unwrap();
39 
40     assert!(text.contains("<title>mozilla-modern.badssl.com</title>"));
41 }
42 
43 #[cfg(feature = "__tls")]
44 #[tokio::test]
test_badssl_self_signed()45 async fn test_badssl_self_signed() {
46     let text = reqwest::Client::builder()
47         .danger_accept_invalid_certs(true)
48         .no_proxy()
49         .build()
50         .unwrap()
51         .get("https://self-signed.badssl.com/")
52         .send()
53         .await
54         .unwrap()
55         .text()
56         .await
57         .unwrap();
58 
59     assert!(text.contains("<title>self-signed.badssl.com</title>"));
60 }
61 
62 #[cfg(feature = "__tls")]
63 #[tokio::test]
test_badssl_no_built_in_roots()64 async fn test_badssl_no_built_in_roots() {
65     let result = reqwest::Client::builder()
66         .tls_built_in_root_certs(false)
67         .no_proxy()
68         .build()
69         .unwrap()
70         .get("https://mozilla-modern.badssl.com/")
71         .send()
72         .await;
73 
74     assert!(result.is_err());
75 }
76 
77 #[cfg(feature = "native-tls")]
78 #[tokio::test]
test_badssl_wrong_host()79 async fn test_badssl_wrong_host() {
80     let text = reqwest::Client::builder()
81         .danger_accept_invalid_hostnames(true)
82         .no_proxy()
83         .build()
84         .unwrap()
85         .get("https://wrong.host.badssl.com/")
86         .send()
87         .await
88         .unwrap()
89         .text()
90         .await
91         .unwrap();
92 
93     assert!(text.contains("<title>wrong.host.badssl.com</title>"));
94 
95     let result = reqwest::Client::builder()
96         .danger_accept_invalid_hostnames(true)
97         .build()
98         .unwrap()
99         .get("https://self-signed.badssl.com/")
100         .send()
101         .await;
102 
103     assert!(result.is_err());
104 }
105