about summary refs log tree commit diff
path: root/src/tests.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T15·44+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T16·30+0100
commitde16d9698db4ea851464d3f3c49f51c97dcbdf03 (patch)
tree2d128ab13cafbcb275842e5101b0aa5b329b1985 /src/tests.rs
parentbd726c7d4c0b32af26d338e6c33f9fb8a7d80171 (diff)
feat: Add optional `Request::basic_auth` utility function
This function adds a dependency on `base64` and is thus gated behind
the (enabled by default) `basic_auth` feature.
Diffstat (limited to 'src/tests.rs')
-rw-r--r--src/tests.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/tests.rs b/src/tests.rs
index cc44ca7b53..088334aa27 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -88,3 +88,19 @@ fn test_http_post_json() {
         "Content-Type should be `application/json`",
     );
 }
+
+// Tests for different authentication methods that are supported
+// out-of-the-box:
+
+#[cfg(feature = "basic_auth")] #[test]
+fn test_basic_auth() {
+    let request = Request::new(
+        Method::Get, "https://httpbin.org/basic-auth/alan_watts/oneness"
+    );
+
+    let response = request
+        .basic_auth("alan_watts", "oneness").expect("failed to set auth header")
+        .send().expect("failed to send request");
+
+    assert!(response.is_success(), "authorized request should succeed");
+}