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

8140 fixed username validation federated account creation #8141

Conversation

mderuijter
Copy link
Contributor

What this PR does / why we need it:
Fixes username validation for federated account creation
Which issue(s) this PR closes:

Closes #8140

Special notes for your reviewer:
None
Suggestions on how to test this:
Please see steps explained in the related issue
Does this PR introduce a user interface change? If mockups are available, please link/include them here:
No
Is there a release notes update needed for this change?:
No
Additional documentation:

@mderuijter
Copy link
Contributor Author

@djbrooke It seems CI is failing, I made sure to merge the latest from develop. Any idea what is causing it?

@qqmyers
Copy link
Member

qqmyers commented Oct 13, 2021

@mderuijter,
It’s a failure on the new Curation label API (below). It looked to me like you had most of the fixes that went in for that feature but I’d suggest merging with develop again to see if that makes it go away.

-- Jim

Error
Expected status code <200> doesn't match actual status code <400>.
Stacktrace
java.lang.AssertionError:
Expected status code <200> doesn't match actual status code <400>.
at edu.harvard.iq.dataverse.api.DatasetsIT.testCurationLabelAPIs(DatasetsIT.java:2404)
Standard Output
{"status":"OK","data":{"user":{"id":125,"userName":"user4ef6a686"},"authenticatedUser":{"id":125,"identifier":"@user4ef6a686","displayName":"user4ef6a686 user4ef6a686","firstName":"user4ef6a686","lastName":"user4ef6a686","email":"user4ef6a686@mailinator.com","superuser":false,"deactivated":false,"persistentUserId":"user4ef6a686","createdTime":"2021-10-12T17:30:13Z","lastLoginTime":"2021-10-12T17:30:13Z","authenticationProviderId":"builtin"},"apiToken":"502666a6-6973-4e1d-8033-7f0a063f6e53"}}
{"status":"OK","data":{"id":166,"alias":"dv66eb818c","name":"dv66eb818c","dataverseContacts":[{"displayOrder":0,"contactEmail":"9880534a@mailinator.com"}],"permissionRoot":true,"dataverseType":"UNCATEGORIZED","ownerId":1,"creationDate":"2021-10-12T17:30:13Z"}}
Standard Error
Oct 12, 2021 5:30:13 PM edu.harvard.iq.dataverse.api.UtilIT createRandomUser
INFO: Creating random test user user4ef6a686
Oct 12, 2021 5:30:13 PM edu.harvard.iq.dataverse.api.UtilIT getUsernameFromResponse
INFO: Username found in create user response: user4ef6a686
Oct 12, 2021 5:30:13 PM edu.harvard.iq.dataverse.api.UtilIT getApiTokenFromResponse
INFO: API token found in create user response: 502666a6-6973-4e1d-8033-7f0a063f6e53
Oct 12, 2021 5:30:13 PM edu.harvard.iq.dataverse.api.UtilIT getAliasFromResponse
INFO: Alias found in create dataverse response: dv66eb818c

Copy link
Contributor

@sekmiller sekmiller left a comment

Choose a reason for hiding this comment

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

Would it make sense to put the userNameFound method into the UserNameValidator? I know we probably can't put it into the isValid method because we want to show different error messages, but it might be good for code consolidation.

@sekmiller sekmiller removed their assignment Oct 14, 2021
@djbrooke
Copy link
Contributor

@mderuijter - what do you think about the feedback from @sekmiller above?

@mderuijter
Copy link
Contributor Author

@sekmiller @djbrooke it does make sense to combine the two, let me put it on the to do list

@qqmyers
Copy link
Member

qqmyers commented Oct 15, 2021

@mderuijter - #8151 fixes the test failure you saw previously. I'm not sure how/why your branch doesn't show a failure now as the test is truly broken. In any case - merging with dev now should be a real fix.

@@ -33,7 +33,7 @@ public boolean isValid(String value, ConstraintValidatorContext context) {
* @param username
* @return boolean
*/
public static boolean isUserNameValid(final String username, ConstraintValidatorContext context) {
public static boolean isUserNameValid(final String username) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What the ConstraintValidatorContext removed because it was never used? If so, @sekmiller do you happen to recall why it may have been there? And if so should we also then remove it from the isValid method above? (this would mean finding all calls to it, of course)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scolapasta It was removed because it was not being used indeed.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems not to have been used at all and should probably be removed from isValid. Not sure why it was in there in the first place. It looks like Sarah wrote the original code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mderuijter since there's no reason to have the context in the isValid method, would you be able to remove it there (and refactor calls to it) as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scolapasta I see this will result in removing the entire implements ConstraintValidator<ValidateUserName, String> Interface structure as well, which leads to a related problem in ValidateUserName.java as well. Which in turn is used in BuiltinUser.java line 48. So eventhough the context parameter is not used, the surrounding structure is. I'm not entirely sure how to refactor that properly...

Copy link
Contributor

Choose a reason for hiding this comment

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

ok! that makes sense. I went ahead and added a comment in order to clarify this for when we look at this down the line.

@scolapasta scolapasta self-assigned this Oct 15, 2021
@mderuijter
Copy link
Contributor Author

Would it make sense to put the userNameFound method into the UserNameValidator? I know we probably can't put it into the isValid method because we want to show different error messages, but it might be good for code consolidation.

@sekmiller I had a look at the code again and I'm assuming you mean the method call of the AuthenticationService at

boolean userNameFound = authenticationSvc.identifierExists(userName);
Moving that to the UserNameValidator would either mean turning UserNameValidator into a service bean or passing the AuthenticationService as a parameter and creating a separate method that calls authenticationSvc.identifierExists(userName) so you can return different FacesMessages.

I'm not sure there's a lot to win here by moving that around to be honest

@sekmiller
Copy link
Contributor

OK @mderuijter, point taken. My hope was to have all of the validation logic in one place, but I see the pitfalls. I'll approve the PR but let Gustavo make the final call on passing to QA.

@coveralls
Copy link

coveralls commented Oct 20, 2021

Coverage Status

Coverage decreased (-0.002%) to 19.016% when pulling 5b7d028 on mderuijter:8140-fixed-username-validation-federated-account-creation into c0d06a5 on IQSS:develop.

IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) automation moved this from Review 🦁 to QA 🔎✅ Oct 21, 2021
@qqmyers qqmyers added the GDCC: DANS related to GDCC work for DANS label Oct 26, 2021
@kcondon kcondon self-assigned this Oct 26, 2021
@djbrooke djbrooke added this to the 5.8 milestone Nov 1, 2021
@kcondon kcondon merged commit 93d1359 into IQSS:develop Nov 1, 2021
IQSS/dataverse (TO BE RETIRED / DELETED in favor of project 34) automation moved this from QA 🔎✅ to Done 🚀 Nov 1, 2021
DANS Data Station Archaeology automation moved this from In Review to Done Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GDCC: DANS related to GDCC work for DANS
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Username not validated on the federated account creation page
7 participants