-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(users): introduce generic ids for users instead of using emails a…
…s ids closes #242
- Loading branch information
Showing
23 changed files
with
157 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,8 @@ public class ComponentDatabaseHandlerTest { | |
private static final String email1 = "[email protected]"; | ||
private static final String email2 = "[email protected]"; | ||
|
||
private static final User user1 = new User().setEmail(email1).setDepartment("AB CD EF").setId(email1); | ||
private static final User user2 = new User().setEmail(email2).setDepartment("AB CD EF").setId(email2); | ||
private static final User user1 = new User().setEmail(email1).setDepartment("AB CD EF").setId("481489458"); | ||
private static final User user2 = new User().setEmail(email2).setDepartment("AB CD EF").setId("4786487647680"); | ||
|
||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public static void main(String[] args) throws TException, IOException { | |
TProtocol protocol = new TCompactProtocol(thriftClient); | ||
ModerationService.Iface client = new ModerationService.Client(protocol); | ||
|
||
List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("").setEmail("[email protected]").setDepartment("BB")); | ||
List<ModerationRequest> requestsByModerator = client.getRequestsByModerator(new User().setId("58245y9845").setEmail("[email protected]").setDepartment("BB")); | ||
|
||
|
||
System.out.println("Fetched " + requestsByModerator.size() + " moderation requests from moderation service"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import static org.eclipse.sw360.datahandler.thrift.ThriftValidate.prepareUser; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class ThriftValidateTest { | ||
final String DUMMY_EMAIL_ADDRESS = "[email protected]"; | ||
|
@@ -36,8 +37,8 @@ public void testPrepareUser() throws Exception { | |
user.setCommentMadeDuringModerationRequest(DUMMY_MODERATION_COMMENT); | ||
prepareUser(user); | ||
|
||
assertEquals(user.getEmail(), user.getId()); | ||
assertEquals(TYPE_USER,user.getType()); | ||
assertNull(user.getId()); | ||
assertEquals(TYPE_USER, user.getType()); | ||
assertFalse(user.isSetCommentMadeDuringModerationRequest()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ public void before() throws TException { | |
given(this.componentServiceMock.getComponentsForUser(anyObject())).willReturn(componentList); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
// user.setId("[email protected]"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ public void before() throws TException { | |
given(this.projectServiceMock.getProjectsForUser(anyObject())).willReturn(projectList); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,13 +43,13 @@ public void before() { | |
List<User> userList = new ArrayList<>(); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
userList.add(user); | ||
|
||
user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("987654321"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("Jane Doe"); | ||
userList.add(user); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ public void before() throws TException { | |
given(this.attachmentServiceMock.getAttachmentByIdForUser(eq(attachment.getAttachmentContentId()), anyObject())).willReturn(attachmentInfo); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ public void before() throws TException { | |
given(this.componentServiceMock.searchComponentByName(eq(angularComponent.getName()))).willReturn(componentListByName); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
user.setDepartment("sw360"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,7 @@ public void before() throws TException { | |
given(this.releaseServiceMock.getReleaseForUserById(eq(release2.getId()), anyObject())).willReturn(release2); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
user.setDepartment("sw360"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ public void before() throws TException { | |
given(this.releaseServiceMock.getReleaseForUserById(eq(release.getId()), anyObject())).willReturn(release); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,12 +50,12 @@ public class UserSpecTest extends TestRestDocsSpecBase { | |
private User user; | ||
|
||
@Before | ||
public void before() throws UnsupportedEncodingException { | ||
public void before() { | ||
List<User> userList = new ArrayList<>(); | ||
|
||
user = new User(); | ||
user.setEmail("[email protected]"); | ||
user.setId(Base64.getEncoder().encodeToString(user.getEmail().getBytes("utf-8"))); | ||
user.setId("4784587578e87989"); | ||
user.setUserGroup(UserGroup.ADMIN); | ||
user.setFullname("John Doe"); | ||
user.setGivenname("John"); | ||
|
@@ -66,10 +66,11 @@ public void before() throws UnsupportedEncodingException { | |
userList.add(user); | ||
|
||
given(this.userServiceMock.getUserByEmail("[email protected]")).willReturn(user); | ||
given(this.userServiceMock.getUser("4784587578e87989")).willReturn(user); | ||
|
||
User user2 = new User(); | ||
user2.setEmail("[email protected]"); | ||
user2.setId(Base64.getEncoder().encodeToString(user.getEmail().getBytes("utf-8"))); | ||
user2.setId("frwey45786rwe"); | ||
user2.setUserGroup(UserGroup.USER); | ||
user2.setFullname("Jane Doe"); | ||
user2.setGivenname("Jane"); | ||
|
@@ -102,7 +103,7 @@ public void should_document_get_users() throws Exception { | |
@Test | ||
public void should_document_get_user() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
mockMvc.perform(get("/api/users/" + user.getId()) | ||
mockMvc.perform(get("/api/users/byid/" + user.getId()) | ||
.header("Authorization", "Bearer " + accessToken) | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status().isOk()) | ||
|
@@ -111,6 +112,31 @@ public void should_document_get_user() throws Exception { | |
linkWithRel("self").description("The <<resources-users,User resource>>") | ||
), | ||
responseFields( | ||
fieldWithPath("id").description("The user's id"), | ||
fieldWithPath("email").description("The user's email"), | ||
fieldWithPath("userGroup").description("The user group, possible values are: " + Arrays.asList(UserGroup.values())), | ||
fieldWithPath("fullName").description("The users's full name"), | ||
fieldWithPath("givenName").description("The user's given name"), | ||
fieldWithPath("lastName").description("The user's last name"), | ||
fieldWithPath("department").description("The user's company department"), | ||
fieldWithPath("formerEmailAddresses").description("The user's former email addresses"), | ||
fieldWithPath("_links").description("<<resources-index-links,Links>> to other resources") | ||
))); | ||
} | ||
|
||
@Test | ||
public void should_document_get_user_by_email() throws Exception { | ||
String accessToken = TestHelper.getAccessToken(mockMvc, testUserId, testUserPassword); | ||
mockMvc.perform(get("/api/users/" + user.getEmail()) | ||
.header("Authorization", "Bearer " + accessToken) | ||
.accept(MediaTypes.HAL_JSON)) | ||
.andExpect(status().isOk()) | ||
.andDo(this.documentationHandler.document( | ||
links( | ||
linkWithRel("self").description("The <<resources-users,User resource>>") | ||
), | ||
responseFields( | ||
fieldWithPath("id").description("The user's id"), | ||
fieldWithPath("email").description("The user's email"), | ||
fieldWithPath("userGroup").description("The user group, possible values are: " + Arrays.asList(UserGroup.values())), | ||
fieldWithPath("fullName").description("The users's full name"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ public void before() { | |
vulnerabilityList.add(vulnerability2); | ||
|
||
User user = new User(); | ||
user.setId("[email protected]"); | ||
user.setId("123456789"); | ||
user.setEmail("[email protected]"); | ||
user.setFullname("John Doe"); | ||
|
||
|
Oops, something went wrong.