@Test public void testHandle_unauthorized() throws IOException { when(contentPermissionChecker.isPermitted(eq(REPO_NAME), eq(NpmFormat.NAME), eq(BreadActions.EDIT), any())) .thenReturn(false); ComponentUpload component = new ComponentUpload(); AssetUpload asset = new AssetUpload(); asset.setPayload(payload); component.getAssetUploads().add(asset); try { underTest.handle(repository, component); fail("Expected validation exception"); } catch (ValidationErrorsException e) { assertThat(e.getValidationErrors().size(), is(1)); assertThat(e.getValidationErrors().get(0).getMessage(), is("Not authorized for requested path '@foo/bar/-/bar-1.5.3.tgz'")); } }
@Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } @Inject  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions); }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } @Inject  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions); @Override UploadResponse handle(final Repository repository, final ComponentUpload upload); @Override Content handle(
      final Repository repository,
      final File content,
      final String path); @Override UploadDefinition getDefinition(); @Override VariableResolverAdapter getVariableResolverAdapter(); @Override ContentPermissionChecker contentPermissionChecker(); @Override boolean supportsExportImport(); }
OrientNpmUploadHandler extends UploadHandlerSupport implements NpmUploadHandler { @Override public UploadResponse handle(final Repository repository, final ComponentUpload upload) throws IOException { OrientNpmHostedFacet facet = repository.facet(OrientNpmHostedFacet.class); StorageFacet storageFacet = repository.facet(StorageFacet.class); PartPayload payload = upload.getAssetUploads().get(0).getPayload(); if (!payload.getName().endsWith(".tgz")) { throw new IllegalArgumentException("Unsupported extension. Extension must be .tgz"); } try (TempBlob tempBlob = storageFacet.createTempBlob(payload, NpmFacetUtils.HASH_ALGORITHMS)) { final Map<String, Object> packageJson = npmPackageParser.parsePackageJson(tempBlob); ensureNpmPermitted(repository, packageJson); UnitOfWork.begin(storageFacet.txSupplier()); try { return new UploadResponse(facet.putPackage(packageJson, tempBlob)); } finally { UnitOfWork.end(); } } } @Inject  OrientNpmUploadHandler(final ContentPermissionChecker contentPermissionChecker,
                                @Named("simple") final VariableResolverAdapter variableResolverAdapter,
                                final NpmPackageParser npmPackageParser,
                                final Set<UploadDefinitionExtension> uploadDefinitionExtensions); @Override UploadResponse handle(final Repository repository, final ComponentUpload upload); @Override Content handle(
      final Repository repository,
      final File content,
      final String path); @Override UploadDefinition getDefinition(); @Override VariableResolverAdapter getVariableResolverAdapter(); @Override ContentPermissionChecker contentPermissionChecker(); @Override boolean supportsExportImport();  }