-
Notifications
You must be signed in to change notification settings - Fork 332
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
Conversation
depends on #6086 |
1fe6803
to
cb585e5
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
cb585e5
to
80637c9
Compare
5ea4bc9
to
0f6d4a3
Compare
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it an expected mandatory exception?
https://docs.pytest.org/en/latest/how-to/assert.html#assertions-about-expected-exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed your point :)
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example:
freeipa/ipatests/test_xmlrpc/test_plugins_plugin.py
Lines 56 to 60 in 637412a
with pytest.raises(errors.OptionError) as e: | |
self.run_plugins( | |
nonexistentoption="nonexistentoption", server=server | |
) | |
assert "Unknown option: nonexistentoption" in str(e.value) |
e5c9396
to
b8224fe
Compare
@stanislavlevin @rcritten Could you look at this please? |
Hi, @mrizwan93.
|
4994191
to
5b1ed80
Compare
5848671
to
f8d4bee
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
a620feb
to
9939cca
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
.
5519ca8
to
eb75cf2
Compare
@@ -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 |
There was a problem hiding this comment.
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
.
eb75cf2
to
48fba47
Compare
@@ -31,6 +31,49 @@ | |||
Declarative) | |||
|
|||
|
|||
def pwpolicy_cmd( | |||
cmd, minlife, cospriority=None, | |||
pwpolicy_group=None, pwpolicyadd=False): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
dee6722
to
8edfeb6
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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.
d6e8f46
to
cc61243
Compare
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>
cc61243
to
0026f65
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
master:
|
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