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

Ensure user store uses lowercased username for document id. #10369

Merged
merged 1 commit into from
Jun 24, 2019

Conversation

hpidcock
Copy link
Member

Description of change

Not all user store operations correctly formatted the mongo document id.
This fixes the behaviour in all affected user state functions and add tests to ensure this behaviour works.

Previously juju register with a secret token failed because the update password didn't behave correctly when a username contained uppercase.

QA steps

Adding a user and registering that user should succeed when the username contains uppercase.

juju bootstrap localhost
juju add-user TestName
XDG_DATA_HOME=`mktemp -d` juju register <secret token from add-user>`

Documentation changes

N/A

Bug reference

https://bugs.launchpad.net/juju/+bug/1833449

@hpidcock
Copy link
Member Author

state/user.go Outdated
@@ -37,12 +37,14 @@ func userIDFromGlobalKey(key string) string {
}

func (st *State) checkUserExists(name string) (bool, error) {
nameToLower := strings.ToLower(name)

Choose a reason for hiding this comment

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

Personal preference.. but I don't like variables that sound like they're about actions in the future, when they're about the past. imo we're representing a nameLowerCase rather than a nameToLower.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah agreed, there was already code see addUser which named it this way. So I was going for consistency. I don't mind changing them all.

Choose a reason for hiding this comment

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

It looks like the variables in those private methods were created 4 years ago. We probably won't hurt anyone's feelings by changing them now.

Maybe add to PR?

Copy link

@timClicks timClicks left a comment

Choose a reason for hiding this comment

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

General question only - do we know if our documentation specifies that user names are case insensitive?

@hpidcock
Copy link
Member Author

General question only - do we know if our documentation specifies that user names are case insensitive?

Not sure. The user name validation allows upper case explicitly in it's regex and the add user logic already supports this (hence why the mongo ids are lowercased)

@hpidcock hpidcock force-pushed the 1833449-register-uppercase-username branch from 5005ffd to 9170356 Compare June 24, 2019 04:26
@hpidcock
Copy link
Member Author

$$merge$$

@jujubot jujubot merged commit ff42def into juju:2.6 Jun 24, 2019
jujubot added a commit that referenced this pull request Jun 25, 2019
@hpidcock hpidcock deleted the 1833449-register-uppercase-username branch November 15, 2019 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants