Skip to content

Commit a0f44e4

Browse files
authoredJun 16, 2023
Merge pull request #58 from DMTF/Fix57-POST-Create-Fixes
Fixes to POST (create) testing
2 parents d037530 + 5415c30 commit a0f44e4

File tree

6 files changed

+56
-17
lines changed

6 files changed

+56
-17
lines changed
 

‎redfish_protocol_validator/accounts.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,21 @@ def new_username(existing_users):
8989
return user
9090

9191

92-
def new_password(sut: SystemUnderTest, length=10, upper=1, lower=1,
93-
digits=1, symbols=0):
92+
def new_password(sut: SystemUnderTest, length=16, upper=1, lower=1,
93+
digits=1, symbols=1):
94+
# Get the min and max password length and override 'length' if needed
95+
# Use either limit if one is specified
96+
response = sut.get_response('GET', sut.account_service_uri)
97+
try:
98+
if response.ok:
99+
data = response.json()
100+
if 'MinPasswordLength' in data and length < data['MinPasswordLength']:
101+
length = data['MinPasswordLength']
102+
elif 'MaxPasswordLength' in data and length > data['MaxPasswordLength']:
103+
length = data['MaxPasswordLength']
104+
except:
105+
pass
106+
94107
ascii_symbols = '_-.'
95108
pwd = random.sample(string.ascii_uppercase, upper)
96109
pwd.extend(random.sample(string.ascii_lowercase, lower))

‎redfish_protocol_validator/service_requests.py

+34-9
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ def test_post_create_not_supported(sut: SystemUnderTest):
11381138
"""Perform tests for Assertion.REQ_POST_CREATE_NOT_SUPPORTED."""
11391139
response = sut.get_response('POST', sut.accounts_uri)
11401140
if response is None:
1141-
msg = ('Not response found for POST to Accounts URI; unable to test '
1141+
msg = ('No response found for POST to Accounts URI; unable to test '
11421142
'this assertion')
11431143
sut.log(Result.NOT_TESTED, 'POST', '', sut.accounts_uri,
11441144
Assertion.REQ_POST_CREATE_NOT_SUPPORTED, msg)
@@ -1151,14 +1151,39 @@ def test_post_create_not_supported(sut: SystemUnderTest):
11511151
Assertion.REQ_POST_CREATE_NOT_SUPPORTED,
11521152
'Test passed')
11531153
else:
1154-
msg = ('POST request to URI %s failed with %s; expected %s; extended '
1155-
'error: %s' % (sut.accounts_uri, response.status_code,
1156-
requests.codes.METHOD_NOT_ALLOWED,
1157-
utils.get_extended_error(response)))
1158-
sut.log(Result.FAIL, 'POST', response.status_code, sut.accounts_uri,
1159-
Assertion.REQ_POST_CREATE_NOT_SUPPORTED,
1160-
msg)
1161-
1154+
try:
1155+
allow = sut.get_response('GET', sut.accounts_uri).headers.get('Allow')
1156+
except:
1157+
allow = None
1158+
if allow:
1159+
if 'POST' in allow.upper():
1160+
msg = ('POST request to URI %s failed with %s; extended '
1161+
'error: %s; GET response contains an Allow header '
1162+
'with POST specified' %
1163+
(sut.accounts_uri, response.status_code,
1164+
utils.get_extended_error(response)))
1165+
sut.log(Result.WARN, 'POST', response.status_code,
1166+
sut.accounts_uri,
1167+
Assertion.REQ_POST_CREATE_NOT_SUPPORTED, msg)
1168+
else:
1169+
msg = ('POST request to URI %s failed with %s; expected %s; '
1170+
'extended error: %s' %
1171+
(sut.accounts_uri, response.status_code,
1172+
requests.codes.METHOD_NOT_ALLOWED,
1173+
utils.get_extended_error(response)))
1174+
sut.log(Result.FAIL, 'POST', response.status_code,
1175+
sut.accounts_uri,
1176+
Assertion.REQ_POST_CREATE_NOT_SUPPORTED, msg)
1177+
else:
1178+
msg = ('POST request to URI %s failed with %s; expected %s; '
1179+
'extended error: %s; GET response does not contain an '
1180+
'Allow header to verify' %
1181+
(sut.accounts_uri, response.status_code,
1182+
requests.codes.METHOD_NOT_ALLOWED,
1183+
utils.get_extended_error(response)))
1184+
sut.log(Result.WARN, 'POST', response.status_code,
1185+
sut.accounts_uri, Assertion.REQ_POST_CREATE_NOT_SUPPORTED,
1186+
msg)
11621187

11631188
def test_post_create_not_idempotent(sut: SystemUnderTest):
11641189
"""Perform tests for Assertion.REQ_POST_CREATE_NOT_IDEMPOTENT."""

‎requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ pyasn1
44
pyasn1-modules
55
requests>=2.23.0
66
sseclient-py
7-
urllib3
7+
urllib3<2

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
'console_scripts': ['rf_protocol_validator=redfish_protocol_validator.console_scripts:main']
3131
},
3232
install_requires=["aenum", "colorama", "pyasn1", "pyasn1-modules",
33-
"requests>=2.23.0", "sseclient-py", "urllib3"]
33+
"requests>=2.23.0", "sseclient-py", "urllib3<2"]
3434
)

‎unittests/test_accounts.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ def test_new_username(self):
9090

9191
def test_new_password(self):
9292
pass1 = accounts.new_password(self.sut)
93-
self.assertEqual(len(pass1), 10)
93+
self.assertEqual(len(pass1), 16)
9494
self.assertTrue(set(pass1).intersection(set(string.ascii_uppercase)))
9595
self.assertTrue(set(pass1).intersection(set(string.ascii_lowercase)))
9696
self.assertTrue(set(pass1).intersection(set(string.digits)))
9797
pass2 = accounts.new_password(self.sut)
98-
self.assertEqual(len(pass2), 10)
98+
self.assertEqual(len(pass2), 16)
9999
self.assertTrue(set(pass2).intersection(set(string.ascii_uppercase)))
100100
self.assertTrue(set(pass2).intersection(set(string.ascii_lowercase)))
101101
self.assertTrue(set(pass2).intersection(set(string.digits)))
102102
self.assertNotEqual(pass1, pass2)
103103
pass3 = accounts.new_password(self.sut, symbols=1)
104-
self.assertEqual(len(pass3), 10)
104+
self.assertEqual(len(pass3), 16)
105105
self.assertTrue(set(pass3).intersection(set(string.ascii_uppercase)))
106106
self.assertTrue(set(pass3).intersection(set(string.ascii_lowercase)))
107107
self.assertTrue(set(pass3).intersection(set(string.digits)))

‎unittests/test_service_requests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1640,11 +1640,12 @@ def test_test_post_create_not_supported_not_tested(self):
16401640
'POST', uri)
16411641
self.assertIsNotNone(result)
16421642
self.assertEqual(Result.NOT_TESTED, result['result'])
1643-
self.assertIn('Not response found for POST to Accounts URI',
1643+
self.assertIn('No response found for POST to Accounts URI',
16441644
result['msg'])
16451645

16461646
def test_test_post_create_not_supported_fail(self):
16471647
uri = self.sut.accounts_uri
1648+
add_response(self.sut, uri, json={}, headers={'Allow': 'GET'})
16481649
add_response(self.sut, uri, 'POST',
16491650
status_code=requests.codes.BAD_REQUEST)
16501651
req.test_post_create_not_supported(self.sut)

0 commit comments

Comments
 (0)
Please sign in to comment.