use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.
the class AuthControllerTest method readOneUserByIdExample2.
@Test
public void readOneUserByIdExample2() throws Exception {
expectedEx.expect(WormholeRequestException.class);
expectedEx.expectMessage("Forbidden");
String userId = UUID.randomUUID().toString();
WormholeUserDetails userdetail = new WormholeUserDetails();
userdetail.setUserId(userId);
List<String> rolenames = new ArrayList<String>();
rolenames.add("sysuser");
WormholeUser sysuser = new WormholeUser();
sysuser.setRoleNames(rolenames);
sysuser.setId(userId);
userRepository.save(sysuser);
Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
MvcResult result = this.mockMvc.perform(get("/v1/auth/user/123")).andExpect(status().isForbidden()).andReturn();
if (result.getResolvedException() != null) {
userRepository.deleteById(userId);
throw result.getResolvedException();
}
}
use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.
the class AuthControllerTest method testRefreshToken.
@Test
public void testRefreshToken() throws Exception {
ValueOperations<String, String> valueOperations = Mockito.mock(ValueOperations.class);
Mockito.doReturn(valueOperations).when(template).opsForValue();
WormholeUser wormholeuser = createUser();
String userId = UUID.randomUUID().toString();
wormholeuser.setId(userId);
wormholeuser.setUserName("tomRefresh");
wormholeuser.setPassword("$2a$10$Vm8MLIkGwinuICfcqW5RDOoE.aJqnvsaPhnxl7.N4H7oLKVIu3o0.");
wormholeuser.setRoleNames(Arrays.asList("admin"));
userRepository.save(wormholeuser);
MvcResult result = this.mockMvc.perform(post("/v1/auth/token").contentType(MediaType.APPLICATION_JSON).content("{\"userName\":\"tomRefresh\",\"password\":\"123456\"}")).andExpect(status().isOk()).andReturn();
String access_token = "";
Cookie[] cookies = result.getResponse().getCookies();
if (cookies != null && cookies.length != 0) {
for (Cookie currentcookie : cookies) {
if (JwtTokenUtil.Token_Name.equals(currentcookie.getName())) {
access_token = currentcookie.getValue();
break;
}
}
}
DecodedJWT jwtcre = jwtUtil.getDecodedJwt(access_token);
ObjectMapper mapper = new ObjectMapper();
WormholeUserDetails userdetail = new WormholeUserDetails();
userdetail.setUserId(userId);
userdetail.setUsername("tomRefresh");
userdetail.setPassword("$2a$10$Vm8MLIkGwinuICfcqW5RDOoE.aJqnvsaPhnxl7.N4H7oLKVIu3o0.");
Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
Mockito.doReturn(mapper.writeValueAsString(userdetail)).when(tokenService).getUserJsonString(any());
MvcResult result1 = this.mockMvc.perform(get("/v1/auth/token/refresh").header("Authorization", "Bearer " + access_token)).andDo(document("AuthController-RefreshAccessToken-example")).andReturn();
// JwtTokenUtil jwtUtil = new JwtTokenUtil();
DecodedJWT jwt = jwtUtil.getDecodedJwt(result1.getResponse().getHeader("Authorization"));
TestCase.assertEquals("tomRefresh", jwt.getSubject());
userRepository.deleteById(wormholeuser.getId());
}
use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.
the class AuthControllerTest method readOneUserByIdExample.
@Test
public void readOneUserByIdExample() throws Exception {
WormholeUserDetails userdetail = new WormholeUserDetails();
String userId = UUID.randomUUID().toString();
userdetail.setUserId(userId);
List<String> rolenames = new ArrayList<String>();
rolenames.add("admin");
WormholeUser adminUser = new WormholeUser();
adminUser.setRoleNames(rolenames);
adminUser.setId(userId);
userRepository.save(adminUser);
Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
WormholeUser user = createUser();
userRepository.save(user);
this.mockMvc.perform(get("/v1/auth/user/{userId}", user.getId())).andExpect(status().isOk()).andDo(document("AuthController-readOneUserById-example", pathParameters(parameterWithName("userId").description("The id of user, generated by flowgate.")), responseFields(fieldWithPath("id").description("ID of User, created by flowgate"), fieldWithPath("userName").description("userName.").type(JsonFieldType.STRING), fieldWithPath("gender").description("gender").type(JsonFieldType.NUMBER), fieldWithPath("password").description("password"), fieldWithPath("mobile").description("mobile").type(JsonFieldType.STRING), fieldWithPath("status").description("status").type(JsonFieldType.NUMBER), fieldWithPath("createTime").description("createTime").type(Date.class), fieldWithPath("emailAddress").description("emailAddress").type(JsonFieldType.STRING), fieldWithPath("roleNames").description("roleNames").type(List.class), fieldWithPath("userGroupIDs").description("userGroupIDs").type(List.class), fieldWithPath("lastPasswordResetDate").description("lastPasswordResetDate").type(JsonFieldType.NUMBER)))).andReturn();
userRepository.deleteById(user.getId());
userRepository.deleteById(adminUser.getId());
}
use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.
the class AuthControllerTest method readOneUserByIdExample1.
@Test
public void readOneUserByIdExample1() throws Exception {
WormholeUserDetails userdetail = new WormholeUserDetails();
String userId = UUID.randomUUID().toString();
userdetail.setUserId(userId);
List<String> rolenames = new ArrayList<String>();
rolenames.add("sysuser");
WormholeUser sysuser = new WormholeUser();
sysuser.setRoleNames(rolenames);
sysuser.setId(userId);
userRepository.save(sysuser);
Mockito.doReturn(userdetail).when(tokenService).getCurrentUser(any());
this.mockMvc.perform(get("/v1/auth/user/" + sysuser.getId() + "")).andExpect(status().isOk()).andReturn();
userRepository.deleteById(sysuser.getId());
}
use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.
the class AuthControllerTest method createUser.
WormholeUser createUser() {
List<String> rolenames = new ArrayList<String>();
rolenames.add("role1");
rolenames.add("role2");
List<String> userGroupIDs = new ArrayList<String>();
userGroupIDs.add("userGroupIDs1");
userGroupIDs.add("userGroupIDs2");
WormholeUser user = new WormholeUser();
long time = System.currentTimeMillis();
user.setId(UUID.randomUUID().toString());
user.setCreateTime(new Date(time));
user.setEmailAddress("emailAddress");
user.setGender(1);
user.setMobile("mobile");
user.setPassword("password");
user.setRoleNames(rolenames);
user.setStatus(0);
user.setUserGroupIDs(userGroupIDs);
user.setUserName("userName");
return user;
}
Aggregations