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

Normalize User Input in Registration #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arturobernalg
Copy link
Member

This pull request improves the handling of user input during registration by ensuring that extraneous whitespace is removed from key fields. Specifically, the DefaultUserManager.parseProfile() method now trims the loginname, fullname, and email fields so that entries like "admin" and "admin " are treated uniformly.

Copy link
Contributor

@juanpablo-santos juanpablo-santos left a 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 {
Copy link
Contributor

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();
Copy link
Contributor

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;
Copy link
Contributor

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();
Copy link
Contributor

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

@arturobernalg
Copy link
Member Author

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants