-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[WIP] CODENVY-627 Check for reserved usernames on user creation #1511
Changes from 4 commits
7a4f7f5
f855f8e
df25c1e
da69f5d
957742f
017da28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,12 @@ | |
*******************************************************************************/ | ||
package org.eclipse.che.api.user.server; | ||
|
||
import org.eclipse.che.api.core.BadRequestException; | ||
import org.eclipse.che.api.core.ConflictException; | ||
import org.eclipse.che.api.user.server.dao.PreferenceDao; | ||
import org.eclipse.che.api.user.server.dao.Profile; | ||
import org.eclipse.che.api.user.server.dao.User; | ||
import org.eclipse.che.api.user.server.dao.UserDao; | ||
import org.eclipse.che.api.user.server.dao.UserProfileDao; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.testng.annotations.Listeners; | ||
|
@@ -26,7 +25,6 @@ | |
import static org.mockito.Matchers.anyMapOf; | ||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
|
@@ -45,13 +43,11 @@ public class UserManagerTest { | |
@Mock | ||
PreferenceDao preferenceDao; | ||
|
||
@InjectMocks | ||
UserManager manager; | ||
|
||
@Test | ||
public void shouldCreateProfileAndPreferencesOnUserCreation() throws Exception { | ||
final User user = new User().withEmail("test@email.com").withName("testName"); | ||
manager.create(user, false); | ||
|
||
new UserManager(userDao, profileDao, preferenceDao, new String[0]).create(user, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mb it would be better to create instance of UserManager in method annotated with @BeforeMethod There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it's ok as is it. If there will be more tests, maybe then add BeforeMethod. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
verify(profileDao).create(any(Profile.class)); | ||
verify(preferenceDao).setPreferences(anyString(), anyMapOf(String.class, String.class)); | ||
|
@@ -60,8 +56,16 @@ public void shouldCreateProfileAndPreferencesOnUserCreation() throws Exception { | |
@Test | ||
public void shouldGeneratedPasswordWhenCreatingUserAndItIsMissing() throws Exception { | ||
final User user = new User().withEmail("test@email.com").withName("testName"); | ||
manager.create(user, false); | ||
|
||
new UserManager(userDao, profileDao, preferenceDao, new String[0]).create(user, false); | ||
|
||
verify(userDao).create(eq(user.withPassword("<none>"))); | ||
} | ||
|
||
@Test(expectedExceptions = ConflictException.class) | ||
public void shouldThrowConflictExceptionOnCreationIfUserNameIsReserved() throws Exception { | ||
final User user = new User().withEmail("test@email.com").withName("reserved"); | ||
|
||
new UserManager(userDao, profileDao, preferenceDao, new String[] {"reserved"}).create(user, false); | ||
} | ||
} |
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.
I propose to do this case-insensitive
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.
ok