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.
This commit is contained in:
parent
bd726c7d4c
commit
de16d9698d
3 changed files with 29 additions and 1 deletions
16
src/tests.rs
16
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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue