auth url test

This commit is contained in:
Martin Algesten
2018-07-01 18:40:49 +02:00
parent 51744804da
commit 8decd8e489
2 changed files with 29 additions and 1 deletions

View File

@@ -491,7 +491,6 @@ pub fn set_stream(resp: &mut Response, unit: Option<Unit>, stream: Stream) {
resp.stream = Some(stream); resp.stream = Some(stream);
} }
fn read_next_line<R: Read>(reader: &mut R) -> IoResult<AsciiString> { fn read_next_line<R: Read>(reader: &mut R) -> IoResult<AsciiString> {
let mut buf = Vec::new(); let mut buf = Vec::new();
let mut prev_byte_was_cr = false; let mut prev_byte_was_cr = false;

View File

@@ -28,3 +28,32 @@ fn kind_auth() {
.call(); .call();
assert_eq!(resp.status(), 200); assert_eq!(resp.status(), 200);
} }
#[test]
fn url_auth() {
test::set_handler("/url_auth", |unit| {
assert_eq!(
unit.header("Authorization").unwrap(),
"Basic QWxhZGRpbjpPcGVuU2VzYW1l"
);
test::make_response(200, "OK", vec![], vec![])
});
let resp = get("test://Aladdin:OpenSesame@host/url_auth").call();
assert_eq!(resp.status(), 200);
}
#[test]
fn url_auth_overridden() {
test::set_handler("/url_auth_overridden", |unit| {
assert_eq!(
unit.header("Authorization").unwrap(),
"Basic bWFydGluOnJ1YmJlcm1hc2hndW0="
);
test::make_response(200, "OK", vec![], vec![])
});
let agent = agent().auth("martin", "rubbermashgum").build();
let resp = agent
.get("test://Aladdin:OpenSesame@host/url_auth_overridden")
.call();
assert_eq!(resp.status(), 200);
}