@Test(expected = InvalidContentException.class) public void whenContentNameIsSha1AndStrictValidationShouldNotDetermineByDefaultValidator() throws Exception { Supplier<InputStream> supplier = () -> new ByteArrayInputStream("hello".getBytes()); underTest.determineContentType(true, supplier, mimeRulesSource, "file.sha1", TEXT_PLAIN.getMimeType()); }
@Nonnull @Override public String determineContentType(boolean strictContentTypeValidation, Supplier<InputStream> contentSupplier, @Nullable MimeRulesSource mimeRulesSource, @Nullable String contentName, @Nullable String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".pom")) { return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName + ".xml", declaredContentType ); } else if (contentName.endsWith(".sha1") || contentName.endsWith(".md5")) { if (strictContentTypeValidation) { try (InputStream is = contentSupplier.get()) { final String digestCandidate = DigestExtractor.extract(is); if (!DigestExtractor.isDigest(digestCandidate)) { throw new InvalidContentException("Not a Maven2 digest: " + contentName); } } } if (declaredContentType != null) { return declaredContentType; } } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); }
MavenContentValidator extends ComponentSupport implements ContentValidator { @Nonnull @Override public String determineContentType(boolean strictContentTypeValidation, Supplier<InputStream> contentSupplier, @Nullable MimeRulesSource mimeRulesSource, @Nullable String contentName, @Nullable String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".pom")) { return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName + ".xml", declaredContentType ); } else if (contentName.endsWith(".sha1") || contentName.endsWith(".md5")) { if (strictContentTypeValidation) { try (InputStream is = contentSupplier.get()) { final String digestCandidate = DigestExtractor.extract(is); if (!DigestExtractor.isDigest(digestCandidate)) { throw new InvalidContentException("Not a Maven2 digest: " + contentName); } } } if (declaredContentType != null) { return declaredContentType; } } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } }
MavenContentValidator extends ComponentSupport implements ContentValidator { @Nonnull @Override public String determineContentType(boolean strictContentTypeValidation, Supplier<InputStream> contentSupplier, @Nullable MimeRulesSource mimeRulesSource, @Nullable String contentName, @Nullable String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".pom")) { return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName + ".xml", declaredContentType ); } else if (contentName.endsWith(".sha1") || contentName.endsWith(".md5")) { if (strictContentTypeValidation) { try (InputStream is = contentSupplier.get()) { final String digestCandidate = DigestExtractor.extract(is); if (!DigestExtractor.isDigest(digestCandidate)) { throw new InvalidContentException("Not a Maven2 digest: " + contentName); } } } if (declaredContentType != null) { return declaredContentType; } } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } @Inject  MavenContentValidator(final DefaultContentValidator defaultContentValidator); }
MavenContentValidator extends ComponentSupport implements ContentValidator { @Nonnull @Override public String determineContentType(boolean strictContentTypeValidation, Supplier<InputStream> contentSupplier, @Nullable MimeRulesSource mimeRulesSource, @Nullable String contentName, @Nullable String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".pom")) { return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName + ".xml", declaredContentType ); } else if (contentName.endsWith(".sha1") || contentName.endsWith(".md5")) { if (strictContentTypeValidation) { try (InputStream is = contentSupplier.get()) { final String digestCandidate = DigestExtractor.extract(is); if (!DigestExtractor.isDigest(digestCandidate)) { throw new InvalidContentException("Not a Maven2 digest: " + contentName); } } } if (declaredContentType != null) { return declaredContentType; } } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } @Inject  MavenContentValidator(final DefaultContentValidator defaultContentValidator); @Nonnull @Override String determineContentType(boolean strictContentTypeValidation,
                                     Supplier<InputStream> contentSupplier,
                                     @Nullable MimeRulesSource mimeRulesSource,
                                     @Nullable String contentName,
                                     @Nullable String declaredContentType); }
MavenContentValidator extends ComponentSupport implements ContentValidator { @Nonnull @Override public String determineContentType(boolean strictContentTypeValidation, Supplier<InputStream> contentSupplier, @Nullable MimeRulesSource mimeRulesSource, @Nullable String contentName, @Nullable String declaredContentType) throws IOException { if (contentName != null) { if (contentName.endsWith(".pom")) { return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName + ".xml", declaredContentType ); } else if (contentName.endsWith(".sha1") || contentName.endsWith(".md5")) { if (strictContentTypeValidation) { try (InputStream is = contentSupplier.get()) { final String digestCandidate = DigestExtractor.extract(is); if (!DigestExtractor.isDigest(digestCandidate)) { throw new InvalidContentException("Not a Maven2 digest: " + contentName); } } } if (declaredContentType != null) { return declaredContentType; } } } return defaultContentValidator.determineContentType( strictContentTypeValidation, contentSupplier, mimeRulesSource, contentName, declaredContentType ); } @Inject  MavenContentValidator(final DefaultContentValidator defaultContentValidator); @Nonnull @Override String determineContentType(boolean strictContentTypeValidation,
                                     Supplier<InputStream> contentSupplier,
                                     @Nullable MimeRulesSource mimeRulesSource,
                                     @Nullable String contentName,
                                     @Nullable String declaredContentType);  }