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

test: Ensure we can read proxy params from environment #2407

Merged
merged 1 commit into from
Jul 13, 2020

Conversation

inejge
Copy link
Contributor

@inejge inejge commented Jul 9, 2020

Tests for:

  1. Correctly retrieving the proxy (host, port) tuple from $https_proxy or $HTTPS_PROXY

  2. Prioritizing $https_proxy over $HTTPS_PROXY

Using a mutex to serialize environment access in the test function is not strictly necessary as long as there are no other tests running in parallel, but makes it easier to extend testing if the need arises.

@inejge inejge force-pushed the master branch 2 times, most recently from d67b839 to eae405c Compare July 9, 2020 11:58
@inejge
Copy link
Contributor Author

inejge commented Jul 9, 2020

OK, slightly modified to deal with variable name case insensitivity on Windows. The reason for the macOS build failure is unclear to me.

@kinnison
Copy link
Contributor

kinnison commented Jul 9, 2020

That lock is only ever used in that test, so I'm not sure how useful it is. Better would be to ensure we restore the environment after with a guard like the ones used in the integration tests, or else for env_proxy to have a way to be used where it uses provided environment values rather than reading the system env (like we're trying to do for home).

The restoration is important otherwise this will probably mess up developer boxes which set environment variables for proxying on Windows.

@inejge
Copy link
Contributor Author

inejge commented Jul 9, 2020

That lock is only ever used in that test, so I'm not sure how useful it is

No objection there, it can be removed.

Better would be to ensure we restore the environment after with a guard like the ones used in the integration tests

Those guards restore PATH by changing it through registry operations, not by using env::{set,remove}_var(). The proxy environment test shouldn't affect either the command shell which invoked it, or the user's session.

@kinnison
Copy link
Contributor

kinnison commented Jul 9, 2020

Aha, I'm a little sensitive about environment variables in Windows as you might imagine :D Okay. (The macos failure was a GHA bogon btw)

@kinnison kinnison requested a review from rbtcollins July 9, 2020 22:52
set_var("HTTPS_PROXY", "http://proxy2.example.com:8080");
let u = Url::parse("https://www.example.org").ok().unwrap();
assert_eq!(
for_url(&u).host_port(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using the env_proxy function directly: I guess thats what broke, so we probably need to, but its a bit of a shame to be testing our dependencies :(. I haven't looked but if we wrap things up in higher order things maybe those should be checked instead/too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the antecedents of #2399, it should be clear that env_proxy's own logging and tests did detect the breakage, but it wouldn't have helped here; the even higher order problem stemmed from my failure to publish the updated version in a timely manner.

I agree that a higher-level test would be architecturally cleaner, and could imagine spinning up a separate micro-proxy thread (could it be backed by hyper? Probably) and attempting to fetch a file through that. In any case, proxies are an important enough use case for rustup that I believe that they should be tested for in some manner.

@@ -0,0 +1,50 @@
#![cfg(feature = "reqwest-backend")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this bug only affect one backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, cURL has its own proxy detection logic (which env_proxy emulates).

@@ -0,0 +1,50 @@
#![cfg(feature = "reqwest-backend")]

Copy link
Contributor

@rbtcollins rbtcollins Jul 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separately, this is going to make a separate integration test binary; rather than a unit test. I think this is ok for now, but having it in a larger compilation unit would help prevent proliferation, but we'll need to integrate in with currentprocess() to do that - I haven't looked at env_proxy to see whats involved there.

An alternative approach would be to have a helper that will always be isolated (like this is), but simpler: don't scrub the environment or anything; just print host_port() to stdout; then when we run this helper binary, we can set the environment, allowing us to run different scenarios.

But I don't think we need that approach yet, since what we're doing here is really just a smoke test.

use url::Url;

lazy_static! {
static ref LOCK: Mutex<()> = Mutex::new(());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the lock is of any use right now - we have one and only one test, in one test script, and nothing else is consulting it, so it isn't going to lock anything out: just ditch it.


// Tests for:
// 1. Correctly retrieving the proxy (host, port) tuple from $https_proxy or $HTTPS_PROXY
// 2. Prioritizing $https_proxy over $HTTPS_PROXY (except on Windows, where env vars
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think point 2 is interesting: this is very much in the space of 'checking env_proxy internals' : the point of this test is to make sure that urls hooks <-> env_proxy are setup properly in case of future dependency skew issues, not to test the definition of env-proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, just checking https_proxy is probably enough.

@inejge
Copy link
Contributor Author

inejge commented Jul 10, 2020

To summarize, the way forward (in the near term, for this PR) would be to: a) remove locking, b) limit the test to $http_proxy. I'd prefer doing it in a force push. Is that on the right track?

@kinnison
Copy link
Contributor

To summarize, the way forward (in the near term, for this PR) would be to: a) remove locking, b) limit the test to $http_proxy. I'd prefer doing it in a force push. Is that on the right track?

In general, it's easier to review changes-in-response-to-review if you push new commits to do the change, though if you and @rbtcollins are in agreement on the way forward then jumping immediately to a force-push is fine.

I definitely prefer that a PR be rebased to be clean commits before merging though.

@inejge
Copy link
Contributor Author

inejge commented Jul 10, 2020

Right, here is the updated test as an additional commit, then.

@rbtcollins
Copy link
Contributor

LGTM, please squash into a single logical commit to prep for merging

Tests for correctly retrieving the proxy (host, port) tuple from
$https_proxy by directly calling env_proxy::for_url()
@inejge
Copy link
Contributor Author

inejge commented Jul 13, 2020

Rebased and force-pushed.

@rbtcollins rbtcollins merged commit a797355 into rust-lang:master Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants