Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MERGE: main into intergration #222

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ private final Map<String, List<Message>> validateOdfXmlEntries(final OdfPackage
for (final FileEntry xmlEntry : odfPackage.getXmlEntries()) {
messages.put(xmlEntry.getFullPath(), validateXmlEntry(xmlEntry, odfPackage));
}
for (final Entry<String, ParseResult> entry : odfPackage.getMetaInfMap().entrySet()) {
messages.put(entry.getKey(), validatePackageXml(entry.getKey(), odfPackage, entry.getValue()));
}
return messages;
}

Expand All @@ -119,7 +122,12 @@ private final List<Message> validateXmlEntry(final FileEntry xmlEntry, final Odf
if (xmlEntry.isEncrypted()) {
return Arrays.asList(FACTORY.getWarning("PKG-10", xmlPath));
}
ParseResult parseResult = odfPackage.getEntryXmlParseResult(xmlPath);
return validatePackageXml(xmlPath, odfPackage, odfPackage.getEntryXmlParseResult(xmlPath));

}

private final List<Message> validatePackageXml(final String xmlPath, final OdfPackage odfPackage,
final ParseResult parseResult) {
if (parseResult == null) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ public void testParseStream() throws ParserConfigurationException, SAXException,
}

@Test
public void testValidPackage() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testValidPackage()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.EMPTY_ODS);
assertTrue("Empty ODS IS valid", report.isValid());
}

@Test
public void testInValidZip() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testInValidZip()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.FAKEMIME_TEXT);
assertFalse("FAKEMIME should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("PKG-1")).count() > 0);
Expand All @@ -125,7 +127,8 @@ public void testBadlyFormedPackage()
}

@Test
public void testNoManifest() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testNoManifest()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.NO_MANIFEST_ODS);
assertFalse("NO_MANIFEST_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("PKG-3")).count() > 0);
Expand Down Expand Up @@ -172,21 +175,24 @@ public void testManifestEmptyRootMime()
}

@Test
public void testManifestEntry() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testManifestEntry()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MANIFEST_ENTRY_ODS);
assertFalse("MANIFEST_ENTRY_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-2")).count() > 0);
}

@Test
public void testMimetypeEntry() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMimetypeEntry()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MIMETYPE_ENTRY_ODS);
assertFalse("MIMETYPE_ENTRY_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-3")).count() > 0);
}

@Test
public void testMetainfEntry() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMetainfEntry()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.METAINF_ENTRY_ODT);
assertFalse("METAINF_ENTRY_ODT should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-6")).count() > 0);
Expand All @@ -201,50 +207,57 @@ public void testMissingManifestEntry()
}

@Test
public void testMissingXmlEntry() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMissingXmlEntry()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MANIFEST_MISSING_XML_ENTRY_ODS);
assertFalse("MANIFEST_MISSING_XML_ENTRY_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-1")).count() > 0);
}

@Test
public void testMissingFile() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMissingFile()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MISSING_FILE_ODS);
assertFalse("MISSING_FILE_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-4")).count() > 0);
}

@Test
public void testNoMimeWithRoot() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testNoMimeWithRoot()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.NO_MIME_ROOT_ODS);
assertFalse("NO_MIME_ROOT_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MIM-4")).count() > 0);
}

@Test
public void testNoRootMimeTyoe() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testNoRootMimeTyoe()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MANIFEST_NO_ROOT_MIMETYPE_ODS);
assertFalse("MANIFEST_NO_ROOT_MIMETYPE_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-5")).count() > 0);
}

@Test
public void testNoMimeNoRoot() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testNoMimeNoRoot()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.NO_MIME_NO_ROOT_ODS);
assertTrue("NO_MIME_NO_ROOT_ODS should be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("PKG-4")).count() > 0);
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MAN-7")).count() > 0);
}

@Test
public void testMimeLast() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMimeLast()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MIME_LAST_ODS);
assertFalse("MIME_LAST_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MIM-1")).count() > 0);
}

@Test
public void testMimeCompressed() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMimeCompressed()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MIME_COMPRESSED_ODS);
assertFalse("MIME_COMPRESSED_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MIM-2")).count() > 0);
Expand All @@ -260,39 +273,45 @@ public void testMimeCompressedLast()
}

@Test
public void testMimeExtra() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testMimeExtra()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.MIME_EXTRA_ODS);
assertFalse("MIME_EXTRA_ODS should NOT be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("MIM-3")).count() > 0);
}

@Test
public void testNoThumbnail() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testNoThumbnail()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.NO_THUMBNAIL_ODS);
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("PKG-7")).count() > 0);
}

@Test
public void testNoEmbeddedWord() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testNoEmbeddedWord()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.EMBEDDED_WORD);
assertTrue("EMBEDDED_WORD IS valid", report.isValid());
}

@Test
public void testPasswordEncrypted() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testPasswordEncrypted()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.ENCRYPTED_PASSWORDS);
assertTrue("ENCRYPTED_PASSWORDS should be valid", report.isValid());
assertTrue(report.getMessages().stream().filter(m -> m.getId().equals("PKG-10")).count() > 0);
}

@Test
public void testDsigValid() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testDsigValid()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.DSIG_VALID);
assertTrue("Package is not valid", report.isValid());
}

@Test
public void testDsigInvalid() throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
public void testDsigInvalid()
throws ParserConfigurationException, SAXException, IOException, ParseException, URISyntaxException {
ValidationReport report = Utilities.getValidationReport(TestFiles.DSIG_INVALID);
assertFalse("Package should be NOT be valid, dsig file has bad version", report.isValid());
}
Expand Down
Loading