(#101) Validate usernames across cli & tui #115

Merged
o32patel merged 8 commits from 101-username-validation into master 2024-01-22 13:15:43 -05:00
Member

Current changes should address issues raised by @merenber in #114 excluding #114 (comment) (both CLI and TUI validation)

Current changes should address issues raised by @merenber in #114 excluding https://git.csclub.uwaterloo.ca/public/pyceo/pulls/114#issuecomment-14153 (both CLI and TUI validation)
o32patel added 1 commit 2024-01-16 08:34:06 -05:00
o32patel self-assigned this 2024-01-16 08:34:12 -05:00
merenber requested changes 2024-01-16 22:38:32 -05:00
merenber left a comment
Owner

A few minor comments, but looks great overall. Thank you for taking the initiative to add this feature!

A few minor comments, but looks great overall. Thank you for taking the initiative to add this feature!
@ -53,1 +56,4 @@
return datetime.datetime.now()
class UsernameValidationResult:
Owner

This can be simplified with Python's dataclass decorator:

from dataclasses import dataclass

@dataclass
class UsernameValidationResult:
    is_valid: bool
    error_message: str = ''
This can be simplified with Python's dataclass decorator: ```python from dataclasses import dataclass @dataclass class UsernameValidationResult: is_valid: bool error_message: str = '' ```
o32patel marked this conversation as resolved
@ -0,0 +2,4 @@
def test_validate_username():
assert utils.validate_username('').__eq__(utils.UsernameValidationResult(False, 'Username must not be empty'))
Owner

Why are we using __eq__ here? Why not just ==?

Why are we using `__eq__` here? Why not just `==`?
o32patel marked this conversation as resolved
o32patel added 3 commits 2024-01-16 22:43:16 -05:00
Author
Member

Since the TUI verifies the usernames for every input, I coped that behaviour over to the CLI parts, should they also be applied to the API? Or is it fine to leave it as only verifiying for new users?

Since the TUI verifies the usernames for every input, I coped that behaviour over to the CLI parts, should they also be applied to the API? Or is it fine to leave it as only verifiying for new users?
o32patel added 1 commit 2024-01-16 23:11:34 -05:00
continuous-integration/drone/pr Build is failing Details
adc31519c0
Simplify UsernameValidationResult and tests
Owner

Since the TUI verifies the usernames for every input, I coped that behaviour over to the CLI parts, should they also be applied to the API? Or is it fine to leave it as only verifiying for new users?

The same username validation logic should be applied to the /members POST endpoint:
https://git.csclub.uwaterloo.ca/public/pyceo/src/branch/master/ceod/api/members.py#L26

> Since the TUI verifies the usernames for every input, I coped that behaviour over to the CLI parts, should they also be applied to the API? Or is it fine to leave it as only verifiying for new users? The same username validation logic should be applied to the /members POST endpoint: https://git.csclub.uwaterloo.ca/public/pyceo/src/branch/master/ceod/api/members.py#L26
Owner

I just checked the CI logs, it looks like the tests are failing because some of the tests use underscores in the usernames ... ugh. I think it's OK to allow underscores in the username regex for now. Someone can open a separate PR later to clean that up.

I just checked the CI logs, it looks like the tests are failing because some of the tests use underscores in the usernames ... ugh. I think it's OK to allow underscores in the username regex for now. Someone can open a separate PR later to clean that up.
Author
Member

Since the TUI verifies the usernames for every input, I coped that behaviour over to the CLI parts, should they also be applied to the API? Or is it fine to leave it as only verifiying for new users?

The same username validation logic should be applied to the /members POST endpoint:
https://git.csclub.uwaterloo.ca/public/pyceo/src/branch/master/ceod/api/members.py#L26

Cool, should be done in 3f751ccece

> > Since the TUI verifies the usernames for every input, I coped that behaviour over to the CLI parts, should they also be applied to the API? Or is it fine to leave it as only verifiying for new users? > > The same username validation logic should be applied to the /members POST endpoint: > https://git.csclub.uwaterloo.ca/public/pyceo/src/branch/master/ceod/api/members.py#L26 Cool, should be done in 3f751ccece
o32patel added 1 commit 2024-01-17 21:56:54 -05:00
continuous-integration/drone/pr Build is passing Details
c48cce3826
Allow underscores in usernames to pass ci
Author
Member

And everything should be good now

And everything should be good now
o32patel changed title from WIP: (#101) Validate usernames across cli & tui to (#101) Validate usernames across cli & tui 2024-01-17 21:57:18 -05:00
o32patel requested review from merenber 2024-01-18 19:08:14 -05:00
merenber requested changes 2024-01-19 18:55:51 -05:00
@ -105,6 +112,11 @@ def print_user_lines(d: Dict):
@members.command(short_help='Get info about a user')
@click.argument('username')
def get(username):
# Verify that the username is valid before requesting data from API
Owner

We don't need to validate the username for get/modify/renew/pwreset/delete, because the client will get a 404 if the username is invalid. We only need to validate the username when adding new members.

We don't need to validate the username for get/modify/renew/pwreset/delete, because the client will get a 404 if the username is invalid. We only need to validate the username when adding new members.
Author
Member

Should this also be done for the TUI? Currently it validates under Controller.get_username_from_view() which is shared across all/most options

Should this also be done for the TUI? Currently it validates under Controller.get_username_from_view() which is shared across all/most options
Owner

Nah, I think that should be fine. I just didn't want to duplicate code if it wasn't necessary.

Nah, I think that should be fine. I just didn't want to duplicate code if it wasn't necessary.
Owner

Could we also please add a few unit tests for the API (under tests/ceod/api)? Just as a sanity check.

Could we also please add a few unit tests for the API (under tests/ceod/api)? Just as a sanity check.
o32patel added 1 commit 2024-01-22 00:59:06 -05:00
o32patel added 1 commit 2024-01-22 01:37:31 -05:00
continuous-integration/drone/pr Build is passing Details
d11bdc1a6f
add ceod unit tests for valid usernames
o32patel reviewed 2024-01-22 01:38:50 -05:00
@ -135,6 +135,40 @@ def test_api_create_user_without_forwarding_addresses(cfg, client):
assert data['error'] == "BadRequest: Attribute 'forwarding_addresses' is missing or empty"
def test_api_create_user_without_valid_username(cfg, client):
Author
Member

test_api_create_user_without_valid_username should probably be expanded on with the _ fix mentioned here: #115 (comment)

test_api_create_user_without_valid_username should probably be expanded on with the _ fix mentioned here: https://git.csclub.uwaterloo.ca/public/pyceo/pulls/115#issuecomment-14170
merenber approved these changes 2024-01-22 07:48:58 -05:00
o32patel merged commit de23296413 into master 2024-01-22 13:15:43 -05:00
o32patel deleted branch 101-username-validation 2024-01-22 13:15:43 -05:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: public/pyceo#115
No description provided.