Skip to content

Commit

Permalink
test negative user with invalid token
Browse files Browse the repository at this point in the history
  • Loading branch information
pondrejk authored and ogajduse committed Aug 23, 2023
1 parent f3bc09d commit 1ef2266
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/foreman/cli/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,46 @@ def test_custom_personal_access_token_role(self, target_sat):
f'curl -k -u {user["login"]}:{token_value} {target_sat.url}/api/v2/users'
)
assert f'Unable to authenticate user {user["login"]}' in command_output.stdout

@pytest.mark.tier2
def test_negative_personal_access_token_invalid_date(self, target_sat):
"""Personal access token with invalid expire date.
:id: 8c7c91c5-f6d9-4709-857c-6a875db41b88
:steps:
1. Set the expired time to a nonsensical datetime
2. Set the expired time to a past datetime
:expectedresults: token is not created with invalid or past expire time
:CaseLevel: System
:CaseImportance: Medium
:BZ: 2231814
"""
user = target_sat.cli_factory.make_user()
target_sat.cli.User.add_role({'login': user['login'], 'role': 'Viewer'})
token_name = gen_alphanumeric()
# check for invalid datetime
invalid_datetimes = ['00-14-00 09:30:55', '2028-08-22 28:30:55', '0000-00-22 15:90:55']
for datetime_expire in invalid_datetimes:
with pytest.raises(CLIReturnCodeError):
target_sat.cli.User.access_token(
action='create',
options={
'name': token_name,
'user-id': user['id'],
'expires-at': datetime_expire,
},
)
# check for past datetime
datetime_now = datetime.datetime.utcnow()
datetime_expire = datetime_now - datetime.timedelta(seconds=20)
datetime_expire = datetime_expire.strftime("%Y-%m-%d %H:%M:%S")
with pytest.raises(CLIReturnCodeError):
target_sat.cli.User.access_token(
action='create',
options={'name': token_name, 'user-id': user['id'], 'expires-at': datetime_expire},
)

0 comments on commit 1ef2266

Please sign in to comment.