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

Remove test_auth_ui_sets_header_on_401.

The fetch stack does not yet support asking the user for credentials (#14305).
  • Loading branch information
Ms2ger committed Nov 23, 2016
commit 4c34e9aa89420fea91a0d4e5431479ccba6d9239
@@ -224,28 +224,6 @@ impl HttpRequest for MockRequest {
}
}

struct AssertAuthHeaderRequestFactory {
expected_headers: Headers,
body: Vec<u8>
}

impl HttpRequestFactory for AssertAuthHeaderRequestFactory {
type R = MockRequest;

fn create(&self, _: ServoUrl, _: Method, headers: Headers) -> Result<MockRequest, LoadError> {
let request = if headers.has::<Authorization<Basic>>() {
assert_headers_included(&self.expected_headers, &headers);
MockRequest::new(ResponseType::Text(self.body.clone()))
} else {
let mut headers = Headers::new();
headers.set_raw("WWW-Authenticate", vec![b"Basic realm=\"Test realm\"".to_vec()]);
MockRequest::new(ResponseType::NeedsAuth(headers))
};

Ok(request)
}
}

fn assert_headers_included(expected: &Headers, request: &Headers) {
assert!(expected.len() != 0);
for header in expected.iter() {
@@ -1529,39 +1507,6 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
assert!(response.status.unwrap().is_success());
}

#[test]
fn test_auth_ui_sets_header_on_401() {
let url = ServoUrl::parse("http://mozilla.com").unwrap();
let http_state = HttpState::new();
let ui_provider = TestProvider { username: "test".to_owned(), password: "test".to_owned() };

let mut auth_header = Headers::new();

auth_header.set(
Authorization(
Basic {
username: "test".to_owned(),
password: Some("test".to_owned())
}
)
);

let load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);

match load(
&load_data, &ui_provider, &http_state,
None, &AssertAuthHeaderRequestFactory {
expected_headers: auth_header,
body: <[_]>::to_vec(&[])
}, DEFAULT_USER_AGENT.into(), &CancellationListener::new(None), None) {
Err(e) => panic!("response contained error {:?}", e),
Ok(response) => {
assert_eq!(response.metadata.status,
Some((200, b"OK".to_vec())));
}
}
}

#[test]
fn test_auth_ui_needs_www_auth() {
let url = ServoUrl::parse("http://mozilla.com").unwrap();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.