Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

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

Open
hritvikpatel4 wants to merge 2 commits into
apache:masterfrom
hritvikpatel4:fix-user-update-to-fail-with-spaces
Open

Fix user update to raise exception when the username contains spaces#6895
hritvikpatel4 wants to merge 2 commits into
apache:masterfrom
hritvikpatel4:fix-user-update-to-fail-with-spaces

Conversation

@hritvikpatel4

@hritvikpatel4 hritvikpatel4 commented Jun 10, 2022

Copy link
Copy Markdown

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
Comment thread lib/go-tc/users.go
} 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Comment thread traffic_ops/testing/api/v2/user_test.go
* 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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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