Skip to content

Commit

Permalink
Improved the error messages and added coverage of bad property config…
Browse files Browse the repository at this point in the history
…uration for key particulars.
  • Loading branch information
ldaley committed Jun 27, 2011
1 parent e5476ec commit 72aec70
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Expand Up @@ -72,11 +72,22 @@ class PgpSignatoryFactory {
}

PGPSecretKey readSecretKey(String keyId, File file) {
if (!file.exists()) {
throw new InvalidUserDataException("Unable to retrieve secret key from key ring file '$file' as it does not exist")
}

file.withInputStream { readSecretKey(it, keyId, "file: $file.absolutePath") }
}

protected PGPSecretKey readSecretKey(InputStream input, String keyId, String sourceDescription) {
readSecretKey(new PGPSecretKeyRingCollection(input), normalizeKeyId(keyId), sourceDescription)
def keyRingCollection
try {
keyRingCollection = new PGPSecretKeyRingCollection(input)
} catch (Exception e) {
throw new InvalidUserDataException("Unable to read secret key from $sourceDescription (it may not be a PGP secret key ring)", e)
}

readSecretKey(keyRingCollection, normalizeKeyId(keyId), sourceDescription)
}

protected PGPSecretKey readSecretKey(PGPSecretKeyRingCollection keyRings, PgpKeyId keyId, String sourceDescription) {
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/
package org.gradle.plugins.signing

import org.gradle.api.InvalidUserDataException

class SignatoriesConfigurationSpec extends SigningProjectSpec {

def setup() {
Expand Down Expand Up @@ -65,5 +67,31 @@ class SignatoriesConfigurationSpec extends SigningProjectSpec {
signing.signatories.custom != null
signing.signatories.custom.keyId.asHex == properties.keyId
}

def "trying to read non existent file produces reasonable error message"() {
when:
setProperty("signing.keyId", "aaaaaaaa")
setProperty("signing.secretKeyRingFile", "i/dont/exist")
setProperty("signing.password", "anything")

and:
signing.signatory

then:
def e = thrown(InvalidUserDataException)
e.message.contains "it does not exist"
}

def "trying to use an invalid key ring file produces a reasonable error message"() {
given:
addSigningProperties(set: "invalid-key-ring")

when:
signing.signatory

then:
def e = thrown(InvalidUserDataException)
e.message.contains "Unable to read secret key from"
}

}
@@ -0,0 +1 @@
24875D73
@@ -0,0 +1 @@
gradle
@@ -0,0 +1 @@
not a valid key ring file

0 comments on commit 72aec70

Please sign in to comment.