Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite and remove most unit tests for the legacy fetch stack. #14315

Merged
merged 14 commits into from Nov 24, 2016

Rewrite test_auth_ui_needs_www_auth.

  • Loading branch information
Ms2ger committed Nov 23, 2016
commit a8f7f3c1db4b6992a8364a5f621a589be743df0d
@@ -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 {
headers.set(Location(host.to_string()));

@@ -182,7 +173,6 @@ enum ResponseType {
RedirectWithHeaders(String, Headers),
Text(Vec<u8>),
WithHeaders(Vec<u8>, Headers),
NeedsAuth(Headers),
Dummy404
}

@@ -207,9 +197,6 @@ fn response_for_request_type(t: ResponseType) -> Result<MockResponse, LoadError>
ResponseType::WithHeaders(b, h) => {
Ok(respond_with_headers(b, h))
},
ResponseType::NeedsAuth(h) => {
Ok(basic_auth(h))
},
ResponseType::Dummy404 => {
Ok(respond_404())
}
@@ -1509,37 +1496,28 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {

#[test]
fn test_auth_ui_needs_www_auth() {
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
struct AuthProvider;
impl UIProvider for AuthProvider {
fn input_username_and_password(&self, _prompt: &str) -> (Option<String>, Option<String>) {
panic!("shouldn't be invoked")
}
}

struct Factory;
let handler = move |_: HyperRequest, mut response: HyperResponse| {
*response.status_mut() = StatusCode::Unauthorized;
response.send(b"").unwrap();
};
let (mut server, url) = make_server(handler);

impl HttpRequestFactory for Factory {
type R = MockRequest;
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()
});

fn create(&self, _: ServoUrl, _: Method, _: Headers) -> Result<MockRequest, LoadError> {
Ok(MockRequest::new(ResponseType::NeedsAuth(Headers::new())))
}
}
let response = fetch_sync(request, None);

let load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
let _ = server.close();

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())));
}
}
assert_eq!(response.status.unwrap(), StatusCode::Unauthorized);
}

fn assert_referrer_header_matches(origin_info: &LoadOrigin,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.