use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_verificationFailed_transparencyKeyCertificateNotProvidedByUser.
@Test
public void bundleMode_verificationFailed_transparencyKeyCertificateNotProvidedByUser() throws Exception {
// The public key transparencyKeyCertificate used to create JWS does not match the private key,
// and will result
// in signature verification failure later.
String serializedJws = createJwsToken(CodeTransparency.getDefaultInstance(), CertificateFactory.buildSelfSignedCertificate(kpg.generateKeyPair(), "CN=CheckTransparencyCommandTest_BadCertificate"), transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).build().checkTransparency(new PrintStream(outputStream));
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).contains("No APK present. APK signature was not checked.");
assertThat(output).contains("Verification failed because code transparency signature is invalid.");
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class DumpManagerTest method dumpManifest_moduleNotBase.
@Test
public void dumpManifest_moduleNotBase() throws Exception {
XmlNode manifestBase = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("base"))).build();
XmlNode manifestModule = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("module"))).build();
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestBase)).addModule("module", module -> module.setManifest(manifestModule)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setModuleName("module").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("<manifest package=\"module\" split=\"module\"/>%n"));
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class DumpManagerTest method dumpManifest_withXPath_predicate.
@Test
public void dumpManifest_withXPath_predicate() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app", withMetadataValue("key1", "value1"), withMetadataValue("key2", "value2")))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/meta-data[@android:name = \"key2\"]/@android:value").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("value2%n"));
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class DumpManagerTest method dumpResources_sameResourceNamePresentInMultipleModules.
@Test
public void dumpResources_sameResourceNamePresentInMultipleModules() throws Exception {
ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.app").addStringResource("module", "base").build();
ResourceTable fooResourceTable = new ResourceTableBuilder().addPackage("com.app.foo", 0x80).addStringResource("module", "foo").build();
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app")).setResourceTable(baseResourceTable)).addModule("foo", module -> module.setManifest(androidManifest("com.app.foo")).setResourceTable(fooResourceTable)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.RESOURCES).setOutputStream(new PrintStream(outputStream)).setResourceName("string/module").build().execute();
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).isEqualTo(String.format("Package 'com.app':%n" + "0x7f010000 - string/module%n" + "\t(default)%n" + "%n" + "Package 'com.app.foo':%n" + "0x80010000 - string/module%n" + "\t(default)%n" + "%n"));
}
use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.
the class DumpManagerTest method dumpManifest.
@Test
public void dumpManifest() throws Exception {
XmlNode manifest = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").build()).build();
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifest)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setModuleName("base").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("<manifest/>%n"));
}
Aggregations