mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Rewrite test_auth_ui_needs_www_auth.
This commit is contained in:
parent
4c34e9aa89
commit
a8f7f3c1db
1 changed files with 18 additions and 40 deletions
|
@ -149,15 +149,6 @@ impl UIProvider for TestProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn basic_auth(headers: Headers) -> MockResponse {
|
|
||||||
MockResponse::new(
|
|
||||||
headers,
|
|
||||||
StatusCode::Unauthorized,
|
|
||||||
RawStatus(401, Cow::Borrowed("Unauthorized")),
|
|
||||||
b"".to_vec()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn redirect_with_headers(host: String, mut headers: Headers) -> MockResponse {
|
fn redirect_with_headers(host: String, mut headers: Headers) -> MockResponse {
|
||||||
headers.set(Location(host.to_string()));
|
headers.set(Location(host.to_string()));
|
||||||
|
|
||||||
|
@ -182,7 +173,6 @@ enum ResponseType {
|
||||||
RedirectWithHeaders(String, Headers),
|
RedirectWithHeaders(String, Headers),
|
||||||
Text(Vec<u8>),
|
Text(Vec<u8>),
|
||||||
WithHeaders(Vec<u8>, Headers),
|
WithHeaders(Vec<u8>, Headers),
|
||||||
NeedsAuth(Headers),
|
|
||||||
Dummy404
|
Dummy404
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,9 +197,6 @@ fn response_for_request_type(t: ResponseType) -> Result<MockResponse, LoadError>
|
||||||
ResponseType::WithHeaders(b, h) => {
|
ResponseType::WithHeaders(b, h) => {
|
||||||
Ok(respond_with_headers(b, h))
|
Ok(respond_with_headers(b, h))
|
||||||
},
|
},
|
||||||
ResponseType::NeedsAuth(h) => {
|
|
||||||
Ok(basic_auth(h))
|
|
||||||
},
|
|
||||||
ResponseType::Dummy404 => {
|
ResponseType::Dummy404 => {
|
||||||
Ok(respond_404())
|
Ok(respond_404())
|
||||||
}
|
}
|
||||||
|
@ -1509,37 +1496,28 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_auth_ui_needs_www_auth() {
|
fn test_auth_ui_needs_www_auth() {
|
||||||
let url = ServoUrl::parse("http://mozilla.com").unwrap();
|
let handler = move |_: HyperRequest, mut response: HyperResponse| {
|
||||||
let http_state = HttpState::new();
|
*response.status_mut() = StatusCode::Unauthorized;
|
||||||
struct AuthProvider;
|
response.send(b"").unwrap();
|
||||||
impl UIProvider for AuthProvider {
|
};
|
||||||
fn input_username_and_password(&self, _prompt: &str) -> (Option<String>, Option<String>) {
|
let (mut server, url) = make_server(handler);
|
||||||
panic!("shouldn't be invoked")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Factory;
|
let request = Request::from_init(RequestInit {
|
||||||
|
url: url.clone(),
|
||||||
|
method: Method::Get,
|
||||||
|
body: None,
|
||||||
|
destination: Destination::Document,
|
||||||
|
origin: url.clone(),
|
||||||
|
pipeline_id: Some(TEST_PIPELINE_ID),
|
||||||
|
credentials_mode: CredentialsMode::Include,
|
||||||
|
.. RequestInit::default()
|
||||||
|
});
|
||||||
|
|
||||||
impl HttpRequestFactory for Factory {
|
let response = fetch_sync(request, None);
|
||||||
type R = MockRequest;
|
|
||||||
|
|
||||||
fn create(&self, _: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
|
let _ = server.close();
|
||||||
Ok(MockRequest::new(ResponseType::NeedsAuth(Headers::new())))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
|
assert_eq!(response.status.unwrap(), StatusCode::Unauthorized);
|
||||||
|
|
||||||
let response = load(&load_data, &AuthProvider, &http_state,
|
|
||||||
None, &Factory, DEFAULT_USER_AGENT.into(),
|
|
||||||
&CancellationListener::new(None), None);
|
|
||||||
match response {
|
|
||||||
Err(e) => panic!("response contained error {:?}", e),
|
|
||||||
Ok(response) => {
|
|
||||||
assert_eq!(response.metadata.status,
|
|
||||||
Some((401, "Unauthorized".as_bytes().to_vec())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_referrer_header_matches(origin_info: &LoadOrigin,
|
fn assert_referrer_header_matches(origin_info: &LoadOrigin,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue