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

Fix user update to raise exception when the username contains spaces #6895

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hritvikpatel4
Copy link

@hritvikpatel4 hritvikpatel4 commented Jun 10, 2022

This PR fixes #4240 by adding checks to raise an exception when the username contains spaces.


Which Traffic Control components are affected by this PR?

  • Traffic Ops

What is the best way to verify this PR?

Run TrafficOps integration tests

If this is a bugfix, which Traffic Control versions contained the bug?

  • master

PR submission checklist

@ocket8888 ocket8888 added bug something isn't working as intended Traffic Portal v1 related to Traffic Portal version 1 low impact affects only a small portion of a CDN, and cannot itself break one labels Jun 10, 2022
@@ -487,6 +488,8 @@ func (u *CurrentUserUpdateRequestUser) UnmarshalAndValidate(user *User) error {
errs = append(errs, fmt.Errorf("username: %w", err))
} else if user.Username == nil || *user.Username == "" {
errs = append(errs, errors.New("username: cannot be null or empty string"))
} else if strings.Contains(*user.Username, " ") {
errs = append(errs, errors.New("username: cannot contain spaces"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Since in older versions of Traffic Ops, it was possible to have users with spaces in their usernames, it's a breaking change to the API to no longer allow that. As such, that change cannot be made in APIv2 or v3.

However, I think a better solution than returning an error when the username contains spaces is to simply change the form validation in Traffic Portal to allow spaces, since the API already does. That also allows you to avoid the mess of API versioning.

Copy link
Author

Choose a reason for hiding this comment

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

So if the condition defined in line 491 is true, I would need to change the form validation in the Traffic Portal?

If yes, where can I find the part of form validation in Traffic Portal?

And would I need to make the change for the form validation from the Go code?

Copy link
Contributor

Choose a reason for hiding this comment

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

The controller for the user details page view can be found at traffic_portal/app/src/common/modules/form/user/FormUserController.js

Copy link
Author

Choose a reason for hiding this comment

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

The controller for the user details page view can be found at traffic_portal/app/src/common/modules/form/user/FormUserController.js

Alright, I'll look into that file. Thanks!

traffic_ops/testing/api/v2/user_test.go Show resolved Hide resolved
* Fixed bug in v2 test
* Added tests for v3 and v4 API
@ocket8888 ocket8888 self-assigned this Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something isn't working as intended low impact affects only a small portion of a CDN, and cannot itself break one Traffic Portal v1 related to Traffic Portal version 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can update a user's username to contain spaces
2 participants