use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method adminListsTest.
@Test
@WithMockUhUser(username = "admin")
public void adminListsTest() throws Exception {
String uri = REST_CONTROLLER_BASE + "adminLists";
given(httpRequestService.makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.GET))).willReturn(new ResponseEntity(HttpStatus.OK));
assertNotNull(mockMvc.perform(get(uri).with(csrf())).andExpect(status().isOk()).andReturn());
verify(httpRequestService, times(1)).makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.GET));
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method shouldDoGrouperHandshake.
@Test
@WithMockUhUser
public void shouldDoGrouperHandshake() throws Exception {
GroupingsRestController controller = applicationContext.getBean(GroupingsRestController.class);
Realm realm = controller.getRealm();
assertFalse(realm.isAnyProfileActive("default"));
assertTrue(realm.isAnyProfileActive("localTest"));
// What we are testing.
assertFalse(controller.shouldDoApiHandshake());
Realm realmMock = mock(Realm.class);
// Swap in mock.
controller.setRealm(realmMock);
assertTrue(mockingDetails(controller.getRealm()).isMock());
given(realmMock.isAnyProfileActive("default", "localTest")).willReturn(false);
// What we are testing.
assertTrue(controller.shouldDoApiHandshake());
// Mock real realm back.
controller.setRealm(realm);
assertFalse(mockingDetails(controller.getRealm()).isMock());
// Let's cheat a little to get at some private fields.
Class<?> c0 = controller.getClass();
Field field0 = c0.getDeclaredField("API_HANDSHAKE_ENABLED");
field0.setAccessible(true);
Boolean existingValue = (Boolean) field0.get(controller);
assertTrue(existingValue);
field0.set(controller, Boolean.FALSE);
// What we are testing.
assertFalse(controller.shouldDoApiHandshake());
// Put property value back.
field0.set(controller, Boolean.TRUE);
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class GroupingsRestControllerTest method optInGroupsTest.
@Test
@WithMockUhUser(username = "admin")
public void optInGroupsTest() throws Exception {
String uri = REST_CONTROLLER_BASE + "groupings/optInGroups";
given(httpRequestService.makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.GET))).willReturn(new ResponseEntity(HttpStatus.OK));
assertNotNull(mockMvc.perform(get(uri).with(csrf())).andExpect(status().isOk()).andReturn());
verify(httpRequestService, times(1)).makeApiRequest(eq(ADMIN_USERNAME), anyString(), eq(HttpMethod.GET));
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class AuthorizationServiceTest method fetchPrivilegesTest.
@Test
@WithMockUhUser
public void fetchPrivilegesTest() {
// Setup for the mocking.
User user = userContextService.getCurrentUser();
String uhUuid = user.getUhUuid();
Principal principal = new SimplePrincipal(uhUuid);
given(groupingsRestController.hasOwnerPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
given(groupingsRestController.hasAdminPrivs(principal)).willReturn(new ResponseEntity<>("true", HttpStatus.OK));
// What we are testing.
RoleHolder roleHolder = authorizationService.fetchRoles(uhUuid, "test");
// Check results.
assertThat(roleHolder.size(), equalTo(4));
assertTrue(roleHolder.contains(Role.ANONYMOUS));
assertTrue(roleHolder.contains(Role.UH));
assertTrue(roleHolder.contains(Role.OWNER));
assertTrue(roleHolder.contains(Role.ADMIN));
}
use of edu.hawaii.its.groupings.controller.WithMockUhUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class AuthorizationServiceTest method fetchDefaultTest.
@Test
@WithMockUhUser
public void fetchDefaultTest() {
// Setup for the mocking.
User user = userContextService.getCurrentUser();
String uhUuid = user.getUhUuid();
Principal principal = new SimplePrincipal(uhUuid);
given(groupingsRestController.hasOwnerPrivs(principal)).willReturn(new ResponseEntity<>(null, HttpStatus.OK));
given(groupingsRestController.hasAdminPrivs(principal)).willReturn(new ResponseEntity<>(null, HttpStatus.OK));
// What we are testing.
RoleHolder roleHolder = authorizationService.fetchRoles(uhUuid, "test");
// Check results.
assertThat(roleHolder.size(), equalTo(2));
assertTrue(roleHolder.contains(Role.ANONYMOUS));
assertTrue(roleHolder.contains(Role.UH));
assertFalse(roleHolder.contains(Role.EMPLOYEE));
assertFalse(roleHolder.contains(Role.ADMIN));
assertFalse(roleHolder.contains(Role.OWNER));
}
Aggregations