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

Validates that short_paths_home is not equal to, or a subdirectory of… #5864

Merged
merged 10 commits into from Oct 9, 2019
Merged

Validates that short_paths_home is not equal to, or a subdirectory of… #5864

merged 10 commits into from Oct 9, 2019

Conversation

cctechwiz
Copy link
Contributor

Changelog: Bugfix: Adds the short_paths_home property to ConanClientConfigParser to validate that it is not a subdirectory of the conan cache.

Docs: conan-io/docs#1436

Fixes #5755

  • Refer to the issue that supports this Pull Request.
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.

@CLAassistant
Copy link

CLAassistant commented Oct 5, 2019

CLA assistant check
All committers have signed the CLA.

This is an OK case, because we are just trying to validate that short_paths_home is not a subdirectory of the conan cache directory.
If they are on separate drives then that validity condition is satisfied.
Changed function call from commonpath to commonprefix to support use on both python2 and python3

commonprefix does not raise an error if the root drives are not the same so that logic was removed.
@cctechwiz
Copy link
Contributor Author

@memsharded Can I get some guidance here? It seems like the test that is failing now is "failing correctly" according to the behavior this PR is trying to fix. Any suggestions for modifying the test to still perform the original intent but not flag the new exception logic?

@memsharded
Copy link
Member

Hi @cctechwiz

Yes, you are right, the test is failing correctly now. In fact that test shouldn't be there in the first place, it reads weird that allows that. I think you can take advantage of it and change the test to cover the functionality you are implementing. Try changing the test to something like:

    def test_config_home_short_home_dir(self):
        cache_folder = os.path.join(temp_folder(), "custom")
        with environment_append({"CONAN_USER_HOME_SHORT": cache_folder}):
            client = TestClient(cache_folder=cache_folder)
            client.run("config home", assert_error=True)
            self.assertIn("cannot be a subdirectory of the conan cache", client.out)

@memsharded memsharded added this to the 1.20 milestone Oct 6, 2019
@memsharded memsharded self-assigned this Oct 6, 2019
@cctechwiz
Copy link
Contributor Author

cctechwiz commented Oct 6, 2019

Probably a dumb question, but how do I run the tests locally? I'm not super familiar with python unit testing.


Oh geez, nevermind. That's what I get for not remember what I read in the README.

…e cannot be a subdirectory of the conan cache
@memsharded
Copy link
Member

Yes, in the Readme.

I have check the jenkins logs, and I am sorry what I proposed is not right. As the exception is being launched earlier, it would be necessary to catch the exception. I'd suggest something in the line of:

    def test_config_home_short_home_dir(self):
        cache_folder = os.path.join(temp_folder(), "custom")
        with environment_append({"CONAN_USER_HOME_SHORT": cache_folder}):
            with six.assertRaisesRegex(self, ConanException,
                                       "cannot be a subdirectory of the conan cache"):
                client = TestClient(cache_folder=cache_folder)

remember to import six and ConanException. Sorry I am not testing it, just writing it on the fly.

@cctechwiz
Copy link
Contributor Author

Thank you. I should have caught that. I am having some issues running the tests because it can't find my c++ compiler. I'm debugging that, so in the mean time I figured I would just let Jenkins run the tests for me.

@cctechwiz
Copy link
Contributor Author

Ok @memsharded I'm stumped again. Thanks to your advise I was able to resolve the initial failing test. I found a few other test that were failing and modified them so that the cache dir and short paths dir were different which allowed them to pass.

However, I am unable to make any connection between my changes and the test that is failing now.

Here's the excerpt from the Jenkins log:

======================================================================

FAIL: environment_deactivate_test (disabled_revisions.conans.test.functional.generators.virtualbuildenv_test.VirtualBuildEnvTest)

----------------------------------------------------------------------

Traceback (most recent call last):

  File "D:\J\t\source\c98a\py36\disabled_revisions\conans\test\functional\generators\virtualbuildenv_test.py", line 76, in environment_deactivate_test

    self.assertEqual(normal_environment, deactivate_environment)

AssertionError: {'ALL[595 chars]ry of.', 'CHANGE_URL': 'https://github.com/con[4841 chars]P$G'} != {'ALL[595 chars]ry of…', 'CHANGE_URL': 'https://github.com/con[4841 chars]P$G'}

Diff is 6454 characters long. Set self.maxDiff to None to see it.

Thanks again for all your help.

@memsharded
Copy link
Member

I am having a look at this, not sure what it is, could be a glitch in CI (locally the test pass on my laptop). Relaunching CI.

Don't worry about this, the PR is good, we'll manage. Thanks for your contribution!

@cctechwiz
Copy link
Contributor Author

OK that's good to hear. Thank you for all your help.

I was thinking that I should probably add one more test, similar to the one that throws an exception, but that uses different paths for short paths and the cache. This would test that the config files are actually written into the short path home. Would that be useful?

@memsharded
Copy link
Member

Did a PR to your branch in https://github.com/cctechwiz-forks/conan/pull/1, to rebase this to latest develop. Lets see if that fixes the CI. Thanks!

…tion

Feature/short paths home validation
@memsharded
Copy link
Member

Ok, this is crazy, but this PR is identical to mine, and this fails, while mine is passing. Some glitch in the system is biting us. I am merging this even if CI is red, so you get the Hacktober fest attribution, and lets see what happens once merged in develop 😅

Thanks again!

@memsharded memsharded merged commit 43181ac into conan-io:develop Oct 9, 2019
@cctechwiz
Copy link
Contributor Author

Awesome! Thank you for all your help. It has been a pleasure working with you. I look forward to making more contributions to conan.

@cctechwiz cctechwiz deleted the feature/short_paths_home_validation branch October 9, 2019 13:43
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.

[Feature request] Can we WARN when a user changes user_home_short to same as path?
3 participants