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

Update basic auth cache to key off of origin instead of url #13281

Merged
merged 4 commits into from Sep 16, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -827,7 +827,7 @@ fn http_network_or_cache_fetch(request: Rc<Request>,
let mut authorization_value = None;

// Substep 4
if let Some(basic) = auth_from_cache(&context.state.auth_cache, &current_url) {
if let Some(basic) = auth_from_cache(&context.state.auth_cache, &current_url.origin()) {
if !http_request.use_url_credentials || !has_credentials(&current_url) {
authorization_value = Some(basic);
}
@@ -52,7 +52,7 @@ use time;
use time::Tm;
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
use tinyfiledialogs;
use url::{Position, Url};
use url::{Position, Url, Origin};
use util::prefs::PREFS;
use util::thread::spawn_named;
use uuid;
@@ -688,15 +688,15 @@ fn set_auth_header(headers: &mut Headers,
if let Some(auth) = auth_from_url(url) {
headers.set(auth);
} else {
if let Some(basic) = auth_from_cache(auth_cache, url) {
if let Some(basic) = auth_from_cache(auth_cache, &url.origin()) {
headers.set(Authorization(basic));
}
}
}
}

pub fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, url: &Url) -> Option<Basic> {
if let Some(ref auth_entry) = auth_cache.read().unwrap().entries.get(url) {
pub fn auth_from_cache(auth_cache: &Arc<RwLock<AuthCache>>, origin: &Origin) -> Option<Basic> {
if let Some(ref auth_entry) = auth_cache.read().unwrap().entries.get(&origin.ascii_serialization()) {
let user_name = auth_entry.user_name.clone();
let password = Some(auth_entry.password.clone());
Some(Basic { username: user_name, password: password })
@@ -1017,13 +1017,15 @@ pub fn load<A, B>(load_data: &LoadData,
new_auth_header = None;

if let Some(auth_header) = request_headers.get::<Authorization<Basic>>() {
if response.status().class() == StatusClass::Success {
if response.status().class() == StatusClass::Success ||
response.status().class() == StatusClass::Redirection {
let auth_entry = AuthCacheEntry {
user_name: auth_header.username.to_owned(),
password: auth_header.password.to_owned().unwrap(),
};

http_state.auth_cache.write().unwrap().entries.insert(doc_url.clone(), auth_entry);
let serialized_origin = doc_url.origin().ascii_serialization();
http_state.auth_cache.write().unwrap().entries.insert(serialized_origin, auth_entry);
}
}

@@ -466,7 +466,7 @@ impl AuthCache {
#[derive(RustcDecodable, RustcEncodable, Clone)]
pub struct AuthCache {
pub version: u32,
pub entries: HashMap<Url, AuthCacheEntry>,
pub entries: HashMap<String, AuthCacheEntry>,
}

pub struct CoreResourceManager {
@@ -1533,7 +1533,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
password: "test".to_owned(),
};

http_state.auth_cache.write().unwrap().entries.insert(url.clone(), auth_entry);
http_state.auth_cache.write().unwrap().entries.insert(url.origin().clone().ascii_serialization(), auth_entry);

let mut load_data = LoadData::new(LoadContext::Browsing, url, &HttpTest);
load_data.credentials_flag = true;
"deleted": [],
"deleted_reftests": {},
"items": {
"reftest": {
"http/basic-auth-cache-test.html": [
{
"path": "http/basic-auth-cache-test.html",
"references": [
[
"/http/basic-auth-cache-test-ref.html",
"=="
]
],
"url": "/http/basic-auth-cache-test.html"
}
]
},
"testharness": {
"dom/lists/DOMTokenList-Iterable.html": [
{
]
}
},
"reftest_nodes": {}
"reftest_nodes": {
"http/basic-auth-cache-test.html": [
{
"path": "http/basic-auth-cache-test.html",
"references": [
[
"/http/basic-auth-cache-test-ref.html",
"=="
]
],
"url": "/http/basic-auth-cache-test.html"
}
]
}
},
"reftest_nodes": {
"2dcontext/building-paths/canvas_complexshapes_arcto_001.htm": [
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>

<img src="resources/image.png">
<img src="resources/image.png">
</html>
@@ -0,0 +1,30 @@
<!doctype html>
<html id="doc" class="reftest-wait">
<head>
<meta charset="utf-8">
</head>

<link rel="match" href="basic-auth-cache-test-ref.html">

<img id="auth" onload="loadNoAuth()">
<img id="noauth" onload="removeWait()">


<script type="text/javascript">
function loadAuth() {
var authUrl = 'http://testuser:testpass@' + window.location.host + '/http/resources/securedimage.py';
document.getElementById('auth').src = authUrl;
}

function loadNoAuth() {
var noAuthUrl = 'http://' + window.location.host + '/http/resources/securedimage.py';
document.getElementById('noauth').src = noAuthUrl;
}

function removeWait() {
document.getElementById('doc').className = "";
}

window.onload = loadAuth;
</script>
</html>
Binary file not shown.
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -

def main(request, response):
image_url = str.replace(request.url, "securedimage.py", "image.png")

if "authorization" not in request.headers:
response.status = 401
response.headers.set("WWW-Authenticate", "Basic")
return response
else:
auth = request.headers.get("Authorization")
if auth != "Basic dGVzdHVzZXI6dGVzdHBhc3M=":
response.set_error(403, "Invalid username or password - " + auth)
return response

response.status = 301
response.headers.set("Location", image_url)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.