-
Notifications
You must be signed in to change notification settings - Fork 102
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
Normalize User Input in Registration #377
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes requested
// --- Minimal dummy implementations --- | ||
|
||
// A very basic HttpServletRequest implementation supporting getParameter. | ||
private static class DummyHttpServletRequest implements HttpServletRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both DummyHttpServletRequest
and DummyContext
should better be mocked using mockito
@@ -292,10 +293,10 @@ public UserProfile parseProfile( final Context context ) { | |||
String password = request.getParameter( PARAM_PASSWORD ); | |||
String fullname = request.getParameter( PARAM_FULLNAME ); | |||
String email = request.getParameter( PARAM_EMAIL ); | |||
loginName = InputValidator.isBlank( loginName ) ? null : loginName; | |||
loginName = InputValidator.isBlank( loginName ) ? null : loginName.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InputValidator.isBlank( loginName ) ? null : loginName.trim();
can be reduced to (commons-lang3)StringUtils.trim( loginName )
, and same for the other two fields.
@@ -64,6 +64,7 @@ Licensed to the Apache Software Foundation (ASF) under one | |||
import java.security.Principal; | |||
import java.text.MessageFormat; | |||
import java.util.List; | |||
import java.util.Locale; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed?
@BeforeEach | ||
public void setUp() throws Exception { | ||
// Initialize a minimal test engine. | ||
engine = new TestEngine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be static fields, instantiated with something like:
private static TestEngine engine = TestEngine.build();
private static UserManager userManager = engine.getManager( DefaultUserManager.class );
so if not needed, we avoid instantiating them if/when adding new tests here
Hi @juanpablo-santos please to another pass. |
Trim extraneous whitespace from the loginname, fullname, and email fields in DefaultUserManager.parseProfile(). This change ensures that values such as "admin" and "admin " are treated uniformly. A new unit test (DefaultUserManagerTrimTest) has been added to verify the trimming logic.
This pull request improves the handling of user input during registration by ensuring that extraneous
whitespace
is removed from key fields. Specifically, theDefaultUserManager.parseProfile()
method now trims the loginname, fullname, and email fields so that entries like "admin" and "admin " are treated uniformly.