protected ProjectState createProject(String name, String description, boolean isPublic, String adminsGroupLink, String membersGroupLink, String viewersGroupLink) throws Throwable { return createProject(name, description, isPublic, adminsGroupLink, membersGroupLink, viewersGroupLink, null); }
protected ProjectState patchProject(ProjectState patchState, String projectSelfLink) throws Throwable { ProjectState patchedState = doPatch(patchState, projectSelfLink); return patchedState; }
protected ProjectState updateProject(ProjectState updateState) throws Throwable { ProjectState updatedProject = doPut(updateState); return updatedProject; }
@Before public void beforeForAuthBase() throws Throwable { AuthUtil.resetProviders(); host.setSystemAuthorizationContext(); startServices(host); waitForServiceAvailability(AuthInitialBootService.SELF_LINK); waitForInitialBootServiceToBeSelfStopped(AuthInitialBootService.SELF_LINK); waitForDefaultRoles(); waitForDefaultUsersAndGroups(); TestContext ctx = new TestContext(1, Duration.ofSeconds(DEFAULT_WAIT_SECONDS_FOR_AUTH_SERVICES)); AuthUtil.getPreferredAuthConfigProvider().waitForInitBootConfig(host, ((CustomizationVerificationHost) host).localUsers, ctx::completeIteration, ctx::failIteration); ctx.await(); privilegedTestService = host.startServiceAndWait(PrivilegedTestService.class, PrivilegedTestService.SELF_LINK); host.resetAuthorizationContext(); testService = new TestService(); testService.setSelfLink(TestService.SELF_LINK); testService.setHost(host); }
host.assumeIdentity(buildUserServicePath(USER_EMAIL_ADMIN)); project = doPost(project, ProjectFactoryService.SELF_LINK); assertNotNull(project); assertNotNull(project.documentSelfLink); projectRoles.viewers.add = Collections.singletonList(USER_EMAIL_PROJECT_VIEWER_1); ExpandedProjectState expandedProjectState = getExpandedProjectState(project.documentSelfLink); doPatch(projectRoles, expandedProjectState.documentSelfLink); expandedProjectState = getExpandedProjectState(project.documentSelfLink);
protected void doPostWithRestrictionVerification(ServiceDocument doc, String selfLink) { host.log("POST to %s", selfLink); try { doPost(doc, selfLink); fail(EXPECTED_ILLEGAL_ACCESS_ERROR_MESSAGE); } catch (Throwable t) { assertForbiddenMessage(t); } }
protected void doPutWithRestrictionVerification(ServiceDocument doc, String selfLink) { host.log("PUT to %s", selfLink); try { doPut(doc); fail(EXPECTED_ILLEGAL_ACCESS_ERROR_MESSAGE); } catch (Throwable t) { assertForbiddenMessage(t); } }
@Override protected void startServices(VerificationHost host) throws Throwable { HostInitRequestServicesConfig.startServices(host); super.startServices(host); }
protected void doPatchWithRestrictionVerification(ServiceDocument doc, String selfLink) { host.log("PATCH to %s", selfLink); try { doPatch(doc, selfLink); fail(EXPECTED_ILLEGAL_ACCESS_ERROR_MESSAGE); } catch (Throwable t) { assertForbiddenMessage(t); } }
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 doDeleteWithRestrictionVerification(ServiceDocument doc, String selfLink) { host.log("DELETE to %s", selfLink); try { doDelete(UriUtils.buildUri(host, doc.documentSelfLink), false); 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); } } }
@Override protected VerificationHost createHost() throws Throwable { String[] customArgs = { CommandLineArgumentParser.ARGUMENT_PREFIX + AuthUtil.LOCAL_USERS_FILE + CommandLineArgumentParser.ARGUMENT_ASSIGNMENT + AuthBaseTest.class.getResource(FILE_LOCAL_USERS).toURI().getPath() }; return createHost(customArgs); }
protected void deleteProject(ProjectState projectToBeDeleted) throws Throwable { URI projectUri = UriUtils.buildUri(host, projectToBeDeleted.documentSelfLink); doDelete(projectUri, false); }
protected ProjectState createProject(String name, String description, boolean isPublic, String adminsGroupLink, String membersGroupLink, String viewersGroupLink, Map<String, String> customProperties) throws Throwable { ProjectState projectState = new ProjectState(); projectState.id = UUID.randomUUID().toString(); projectState.name = name; projectState.description = description; projectState.isPublic = isPublic; projectState.customProperties = customProperties; if (adminsGroupLink != null) { projectState.administratorsUserGroupLinks = new HashSet<>(); projectState.administratorsUserGroupLinks.add(adminsGroupLink); } if (membersGroupLink != null) { projectState.membersUserGroupLinks = new HashSet<>(); projectState.membersUserGroupLinks.add(membersGroupLink); } if (viewersGroupLink != null) { projectState.viewersUserGroupLinks = new HashSet<>(); projectState.viewersUserGroupLinks.add(viewersGroupLink); } projectState = doPost(projectState, ProjectFactoryService.SELF_LINK); return projectState; }
protected ProjectState createProjectExpectFailure(String name) throws Throwable { ProjectState state = new ProjectState(); state.name = name; state = doOperation(state, UriUtils.buildUri(host, ProjectFactoryService.SELF_LINK), ProjectState.class, true, Action.POST); return state; }
protected ProjectState createProject(String name, String description, boolean isPublic, Map<String, String> customProperties) throws Throwable { return createProject(name, description, isPublic, null, null, null, customProperties); }
protected ProjectState createProject(String name, Map<String, String> customProperties) throws Throwable { return createProject(name, null, false, null, null, null, customProperties); }
protected ProjectState createProject(String name, String description, boolean isPublic) throws Throwable { return createProject(name, description, isPublic, null, null, null); }
protected ProjectState createProject(String name) throws Throwable { return createProject(name, null, false, null, null, null); }