Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Fail android_binary build with incorrect keystore alias.
Browse files Browse the repository at this point in the history
Summary:Resolves #655
Closes #676

Reviewed By: sdwilsh

fb-gh-sync-id: db35a85
shipit-source-id: db35a85
  • Loading branch information
sean-kenny authored and Facebook Github Bot 4 committed Mar 8, 2016
1 parent a099b0d commit f116fee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/com/facebook/buck/android/ApkBuilderStep.java
Expand Up @@ -187,6 +187,15 @@ private PrivateKeyAndCertificate createKeystoreProperties()
String alias = keystoreProperties.getAlias();
char[] keyPassword = keystoreProperties.getKeypass().toCharArray();
Key key = keystore.getKey(alias, keyPassword);
// key can be null if alias/password is incorrect.
if (key == null) {
throw new HumanReadableException(
"The keystore [%s] key.alias [%s] does not exist or does not identify a key-related " +
"entry",
pathToKeystore,
alias);
}

Certificate certificate = keystore.getCertificate(alias);

return new PrivateKeyAndCertificate((PrivateKey) key, (X509Certificate) certificate);
Expand Down
18 changes: 18 additions & 0 deletions test/com/facebook/buck/android/AndroidBinaryIntegrationTest.java
Expand Up @@ -16,6 +16,7 @@

package com.facebook.buck.android;

import static com.facebook.buck.testutil.RegexMatcher.containsRegex;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -514,4 +515,21 @@ public void testInstrumentationApkWithEmptyResDepBuildsCorrectly() throws IOExce
workspace.runBuckBuild("//apps/sample:instrumentation_apk").assertSuccess();
}

@Test
public void testInvalidKeystoreKeyAlias() throws IOException {
workspace.replaceFileContents(
"keystores/debug.keystore.properties",
"key.alias=my_alias",
"key.alias=invalid_alias"
);

workspace.resetBuildLogFile();
ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", SIMPLE_TARGET);
result.assertFailure("Invalid keystore key alias should fail.");

assertThat(
"error message for invalid keystore key alias is incorrect.",
result.getStderr(),
containsRegex("The keystore \\[.*\\] key\\.alias \\[.*\\].*does not exist"));
}
}
1 change: 1 addition & 0 deletions test/com/facebook/buck/android/BUCK
Expand Up @@ -225,6 +225,7 @@ java_test(
'//src/com/facebook/buck/zip:stream',
'//src/com/facebook/buck/zip:unzip',
'//test/com/facebook/buck/model:BuildTargetFactory',
'//test/com/facebook/buck/testutil:testutil',
'//test/com/facebook/buck/testutil/integration:integration',
'//third-party/java/commons-compress:commons-compress',
'//third-party/java/guava:guava',
Expand Down

0 comments on commit f116fee

Please sign in to comment.