FileBlobStoreDescriptor extends BlobStoreDescriptorSupport { @Override public void validateConfig(final BlobStoreConfiguration config) { super.validateConfig(config); Path path = Optional.ofNullable(config.attributes(CONFIG_KEY).get(PATH_KEY, String.class)) .filter(s -> blobStoreUtil.validateFilePath(s, MAX_NAME_LENGTH)) .map(s -> Paths.get(s)) .orElseThrow(() -> new ValidationErrorsException( format("The maximum name length for any folder in the path is %d.", MAX_NAME_LENGTH))); pathValidator.validatePathUniqueConstraint(config); try { if (!path.isAbsolute()) { Path baseDir = applicationDirectories.getWorkDirectory(BASEDIR).toPath().toRealPath().normalize(); path = baseDir.resolve(path.normalize()); } if (!Files.isDirectory(path)) { Files.createDirectories(path); } else if (Files.isRegularFile(path)) { throw new ValidationErrorsException( format("Blob store could not be written to path '%s' because it is a file not a directory", path)); } } catch (IOException e) { throw new ValidationErrorsException( format("Blob store could not be written because the path %s could not be written to", path), e); } if (!Files.isWritable(path)) { throw new ValidationErrorsException( format("Blob store could not be written to path '%s' because it was not writable", path)); } } @Inject  FileBlobStoreDescriptor(final BlobStoreQuotaService quotaService,
                                 final ApplicationDirectories applicationDirectories,
                                 final BlobStoreUtil blobStoreUtil,
                                 final FileBlobStorePathValidator pathValidator); @Override String getName(); @Override List<FormField> getFormFields(); @Override void validateConfig(final BlobStoreConfiguration config);  }
@Test public void descriptorValidationCallQuotaValidation() throws Exception { BlobStoreConfiguration config = new MockBlobStoreConfiguration(); Path tempDir = Files.createTempDirectory("test"); config.attributes(CONFIG_KEY).set(PATH_KEY, tempDir.toAbsolutePath().toString()); descriptor.validateConfig(config); verify(quotaService, times(1)).validateSoftQuotaConfig(config); }
@Test public void descriptorValidationCallPathValidation() throws Exception { BlobStoreConfiguration config = new MockBlobStoreConfiguration(); String tempDir = Files.createTempDirectory("test").toString(); config.attributes(CONFIG_KEY).set(PATH_KEY, tempDir); descriptor.validateConfig(config); verify(blobStoreUtil, times(1)).validateFilePath(tempDir, MAX_NAME_LENGTH); }