LoadHubArtifactsCommand extends AbstractCommand { protected DocumentMetadataHandle buildMetadata(String permissions, String collection) { DocumentMetadataHandle meta = new DocumentMetadataHandle(); meta.getCollections().add(collection); documentPermissionsParser.parsePermissions(permissions, meta.getPermissions()); return meta; } LoadHubArtifactsCommand();  LoadHubArtifactsCommand(HubConfig hubConfig);  LoadHubArtifactsCommand(HubConfig hubConfig, boolean forceLoad); void setForceLoad(boolean forceLoad); @Override void execute(CommandContext context); void setHubConfig(HubConfig hubConfig);  }
@Test public void verifyDefaultPermissions() { DocumentMetadataHandle h = loadHubArtifactsCommand.buildMetadata(adminHubConfig.getFlowPermissions(),"http: assertEquals(1, h.getCollections().size()); assertEquals("http: DocumentMetadataHandle.DocumentPermissions perms = h.getPermissions(); assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("data-hub-flow-reader").iterator().next()); h = loadHubArtifactsCommand.buildMetadata(adminHubConfig.getStepDefinitionPermissions(),"http: assertEquals(1, h.getCollections().size()); assertEquals("http: perms = h.getPermissions(); assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("data-hub-step-definition-reader").iterator().next()); h = loadHubArtifactsCommand.buildMetadata(adminHubConfig.getModulePermissions(), "hub-core-module"); perms = h.getPermissions(); List<DocumentMetadataHandle.Capability> dhModReader = new ArrayList<>(); dhModReader.add(perms.get("data-hub-module-reader").iterator().next()); dhModReader.add(perms.get("data-hub-module-reader").iterator().next()); dhModReader.contains(DocumentMetadataHandle.Capability.READ); dhModReader.contains(DocumentMetadataHandle.Capability.EXECUTE); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("data-hub-module-writer").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.EXECUTE, perms.get("rest-extension-user").iterator().next()); }
@Test public void customPermissions() { HubConfigImpl config = new HubConfigImpl(); config.setFlowPermissions("manage-user,read,manage-admin,update"); config.setStepDefinitionPermissions("manage-user,read,manage-admin,update"); config.setModulePermissions("manage-user,read,manage-admin,update"); DocumentMetadataHandle.DocumentPermissions perms = loadUserArtifactsCommand.buildMetadata(config.getStepDefinitionPermissions(),"http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-step-definition-reader")); perms = loadUserArtifactsCommand.buildMetadata(config.getFlowPermissions(),"http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-flow-writer")); perms = loadUserArtifactsCommand.buildMetadata(config.getModulePermissions(), "hub-core-module").getPermissions(); assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-module-writer")); }