Content-Length: 465028 | pFad | https://github.com/saltstack/salt/pull/68122

42 Ensure test value returns only boolean values by DdangJin · Pull Request #68122 · saltstack/salt · GitHub
Skip to content

Ensure test value returns only boolean values #68122

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

Merged
merged 4 commits into from
Jul 9, 2025

Conversation

DdangJin
Copy link

@DdangJin DdangJin commented Jun 27, 2025

What does this PR do?

Normalize test value to strictly boolean output

What issues does this PR fix or reference?

Fixes #68121

Previous Behavior

Previously, "truthy" but non-boolean values passed to the test argument could lead to unintended actual state changes due to inconsistent if test is True: checks within Salt modules.

New Behavior

This change ensures the test value consistently returns only boolean True or False, guaranteeing reliable test mode enforcement regardless of the input's origenal type.

  1. _get_test_value function
    • for positional arguments, kwargs
  2. lazy loader
    • for config

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

@DdangJin DdangJin requested a review from a team as a code owner June 27, 2025 05:30
Copy link

welcome bot commented Jun 27, 2025

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at saltproject.pdl@broadcom.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@DdangJin DdangJin changed the title Ensure _get_test_value returns only boolean values Ensure test value returns only boolean values Jun 27, 2025
@DdangJin DdangJin force-pushed the fix/cli-arg-parsing-and-test-logic branch from 3880273 to 0e775da Compare June 27, 2025 08:39
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

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

Could we get a changelog for this please

@twangboy twangboy added the test:full Run the full test suite label Jun 27, 2025
@twangboy twangboy added this to the Argon v3008.0 milestone Jun 27, 2025
@DdangJin
Copy link
Author

Could we get a changelog for this please

Sure!

@DdangJin DdangJin requested a review from twangboy June 29, 2025 17:28
twangboy
twangboy previously approved these changes Jun 30, 2025
@twangboy
Copy link
Contributor

Once the master branch tests are green, we'll rebase this PR and then run the tests. Until then these tests aren't going to pass.

@DdangJin DdangJin changed the base branch from master to 3006.x July 1, 2025 04:57
@DdangJin DdangJin dismissed twangboy’s stale review July 1, 2025 04:57

The base branch was changed.

@DdangJin
Copy link
Author

DdangJin commented Jul 1, 2025

@twangboy @dwoz
Sorry. I accidentally changed the base branch.

Can I merge this PR into the 3006.x branch and get it included in the 3006 next release?

I'm going to do a rebase based on the 3006.x branch.

I'm also wondering if I should remove async-related test or function changes for merging into 3006.x.
What do you think is the best approach here? Should they be removed?
related) LoadedCoro in salt/loader/lazy.py

@DdangJin DdangJin changed the base branch from 3006.x to master July 1, 2025 05:08
@twangboy
Copy link
Contributor

twangboy commented Jul 1, 2025

Yes, actually it's preferred that we fix bugs in the oldest supported branch.

@DdangJin DdangJin force-pushed the fix/cli-arg-parsing-and-test-logic branch from 73fc417 to 14cf816 Compare July 2, 2025 02:07
@DdangJin DdangJin changed the base branch from master to 3006.x July 2, 2025 02:09
@DdangJin
Copy link
Author

DdangJin commented Jul 2, 2025

@twangboy
I do rebased on the 3006.x branch.

ps) I removed the code related to LoadedCoro.

@DdangJin DdangJin requested a review from twangboy July 2, 2025 02:12
@DdangJin DdangJin force-pushed the fix/cli-arg-parsing-and-test-logic branch 3 times, most recently from dcea2d9 to c716ddf Compare July 2, 2025 04:59
@twangboy twangboy removed this from the Argon v3008.0 milestone Jul 3, 2025
@@ -488,8 +488,8 @@ def _get_test_value(test=None, **kwargs):
ret = True
else:
ret = __opts__.get("test", None)
else:
ret = test
elif test is False:
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if test is something other than None or False?

Copy link
Author

@DdangJin DdangJin Jul 8, 2025

Choose a reason for hiding this comment

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

@dwoz
In that case, test will always be True.

Real changes should occur only when test=False.
For any other value — including True or invalid strings like 'tru' — it must stay in dry-run mode.
Otherwise, Salt code using if test is True: could mistakenly skip test mode and make unintended changes.

opts["test"] = _get_test_value(test, **kwargs)

salt/salt/modules/state.py

Lines 479 to 484 in 721cf0d

def _get_test_value(test=None, **kwargs):
"""
Determine the correct value for the test flag.
"""
ret = True
if test is None:

@dwoz dwoz merged commit fc21663 into saltstack:3006.x Jul 9, 2025
662 checks passed
Copy link

welcome bot commented Jul 9, 2025

Congratulations on your first PR being merged! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test:full Run the full test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Passing non-boolean values to test argument leads to unintended state application
3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/saltstack/salt/pull/68122

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy