protected void doGetWithRestrictionVerification(ServiceDocument createdState, String selfLink, String className) throws Throwable { host.log("GET to %s", selfLink); // Verify basic user cannot list the documents List<String> docs = getDocument( ServiceDocumentQueryResult.class, selfLink) .documentLinks; assertTrue(docs == null || docs.isEmpty()); try { getDocument(Class.forName(className), createdState.documentSelfLink); fail(EXPECTED_ILLEGAL_ACCESS_ERROR_MESSAGE); } catch (Throwable t) { assertForbiddenMessage(t); } }
protected void verifyDocumentAccessible(String documentLink, String userEmail, boolean expectAccessible) throws Throwable { host.assumeIdentity(buildUserServicePath(userEmail)); try { Object result = getDocument(Object.class, documentLink); if (!expectAccessible) { String error = String.format("%s must not be able to access %s", userEmail, documentLink); host.log(Level.SEVERE, error); throw new IllegalStateException(error); } else { assertNotNull(result); } } catch (IllegalAccessError e) { if (expectAccessible) { String error = String.format("%s must be able to access %s", userEmail, documentLink); host.log(Level.SEVERE, error); throw new IllegalStateException(error, e); } } }
protected List<UserState> getUsersFromUserGroup(String userGroupLink) throws Throwable { UserGroupState state = getDocument(UserGroupState.class, userGroupLink); assertNotNull(state); assertNotNull(state.query); DeferredResult<List<UserState>> result = ProjectUtil .retrieveUserStatesForGroup(testService, state); List<UserState> resultList = new ArrayList<>(); TestContext ctx = testCreate(1); result.whenComplete((list, ex) -> { if (ex != null) { ctx.failIteration(ex); return; } resultList.addAll(list); ctx.completeIteration(); }); ctx.await(); return resultList; }