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

Fixed/improved regular expresssion for collection names #73577

Merged
merged 3 commits into from Mar 1, 2021
Merged

Fixed/improved regular expresssion for collection names #73577

merged 3 commits into from Mar 1, 2021

Conversation

russoz
Copy link
Contributor

@russoz russoz commented Feb 11, 2021

SUMMARY

The regexp to determine a collection name in schema.py:

COLLECTION_NAME_RE = re.compile('^([^.]+.[^.]+)$')

has two bugs: a) it does not protect the dot between names, allowing things like community#general or community%general or even communitygeneral to be validated, when they shouldn't, and b) it fails to validate namespaces with deeper directory structures.

While investigating this, simplified a regexp in lib/ansible/utils/collection_loader/_collection_finder.py as well

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/utils/collection_loader/_collection_finder.py
test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/schema.py

@ansibot ansibot added affects_2.11 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Feb 11, 2021
@sivel
Copy link
Member

sivel commented Feb 11, 2021

Related #73279

Copy link
Contributor

@samdoran samdoran left a comment

Choose a reason for hiding this comment

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

This change looks correct at first glance, but it needs tests and a changelog fragment. See this fragment as an example.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Feb 17, 2021
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Feb 17, 2021
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. support:community This issue/PR relates to code supported by the Ansible community. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. small_patch core_review In order to be merged, this PR must follow the core review workflow. labels Feb 21, 2021
@russoz
Copy link
Contributor Author

russoz commented Feb 21, 2021

@samdoran changelog fragment added.

Copy link
Contributor

@samdoran samdoran left a comment

Choose a reason for hiding this comment

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

The changelog looks good. Can you please add some more tests cases to the existing unit tests?

('ns1.coll2', True),
('def.coll3', False),
('ns4.return', False),
('assert.this', False),
('import.that', False),
('.that', False),
('this.', False),
('.', False),
('', False),
),
)
def test_fqcn_validation(fqcn, expected):

('no_dots_at_all_action', 'action', ValueError, 'is not a valid collection reference'),
('no_nscoll.myaction', 'action', ValueError, 'is not a valid collection reference'),
('ns.coll.myaction', 'bogus', ValueError, 'invalid collection ref_type'),
])
def test_fqcr_parsing_invalid(ref, ref_type, expected_error_type, expected_error_expression):

@russoz
Copy link
Contributor Author

russoz commented Feb 28, 2021

I love the smell of rebase in the morning

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. labels Feb 28, 2021
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 28, 2021
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Feb 28, 2021
@russoz
Copy link
Contributor Author

russoz commented Mar 1, 2021

@samdoran added a couple of lines to the test data - not a big change so not much to add there.

@samdoran samdoran merged commit 920b68f into ansible:devel Mar 1, 2021
@russoz russoz deleted the coll-regex branch March 2, 2021 12:41
@ansible ansible locked and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.11 bug This issue/PR relates to a bug. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants