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

ipatests: Check maxlife error message where minlife > maxlife specified #6098

Closed
wants to merge 1 commit into from

Conversation

mrizwan93
Copy link
Contributor

When minlife > maxlife specified on commandline, it says:
"ipa: ERROR: invalid 'maxlife': Maximum password life must be
greater than minimum."

But when minlife == maxlife specfied, It works.
This test check that error message says what exactly it does.

related: https://pagure.io/freeipa/issue/9038

Signed-off-by: Mohammad Rizwan myusuf@redhat.com

@mrizwan93 mrizwan93 added the WIP Work in progress - not ready yet for review label Nov 22, 2021
@mrizwan93
Copy link
Contributor Author

depends on #6086

@mrizwan93 mrizwan93 added ipa-4-9 Mark for backport to ipa 4.9 and removed WIP Work in progress - not ready yet for review labels Nov 22, 2021
@mrizwan93 mrizwan93 added the needs review Pull Request is waiting for a review label Nov 22, 2021
@@ -261,3 +261,35 @@ def test_minlength_add(self):
)
assert result.returncode != 0
assert 'minlength' in result.stderr_text

def test_maxlife(self):
"""Check maxlife error message where minlife > maxlife specified
Copy link
Contributor

Choose a reason for hiding this comment

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

If its checking only error text then i would suggest you to add this test
in test_xmlrpc/test_pwpolicy_plugin.py

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to that suggestion. Integration tests are much slower.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines 183 to 187
try:
entry = api.Command['pwpolicy_mod'](krbminpwdlife=25,
krbmaxpwdlife=1)['result']
except errors.ValidationError as e:
assert ("Maximum password life must be equal to "
"or greater than the minimum.") in str(e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

let me rephrase myself.
if this is an expected exception then it should be raised always. Currently, the test assumes that the exception is optional. For example, try except else construction or Pytest's pytest.raises (the link above) can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed your point :)
Updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

example:

with pytest.raises(errors.OptionError) as e:
self.run_plugins(
nonexistentoption="nonexistentoption", server=server
)
assert "Unknown option: nonexistentoption" in str(e.value)

@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 2 times, most recently from e5c9396 to b8224fe Compare December 1, 2021 09:45
@mrizwan93
Copy link
Contributor Author

@stanislavlevin @rcritten Could you look at this please?

@stanislavlevin
Copy link
Contributor

Hi, @mrizwan93.

  • I think it's a good idea to extend your tests to check validate_lifetime of ipaserver/plugins/pwpolicy.py, not only the one case (pwpolicy_mod). pwpolicy_add is affected as well
  • validate_lifetime for pwpolicy_mod has additional conditions. Please, cover them with tests.

@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 9 times, most recently from 4994191 to 5b1ed80 Compare February 1, 2022 13:34
@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 2 times, most recently from 5848671 to f8d4bee Compare February 15, 2022 04:23
@mrizwan93
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mrizwan93
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 7 times, most recently from a620feb to 9939cca Compare February 23, 2022 13:31
Copy link
Contributor

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Hi @mrizwan93
please find an inline comment


# when minlife is -1
pwpolicy_cmd('pwpolicy_mod', -1)
pwpolicy_cmd('pwpolicy_add', -1, test_group101, pwpolicyadd=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

The cospriority argument is missing: the method expects cmd, minlife, cospriority=None, pwpolicy_group=None, pwpolicyadd=False.

@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 2 times, most recently from 5519ca8 to eb75cf2 Compare March 11, 2022 06:01
@@ -186,28 +282,32 @@ def test_b_pwpolicy_add(self):
def test_c_pwpolicy_find(self):
"""Test that password policies are sorted and reported properly"""
result = api.Command['pwpolicy_find']()['result']
assert len(result) == 4
assert len(result) == 6
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of modifying test_c_pwpolicy_find and test_c_pwpolicy_find_pkey_only because there are additional policies, you can simply delete the pwpolicies created in test_maxlife_pwpolicy at the end of test_maxlife_pwpolicy.

@@ -31,6 +31,49 @@
Declarative)


def pwpolicy_cmd(
cmd, minlife, cospriority=None,
pwpolicy_group=None, pwpolicyadd=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

The method arguments are redundant: there is no need for pwpolicyadd=True/False as the cmd arg already defines either add or mod. I would remove the pwpolicyadd arg and replace if pwpolicyadd: with if cmd == "pwpolicy_add":

def pwpolicy_cmd(
cmd, minlife, cospriority=None,
pwpolicy_group=None, pwpolicyadd=False):
if pwpolicyadd:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a method docstring: either create a new pwpolicy with max life = 1 day or modify the existing global pwpolicy.

@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 2 times, most recently from dee6722 to 8edfeb6 Compare March 14, 2022 09:43
Copy link
Contributor

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Hi @mrizwan93
I only have minor nitpicks, please find them inline.

"""Helper method to add or modify the password policy

:param cmd: Either pwpolicy_add or pwpolicy_mod
:pram minlife: minimum life for the password to exist
Copy link
Contributor

Choose a reason for hiding this comment

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

typo pram
minlife: The minimum amount of time (in hours) that must pass between two password change operations.

cmd, minlife, cospriority=None,
pwpolicy_group=None):
"""Helper method to add or modify the password policy

Copy link
Contributor

Choose a reason for hiding this comment

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

The add method harcodes the max life to 1 day.

@mrizwan93 mrizwan93 force-pushed the maxlife-test-6086 branch 2 times, most recently from d6e8f46 to cc61243 Compare March 15, 2022 09:52
When minlife > maxlife specified on commandline, it says:
"ipa: ERROR: invalid 'maxlife': Maximum password life must be
greater than minimum."

But when minlife == maxlife specfied, It works.
This test check that error message says what exactly it does

related: https://pagure.io/freeipa/issue/9038

Signed-off-by: Mohammad Rizwan <myusuf@redhat.com>
@mrizwan93
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@flo-renaud flo-renaud added ack Pull Request approved, can be merged and removed needs review Pull Request is waiting for a review labels Mar 15, 2022
@abbra abbra added the pushed Pull Request has already been pushed label Mar 16, 2022
@abbra
Copy link
Contributor

abbra commented Mar 16, 2022

master:

  • 5a909cf ipatests: Check maxlife error message where minlife > maxlife specified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged ipa-4-9 Mark for backport to ipa 4.9 pushed Pull Request has already been pushed
Projects
None yet
7 participants