mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 17:07:01 +02:00
Added HTTP Authentication for Client (#540)
This commit is contained in:
@@ -506,3 +506,31 @@ fn client_read_until_eof() {
|
||||
let bytes = sys.block_on(response.body()).unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(b"welcome!"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_basic_auth() {
|
||||
let mut srv =
|
||||
test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
||||
/// set authorization header to Basic <base64 encoded username:password>
|
||||
let request = srv
|
||||
.get()
|
||||
.basic_auth("username", Some("password"))
|
||||
.finish()
|
||||
.unwrap();
|
||||
let repr = format!("{:?}", request);
|
||||
assert!(repr.contains("Basic dXNlcm5hbWU6cGFzc3dvcmQ="));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_bearer_auth() {
|
||||
let mut srv =
|
||||
test::TestServer::new(|app| app.handler(|_| HttpResponse::Ok().body(STR)));
|
||||
/// set authorization header to Bearer <token>
|
||||
let request = srv
|
||||
.get()
|
||||
.bearer_auth("someS3cr3tAutht0k3n")
|
||||
.finish()
|
||||
.unwrap();
|
||||
let repr = format!("{:?}", request);
|
||||
assert!(repr.contains("Bearer someS3cr3tAutht0k3n"));
|
||||
}
|
Reference in New Issue
Block a user