use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeyAlias.
@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeyAlias() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true, "--stamp-key-alias=" + STAMP_KEY_ALIAS, "--stamp-key-pass=pass:" + STAMP_KEY_PASSWORD), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
SigningConfiguration stampSigningConfiguration = SigningConfiguration.builder().setSignerConfig(stampPrivateKey, stampCertificate).build();
BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(stampSigningConfiguration).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
assertThat(commandViaBuilder.build().getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
assertThat(commandViaBuilder.build().getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method settingBothSigningConfigAndSigningConfigProvider_throwsError.
@Test
public void settingBothSigningConfigAndSigningConfigProvider_throwsError() {
SigningConfiguration signingConfig = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
ApksigSigningConfiguration apksigSigningConfig = ApksigSigningConfiguration.builder().setSignerConfigs(ImmutableList.of(SignerConfig.builder().setPrivateKey(privateKey).setCertificates(ImmutableList.of(certificate)).build())).build();
IllegalStateException e = assertThrows(IllegalStateException.class, () -> BuildApksCommand.builder().setSigningConfiguration(signingConfig).setSigningConfigurationProvider(apkDescription -> apksigSigningConfig).build());
assertThat(e).hasMessageThat().isEqualTo("Only one of SigningConfiguration or SigningConfigurationProvider should be set.");
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_sameSigningKey.
@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_sameSigningKey() throws Exception {
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
"--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true), fakeAdbServer);
SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
BuildApksCommand commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(signingConfiguration).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get()).build();
assertThat(commandViaBuilder.getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
assertThat(commandViaBuilder.getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method populateLineage_binaryFile.
@Test
public void populateLineage_binaryFile() throws Exception {
SigningCertificateLineage.SignerConfig signerConfig = new SigningCertificateLineage.SignerConfig.Builder(privateKey, certificate).build();
SigningCertificateLineage.SignerConfig oldestSignerConfig = new SigningCertificateLineage.SignerConfig.Builder(oldestSignerPrivateKey, oldestSignerCertificate).build();
SigningCertificateLineage lineage = new SigningCertificateLineage.Builder(oldestSignerConfig, signerConfig).build();
File lineageFile = tmpDir.resolve("lineage-file").toFile();
lineage.writeToFile(lineageFile);
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--lineage=" + lineageFile, "--oldest-signer=" + oldestSignerPropertiesPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
assertThat(signingConfiguration.getSigningCertificateLineage().get().getCertificatesInLineage()).containsExactly(oldestSignerCertificate, certificate);
assertThat(signingConfiguration.getOldestSigner().get().getPrivateKey()).isEqualTo(oldestSignerConfig.getPrivateKey());
assertThat(signingConfiguration.getOldestSigner().get().getCertificates()).containsExactly(oldestSignerConfig.getCertificate());
}
use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.
the class BuildApksCommandTest method populateRotationMinSdkVersion.
@Test
public void populateRotationMinSdkVersion() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
int rotationMinSdkVersion = 30;
BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--rotation-min-sdk-version=" + rotationMinSdkVersion), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
assertThat(signingConfiguration.getRotationMinSdkVersion()).hasValue(rotationMinSdkVersion);
}
Aggregations