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

Conversation

@cctechwiz
Copy link
Contributor

cctechwiz commented Oct 5, 2019

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

This comment has been minimized.

Copy link

CLAassistant commented Oct 5, 2019

CLA assistant check
All committers have signed the CLA.

cctechwiz added 2 commits Oct 5, 2019
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

This comment has been minimized.

Copy link
Contributor Author

cctechwiz commented Oct 6, 2019

@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

This comment has been minimized.

Copy link
Member

memsharded commented Oct 6, 2019

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

memsharded commented Oct 7, 2019

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

This comment has been minimized.

Copy link
Contributor Author

cctechwiz commented Oct 8, 2019

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.

…tories of the cache for testing
@cctechwiz

This comment has been minimized.

Copy link
Contributor Author

cctechwiz commented Oct 8, 2019

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

This comment has been minimized.

Copy link
Member

memsharded commented Oct 8, 2019

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

This comment has been minimized.

Copy link
Contributor Author

cctechwiz commented Oct 8, 2019

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

This comment has been minimized.

Copy link
Member

memsharded commented Oct 8, 2019

Did a PR to your branch in cctechwiz-forks#1, to rebase this to latest develop. Lets see if that fixes the CI. Thanks!

…tion

Feature/short paths home validation
@memsharded

This comment has been minimized.

Copy link
Member

memsharded commented Oct 9, 2019

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
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/jenkins/pr-head This commit cannot be built
Details
license/cla Contributor License Agreement is signed.
Details
@cctechwiz

This comment has been minimized.

Copy link
Contributor Author

cctechwiz commented Oct 9, 2019

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 cctechwiz-forks:feature/short_paths_home_validation branch Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.