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

"--no-compile-sdk-metadata" tests. #3220

Merged
merged 3 commits into from
Jul 25, 2023
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
35 changes: 31 additions & 4 deletions brut.apktool/apktool-lib/src/test/java/brut/androlib/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import brut.directory.ExtFile;
import brut.directory.FileDirectory;
import org.custommonkey.xmlunit.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
Expand Down Expand Up @@ -131,9 +132,35 @@ private void compareXmlFiles(String path, ElementQualifier qualifier) throws Bru
assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar());
}

protected static Document loadDocument(File file) throws IOException, SAXException, ParserConfigurationException {

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setFeature(FEATURE_DISABLE_DOCTYPE_DECL, true);
docFactory.setFeature(FEATURE_LOAD_DTD, false);

try {
docFactory.setAttribute(ACCESS_EXTERNAL_DTD, " ");
docFactory.setAttribute(ACCESS_EXTERNAL_SCHEMA, " ");
} catch (IllegalArgumentException ex) {
LOGGER.warning("JAXP 1.5 Support is required to validate XML");
}

DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// Not using the parse(File) method on purpose, so that we can control when
// to close it. Somehow parse(File) does not seem to close the file in all cases.
try (FileInputStream inputStream = new FileInputStream(file)) {
return docBuilder.parse(inputStream);
}
}

protected static ExtFile sTmpDir;
protected static ExtFile sTestOrigDir;
protected static ExtFile sTestNewDir;

protected final static Logger LOGGER = Logger.getLogger(BaseTest.class.getName());

private static final String ACCESS_EXTERNAL_DTD = "http://javax.xml.XMLConstants/property/accessExternalDTD";
private static final String ACCESS_EXTERNAL_SCHEMA = "http://javax.xml.XMLConstants/property/accessExternalSchema";
private static final String FEATURE_LOAD_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
private static final String FEATURE_DISABLE_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@
import brut.common.BrutException;
import brut.directory.ExtFile;
import brut.util.OS;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.*;

public class BuildAndDecodeTest extends BaseTest {
Expand Down Expand Up @@ -157,4 +166,23 @@ public void singleDexTest() throws BrutException, IOException {
public void unknownFolderTest() throws BrutException {
compareUnknownFiles();
}

@Test
public void confirmPlatformManifestValuesTest() throws IOException, SAXException, ParserConfigurationException {
Document doc = loadDocument(new File(sTestNewDir + "/AndroidManifest.xml"));
Node application = doc.getElementsByTagName("manifest").item(0);
NamedNodeMap attr = application.getAttributes();

Node platformBuildVersionNameAttr = attr.getNamedItem("platformBuildVersionName");
assertEquals("6.0-2438415", platformBuildVersionNameAttr.getNodeValue());

Node platformBuildVersionCodeAttr = attr.getNamedItem("platformBuildVersionCode");
assertEquals("23", platformBuildVersionCodeAttr.getNodeValue());

Node compileSdkVersionAttr = attr.getNamedItem("compileSdkVersion");
assertNull("compileSdkVersion should be stripped via aapt2", compileSdkVersionAttr);

Node compileSdkVersionCodenameAttr = attr.getNamedItem("compileSdkVersionCodename");
assertNull("compileSdkVersionCodename should be stripped via aapt2", compileSdkVersionCodenameAttr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.nio.file.Files;
Expand Down Expand Up @@ -100,29 +98,4 @@ public void netSecConfInManifest() throws IOException, ParserConfigurationExcept
Node debugAttr = attr.getNamedItem("android:networkSecurityConfig");
assertEquals("@xml/network_security_config", debugAttr.getNodeValue());
}

private static Document loadDocument(File file)
throws IOException, SAXException, ParserConfigurationException {

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setFeature(FEATURE_DISABLE_DOCTYPE_DECL, true);
docFactory.setFeature(FEATURE_LOAD_DTD, false);

try {
docFactory.setAttribute(ACCESS_EXTERNAL_DTD, " ");
docFactory.setAttribute(ACCESS_EXTERNAL_SCHEMA, " ");
} catch (IllegalArgumentException ex) {
LOGGER.warning("JAXP 1.5 Support is required to validate XML");
}

DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
try (FileInputStream inputStream = new FileInputStream(file)) {
return docBuilder.parse(inputStream);
}
}

private static final String ACCESS_EXTERNAL_DTD = "http://javax.xml.XMLConstants/property/accessExternalDTD";
private static final String ACCESS_EXTERNAL_SCHEMA = "http://javax.xml.XMLConstants/property/accessExternalSchema";
private static final String FEATURE_LOAD_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
private static final String FEATURE_DISABLE_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl";
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -103,31 +100,4 @@ public void netSecConfInManifest() throws IOException, ParserConfigurationExcept
Node debugAttr = attr.getNamedItem("android:networkSecurityConfig");
assertEquals("@xml/network_security_config", debugAttr.getNodeValue());
}

private static Document loadDocument(File file)
throws IOException, SAXException, ParserConfigurationException {

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setFeature(FEATURE_DISABLE_DOCTYPE_DECL, true);
docFactory.setFeature(FEATURE_LOAD_DTD, false);

try {
docFactory.setAttribute(ACCESS_EXTERNAL_DTD, " ");
docFactory.setAttribute(ACCESS_EXTERNAL_SCHEMA, " ");
} catch (IllegalArgumentException ex) {
LOGGER.warning("JAXP 1.5 Support is required to validate XML");
}

DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// Not using the parse(File) method on purpose, so that we can control when
// to close it. Somehow parse(File) does not seem to close the file in all cases.
try (FileInputStream inputStream = new FileInputStream(file)) {
return docBuilder.parse(inputStream);
}
}

private static final String ACCESS_EXTERNAL_DTD = "http://javax.xml.XMLConstants/property/accessExternalDTD";
private static final String ACCESS_EXTERNAL_SCHEMA = "http://javax.xml.XMLConstants/property/accessExternalSchema";
private static final String FEATURE_LOAD_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
private static final String FEATURE_DISABLE_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl";
}