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

add auth cache to resources + set auth header from it if url does not have creds #10111

Merged
merged 1 commit into from Mar 24, 2016
Merged

Conversation

ddefisher
Copy link
Contributor

initial attempt of

  • in resource_thread.rs, define an HTTP authorization cache storage (username, password, URL) and instantiate it like the cookie_storage member (inside an Arc<Rwlock<>> value, to enable sharing it between threads)

  • in modify_request_headers in http_loader.rs, implement the remaining pieces of step 12(13?) of the appropriate specification using this new authorization cache.

    for the NCSU student project Implement HTTP authorization UI and persistent sessions.


This change is Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 22, 2016
@highfive
Copy link

warning Warning warning

  • These commits modify net code, but no tests are modified. Please consider adding a test!

@jdm
Copy link
Member

jdm commented Mar 22, 2016

This is a great start! Please be sure to:

  • run ./mach test-tidy and fix the stylistic errors that it reports
  • run ./mach test-unit -p net and fix the build errors that it reports

The biggest issue to address here is that the cache needs to support more than a single entry. We actually want a hashmap of serialized URLs to username/password credentials, so we can easily determine if we have stored credentials for a given URL or not. Additionally, we should write a unit test that demonstrates that this new code works as expected - the ones in tests/unit/net/http_loader.rs can be used as a model here.

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-fails-tidy `./mach test-tidy` reported errors. S-needs-tests New tests have been requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 22, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 23, 2016
@ddefisher
Copy link
Contributor Author

Still need to fix the http_loader unit test stuff(it's failing because a lot of functions argument number increased by 1) as well as add a test. Hoping I could get some comments if I am on the right track on the other stuff though. Thanks!

@jdm
Copy link
Member

jdm commented Mar 23, 2016

Definitely on the right track!
-S-awaiting-review +S-needs-code-changes


Reviewed 2 of 2 files at r2.
Review status: all files reviewed at latest revision, 8 unresolved discussions, some commit checks failed.


components/net/http_loader.rs, line 558 [r2] (raw file):
nit: please remove this newline.


components/net/http_loader.rs, line 560 [r2] (raw file):
nit: please remove this newline.


components/net/http_loader.rs, line 563 [r2] (raw file):
nit: } else {


components/net/http_loader.rs, line 564 [r2] (raw file):
nit: please remove this newline.


components/net/http_loader.rs, line 565 [r2] (raw file):
I think this is clearer as:

if let Some(ref auth_entry) = auth_cache.read().unwrap().get(url) {
    auth_from_entry(&auth_entry, headers);
}

components/net/http_loader.rs, line 573 [r2] (raw file):
nit: remove the space before (


components/net/http_loader.rs, line 577 [r2] (raw file):
No need for if let here.

headers.set(Authorization(Basic { username: user_name, password: password }));

components/net/resource_thread.rs, line 277 [r2] (raw file):
Let's remove it if there aren't any methods.


Comments from the review on Reviewable.io

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 23, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 23, 2016
@jdm
Copy link
Member

jdm commented Mar 24, 2016

Great work! Still looking for a unit test that shows the changes working, and ./mach test-tidy is failing again.
-S-awaiting-review


Reviewed 3 of 3 files at r3.
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from the review on Reviewable.io

@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Mar 24, 2016
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 24, 2016
@ddefisher
Copy link
Contributor Author

added a unit test and tidied up

@jdm
Copy link
Member

jdm commented Mar 24, 2016

Great! There are a couple small changes left, but you can squash everything together once they're complete.
-S-fails-tidy -S-needs-tests -S-awaiting-review +S-needs-code-changes +S-needs-squash


Reviewed 2 of 2 files at r4.
Review status: all files reviewed at latest revision, 4 unresolved discussions.


components/net/resource_thread.rs, line 277 [r4] (raw file):
I don't think this constructor is particularly useful. Let's remove it.


tests/unit/net/http_loader.rs, line 1486 [r4] (raw file):
Let's just use this instead:

AuthCacheEntry {
    user_name: "username".to_owned(),
    password: "test".to_owned(),
}

tests/unit/net/http_loader.rs, line 1492 [r4] (raw file):
No need for this clone.


tests/unit/net/http_loader.rs, line 1494 [r4] (raw file):
These are the default values of data and method so we can remove those lines.


Comments from the review on Reviewable.io

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-fails-tidy `./mach test-tidy` reported errors. S-needs-tests New tests have been requested by a reviewer. S-awaiting-review There is new code that needs to be reviewed. labels Mar 24, 2016
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 24, 2016
@jdm
Copy link
Member

jdm commented Mar 24, 2016

@bors-servo: r+
Thanks!


Reviewed 2 of 2 files at r5.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from the review on Reviewable.io

@bors-servo
Copy link
Contributor

📌 Commit d49d3b0 has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-squash Some (or all) of the commits in the PR should be combined. labels Mar 24, 2016
@bors-servo
Copy link
Contributor

⌛ Testing commit d49d3b0 with merge 7f944af...

bors-servo pushed a commit that referenced this pull request Mar 24, 2016
add auth cache to resources + set auth header from it if url does not have creds

initial attempt of

- in resource_thread.rs, define an HTTP authorization cache storage (username, password, URL) and instantiate it like the cookie_storage member (inside an Arc<Rwlock<>> value, to enable sharing it between threads)
- in modify_request_headers in http_loader.rs, implement the remaining pieces of step 12(13?) of the appropriate specification using this new authorization cache.

 for the NCSU student project Implement HTTP authorization UI and persistent sessions.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10111)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, gonk, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, status-appveyor

@bors-servo bors-servo merged commit d49d3b0 into servo:master Mar 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants