typed expected failures and a couple minor things

This commit is contained in:
Vincent Breitmoser 2014-08-16 06:40:03 +02:00
parent a943bebfdf
commit de0d95432e
15 changed files with 56 additions and 49 deletions

View File

@ -19,6 +19,7 @@ import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.openpgp.PGPSignature;
import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@ -238,7 +239,7 @@ public class PgpKeyOperationTest {
parcel.mFingerprint = ring.getFingerprint();
assertModifyFailure("keyring modification with bad master key id should fail",
ring, parcel);
ring, parcel, LogType.MSG_MF_ERROR_KEYID);
}
{
@ -248,7 +249,7 @@ public class PgpKeyOperationTest {
parcel.mFingerprint = ring.getFingerprint();
assertModifyFailure("keyring modification with null master key id should fail",
ring, parcel);
ring, parcel, LogType.MSG_MF_ERROR_KEYID);
}
{
@ -259,7 +260,7 @@ public class PgpKeyOperationTest {
parcel.mFingerprint[5] += 1;
assertModifyFailure("keyring modification with bad fingerprint should fail",
ring, parcel);
ring, parcel, LogType.MSG_MF_ERROR_FINGERPRINT);
}
{
@ -268,7 +269,7 @@ public class PgpKeyOperationTest {
parcel.mFingerprint = null;
assertModifyFailure("keyring modification with null fingerprint should fail",
ring, parcel);
ring, parcel, LogType.MSG_MF_ERROR_FINGERPRINT);
}
{
@ -278,7 +279,7 @@ public class PgpKeyOperationTest {
}
assertModifyFailure("keyring modification with bad passphrase should fail",
ring, parcel, badphrase);
ring, parcel, badphrase, LogType.MSG_MF_UNLOCK_ERROR);
}
}
@ -331,7 +332,8 @@ public class PgpKeyOperationTest {
parcel.reset();
parcel.mAddSubKeys.add(new SubkeyAdd(
PublicKeyAlgorithmTags.RSA_GENERAL, new Random().nextInt(512), KeyFlags.SIGN_DATA, 0L));
assertModifyFailure("creating a subkey with keysize < 512 should fail", ring, parcel);
assertModifyFailure("creating a subkey with keysize < 512 should fail", ring, parcel,
LogType.MSG_CR_ERROR_KEYSIZE_512);
}
@ -339,7 +341,8 @@ public class PgpKeyOperationTest {
parcel.reset();
parcel.mAddSubKeys.add(new SubkeyAdd(PublicKeyAlgorithmTags.RSA_GENERAL, 1024, KeyFlags.SIGN_DATA,
new Date().getTime()/1000-10));
assertModifyFailure("creating subkey with past expiry date should fail", ring, parcel);
assertModifyFailure("creating subkey with past expiry date should fail", ring, parcel,
LogType.MSG_MF_ERROR_PAST_EXPIRY);
}
}
@ -436,14 +439,16 @@ public class PgpKeyOperationTest {
parcel.reset();
parcel.mChangeSubKeys.add(new SubkeyChange(keyId, null, new Date().getTime()/1000-10));
assertModifyFailure("setting subkey expiry to a past date should fail", ring, parcel);
assertModifyFailure("setting subkey expiry to a past date should fail", ring, parcel,
LogType.MSG_MF_ERROR_PAST_EXPIRY);
}
{ // modifying nonexistent subkey should fail
parcel.reset();
parcel.mChangeSubKeys.add(new SubkeyChange(123, null, null));
assertModifyFailure("modifying non-existent subkey should fail", ring, parcel);
assertModifyFailure("modifying non-existent subkey should fail", ring, parcel,
LogType.MSG_MF_ERROR_SUBKEY_MISSING);
}
}
@ -529,21 +534,24 @@ public class PgpKeyOperationTest {
parcel.mRevokeUserIds.add("pink");
parcel.mChangeSubKeys.add(new SubkeyChange(keyId, KeyFlags.CERTIFY_OTHER, null));
assertModifyFailure("master key modification with all user ids revoked should fail", ring, parcel);
assertModifyFailure("master key modification with all user ids revoked should fail", ring, parcel,
LogType.MSG_MF_ERROR_MASTER_NONE);
}
{ // any flag not including CERTIFY_OTHER should fail
parcel.reset();
parcel.mChangeSubKeys.add(new SubkeyChange(keyId, KeyFlags.SIGN_DATA, null));
assertModifyFailure("setting master key flags without certify should fail", ring, parcel);
assertModifyFailure("setting master key flags without certify should fail", ring, parcel,
LogType.MSG_MF_ERROR_NO_CERTIFY);
}
{ // a past expiry should fail
parcel.reset();
parcel.mChangeSubKeys.add(new SubkeyChange(keyId, null, new Date().getTime()/1000-10));
assertModifyFailure("setting subkey expiry to a past date should fail", ring, parcel);
assertModifyFailure("setting subkey expiry to a past date should fail", ring, parcel,
LogType.MSG_MF_ERROR_PAST_EXPIRY);
}
}
@ -663,7 +671,8 @@ public class PgpKeyOperationTest {
parcel.reset();
parcel.mChangePrimaryUserId = uid;
assertModifyFailure("setting primary user id to a revoked user id should fail", modified, parcel);
assertModifyFailure("setting primary user id to a revoked user id should fail", modified, parcel,
LogType.MSG_MF_ERROR_REVOKED_PRIMARY);
}
@ -705,7 +714,8 @@ public class PgpKeyOperationTest {
parcel.reset();
parcel.mRevokeUserIds.add("nonexistent");
assertModifyFailure("revocation of nonexistent user id should fail", modified, parcel);
assertModifyFailure("revocation of nonexistent user id should fail", modified, parcel,
LogType.MSG_MF_ERROR_NOEXIST_REVOKE);
}
}
@ -715,7 +725,8 @@ public class PgpKeyOperationTest {
{
parcel.mAddUserIds.add("");
assertModifyFailure("adding an empty user id should fail", ring, parcel);
assertModifyFailure("adding an empty user id should fail", ring, parcel,
LogType.MSG_MF_UID_ERROR_EMPTY);
}
parcel.reset();
@ -784,7 +795,7 @@ public class PgpKeyOperationTest {
}
assertModifyFailure("changing primary user id to a non-existent one should fail",
ring, parcel);
ring, parcel, LogType.MSG_MF_ERROR_NOEXIST_PRIMARY);
}
// check for revoked primary user id already done in revoke test
@ -878,17 +889,7 @@ public class PgpKeyOperationTest {
}
private void assertModifyFailure(String reason, UncachedKeyRing ring,
SaveKeyringParcel parcel, String passphrase) throws Exception {
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
Assert.assertFalse(reason, result.success());
Assert.assertNull(reason, result.getRing());
}
private void assertModifyFailure(String reason, UncachedKeyRing ring, SaveKeyringParcel parcel)
SaveKeyringParcel parcel, String passphrase, LogType expected)
throws Exception {
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
@ -896,6 +897,22 @@ public class PgpKeyOperationTest {
Assert.assertFalse(reason, result.success());
Assert.assertNull(reason, result.getRing());
Assert.assertTrue(reason + "(with correct error)",
result.getLog().containsType(expected));
}
private void assertModifyFailure(String reason, UncachedKeyRing ring, SaveKeyringParcel parcel,
LogType expected)
throws Exception {
CanonicalizedSecretKeyRing secretRing = new CanonicalizedSecretKeyRing(ring.getEncoded(), false, 0);
EditKeyResult result = op.modifySecretKeyRing(secretRing, parcel, passphrase);
Assert.assertFalse(reason, result.success());
Assert.assertNull(reason, result.getRing());
Assert.assertTrue(reason + "(with correct error)",
result.getLog().containsType(expected));
}

View File

@ -557,7 +557,7 @@ public class PgpKeyOperation {
PGPSecretKey sKey = sKR.getSecretKey(change.mKeyId);
if (sKey == null) {
log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_MISSING,
log.add(LogLevel.ERROR, LogType.MSG_MF_ERROR_SUBKEY_MISSING,
indent + 1, PgpKeyHelper.convertKeyIdToHex(change.mKeyId));
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
}
@ -638,7 +638,7 @@ public class PgpKeyOperation {
PGPSecretKey sKey = sKR.getSecretKey(revocation);
if (sKey == null) {
log.add(LogLevel.ERROR, LogType.MSG_MF_SUBKEY_MISSING,
log.add(LogLevel.ERROR, LogType.MSG_MF_ERROR_SUBKEY_MISSING,
indent+1, PgpKeyHelper.convertKeyIdToHex(revocation));
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
}
@ -813,7 +813,7 @@ public class PgpKeyOperation {
if (!ok) {
// might happen, theoretically, if there is a key with no uid..
log.add(LogLevel.ERROR, LogType.MSG_MF_ERROR_INTEGRITY, indent);
log.add(LogLevel.ERROR, LogType.MSG_MF_ERROR_MASTER_NONE, indent);
return null;
}

View File

@ -359,20 +359,21 @@ public class OperationResultParcel implements Parcelable {
MSG_MF_ERROR_FINGERPRINT (R.string.msg_mf_error_fingerprint),
MSG_MF_ERROR_KEYID (R.string.msg_mf_error_keyid),
MSG_MF_ERROR_INTEGRITY (R.string.msg_mf_error_integrity),
MSG_MF_ERROR_MASTER_NONE(R.string.msg_mf_error_master_none),
MSG_MF_ERROR_NO_CERTIFY (R.string.msg_cr_error_no_certify),
MSG_MF_ERROR_NOEXIST_PRIMARY (R.string.msg_mf_error_noexist_primary),
MSG_MF_ERROR_NOEXIST_REVOKE (R.string.msg_mf_error_noexist_revoke),
MSG_MF_ERROR_NULL_EXPIRY (R.string.msg_mf_error_null_expiry),
MSG_MF_ERROR_PAST_EXPIRY(R.string.msg_mf_error_past_expiry),
MSG_MF_ERROR_REVOKED_PRIMARY (R.string.msg_mf_error_revoked_primary),
MSG_MF_ERROR_PGP (R.string.msg_mf_error_pgp),
MSG_MF_ERROR_REVOKED_PRIMARY (R.string.msg_mf_error_revoked_primary),
MSG_MF_ERROR_SIG (R.string.msg_mf_error_sig),
MSG_MF_ERROR_SUBKEY_MISSING(R.string.msg_mf_error_subkey_missing),
MSG_MF_MASTER (R.string.msg_mf_master),
MSG_MF_PASSPHRASE (R.string.msg_mf_passphrase),
MSG_MF_PRIMARY_REPLACE_OLD (R.string.msg_mf_primary_replace_old),
MSG_MF_PRIMARY_NEW (R.string.msg_mf_primary_new),
MSG_MF_SUBKEY_CHANGE (R.string.msg_mf_subkey_change),
MSG_MF_SUBKEY_MISSING (R.string.msg_mf_subkey_missing),
MSG_MF_SUBKEY_NEW_ID (R.string.msg_mf_subkey_new_id),
MSG_MF_SUBKEY_NEW (R.string.msg_mf_subkey_new),
MSG_MF_SUBKEY_REVOKE (R.string.msg_mf_subkey_revoke),

View File

@ -62,7 +62,6 @@
<string name="label_passphrase_cache_ttl">Cache hesel</string>
<string name="label_message_compression">Komprimovat zprávu</string>
<string name="label_file_compression">Komprimovat soubor</string>
<string name="label_force_v3_signature">Vynutit staré OpenPGPv3 podpisy</string>
<string name="label_key_id">ID klíče</string>
<string name="label_creation">Vytvořeno</string>
<string name="label_expiry">Expirace</string>

View File

@ -94,7 +94,6 @@
<string name="label_passphrase_cache_ttl">Passwort-Cache</string>
<string name="label_message_compression">Nachrichten-Komprimierung</string>
<string name="label_file_compression">Datei-Komprimierung</string>
<string name="label_force_v3_signature">Erzwinge alte OpenPGPv3-Signaturen</string>
<string name="label_keyservers">Schlüsselserver</string>
<string name="label_key_id">Schlüssel-ID</string>
<string name="label_creation">Erstellungsdatum</string>

View File

@ -97,7 +97,6 @@
<string name="label_passphrase_cache_ttl">Caché de frase de contraseña</string>
<string name="label_message_compression">Compresión de mensaje</string>
<string name="label_file_compression">Compresión de archivo</string>
<string name="label_force_v3_signature">Forzar firmas OpenPGPv3 antiguas</string>
<string name="label_keyservers">Servidores de claves</string>
<string name="label_key_id">ID de clave</string>
<string name="label_creation">Creación</string>
@ -585,7 +584,7 @@
<string name="msg_mf_primary_replace_old">Reemplazando certificado de la anterior identidad de usuario primaria </string>
<string name="msg_mf_primary_new">Generando nuevo certificado para nueva identidad de usuario primaria</string>
<string name="msg_mf_subkey_change">Modificando subclave %s</string>
<string name="msg_mf_subkey_missing">¡Intentó operar sobre una subclave ausente %s!</string>
<string name="msg_mf_error_subkey_missing">¡Intentó operar sobre una subclave ausente %s!</string>
<string name="msg_mf_subkey_new">Generando nueva subclave %2$s de %1$s bits</string>
<string name="msg_mf_subkey_new_id">Nueva identidad de subclave: %s</string>
<string name="msg_mf_error_past_expiry">¡La fecha de expiración no puede ser del pasado!</string>

View File

@ -97,7 +97,6 @@
<string name="label_passphrase_cache_ttl">Cache de la phrase de passe</string>
<string name="label_message_compression">Compression des messages</string>
<string name="label_file_compression">Compression des fichiers</string>
<string name="label_force_v3_signature">Forcer les anciennes signatures OpenPGP v3</string>
<string name="label_keyservers">Serveurs de clefs</string>
<string name="label_key_id">ID de le clef</string>
<string name="label_creation">Création</string>
@ -585,7 +584,7 @@
<string name="msg_mf_primary_replace_old">Remplacement du certificat de l\'ID d\'utilisateur principal précédent</string>
<string name="msg_mf_primary_new">Génération d\'un nouveau certificat pour le nouvel ID d\'utilisateur principal</string>
<string name="msg_mf_subkey_change">Modification de la sous-clef %s</string>
<string name="msg_mf_subkey_missing">Une action a été tentée sur la sous-clef manquante %s !</string>
<string name="msg_mf_error_subkey_missing">Une action a été tentée sur la sous-clef manquante %s !</string>
<string name="msg_mf_subkey_new">Génération d\'une nouvelle sous-clef %2$s de %1$s bit</string>
<string name="msg_mf_subkey_new_id">ID de la nouvelle sous-clef : %s</string>
<string name="msg_mf_error_past_expiry">La date d\'expiration ne peut pas être dans le passé !</string>

View File

@ -77,7 +77,6 @@
<string name="label_passphrase_cache_ttl">Cache Frase di Accesso</string>
<string name="label_message_compression">Compressione Messaggio</string>
<string name="label_file_compression">Compressione File</string>
<string name="label_force_v3_signature">Forza vecchie Firme OpenPGPv3</string>
<string name="label_keyservers">Server Chiavi</string>
<string name="label_key_id">ID Chiave</string>
<string name="label_creation">Creazione</string>
@ -525,7 +524,7 @@
<string name="msg_mf_primary_replace_old">Sostituzione certificato del ID utente primario precedente</string>
<string name="msg_mf_primary_new">Generazione di un nuovo certificato per il nuovo ID utente primario</string>
<string name="msg_mf_subkey_change">Modifica sottochiave %s</string>
<string name="msg_mf_subkey_missing">Tentativo di operare su sottochiave mancante %s!</string>
<string name="msg_mf_error_subkey_missing">Tentativo di operare su sottochiave mancante %s!</string>
<string name="msg_mf_subkey_new">Generazione nuovi %1$s bit %2$s sottochiave</string>
<string name="msg_mf_subkey_new_id">Nuovo ID sottochiave: %s</string>
<string name="msg_mf_error_past_expiry">La data di scadenza non può essere passata!</string>

View File

@ -97,7 +97,6 @@
<string name="label_passphrase_cache_ttl">パスフレーズキャッシュ</string>
<string name="label_message_compression">メッセージの圧縮</string>
<string name="label_file_compression">ファイルの圧縮</string>
<string name="label_force_v3_signature">強制的に古いOpenPGPV3形式の署名にする</string>
<string name="label_keyservers">鍵サーバ</string>
<string name="label_key_id">鍵ID</string>
<string name="label_creation">生成</string>
@ -571,7 +570,7 @@
<string name="msg_mf_primary_replace_old">以前の主ユーザIDで証明を入れ替え中</string>
<string name="msg_mf_primary_new">新しい主ユーザIDで新しい証明を生成中</string>
<string name="msg_mf_subkey_change">副鍵 %s を変更中</string>
<string name="msg_mf_subkey_missing">遺失した副鍵 %s の操作をしようとした!</string>
<string name="msg_mf_error_subkey_missing">遺失した副鍵 %s の操作をしようとした!</string>
<string name="msg_mf_subkey_new">新しい %1$s ビットの %2$s 副鍵の生成中</string>
<string name="msg_mf_subkey_new_id">新しい副鍵 ID: %s</string>
<string name="msg_mf_error_past_expiry">期限切れ日を過去にはできません!</string>

View File

@ -71,7 +71,6 @@
<string name="label_passphrase_cache_ttl">Wachtwoordcache</string>
<string name="label_message_compression">Berichtcompressie</string>
<string name="label_file_compression">Bestandscompressie</string>
<string name="label_force_v3_signature">Forceer oude OpenPGPv3 Handtekeningen</string>
<string name="label_keyservers">Sleutelservers</string>
<string name="label_key_id">Sleutel-id</string>
<string name="label_creation">Aanmaak</string>

View File

@ -59,7 +59,6 @@
<string name="label_passphrase_cache_ttl">Bufor haseł</string>
<string name="label_message_compression">Kompresja wiadomości</string>
<string name="label_file_compression">Kompresja plików</string>
<string name="label_force_v3_signature">Wymuś stare podpisy OpenPGPv3</string>
<string name="label_keyservers">Serwery kluczy</string>
<string name="label_key_id">Identyfikator klucza</string>
<string name="label_creation">Utworzenia</string>

View File

@ -74,7 +74,6 @@
<string name="label_passphrase_cache_ttl">Помнить пароль</string>
<string name="label_message_compression">Сжатие сообщения</string>
<string name="label_file_compression">Сжатие файла</string>
<string name="label_force_v3_signature">Использовать OpenPGPv3 подписи (устар.)</string>
<string name="label_keyservers">Серверы ключей</string>
<string name="label_key_id">ID ключа</string>
<string name="label_creation">Создан</string>

View File

@ -74,7 +74,6 @@
<string name="label_passphrase_cache_ttl">Hranjenje gesla v spominu</string>
<string name="label_message_compression">Stiskanje sporočil</string>
<string name="label_file_compression">Stiskanje datotek</string>
<string name="label_force_v3_signature">Vsili stare podpise OpenPGPv3</string>
<string name="label_keyservers">Strežniki</string>
<string name="label_key_id">ID ključa</string>
<string name="label_creation">Ustvarjanje</string>

View File

@ -74,7 +74,6 @@
<string name="label_passphrase_cache_ttl">Кеш парольної фрази</string>
<string name="label_message_compression">Стиснення повідомлення</string>
<string name="label_file_compression">Стиснення файлу</string>
<string name="label_force_v3_signature">Примусово старі підписи OpenPGPv3</string>
<string name="label_keyservers">Сервери ключів</string>
<string name="label_key_id">ІД ключа</string>
<string name="label_creation">Створення</string>

View File

@ -639,7 +639,7 @@
<string name="msg_mf_error_fingerprint">Actual key fingerprint does not match the expected one!</string>
<string name="msg_mf_error_keyid">No key ID. This is an internal error, please file a bug report!</string>
<string name="msg_mf_error_integrity">Internal error, integrity check failed!</string>
<string name="msg_mf_error_noexist_master">No master certificate found to modify!</string>
<string name="msg_mf_error_master_none">No master certificate found to operate on! (All revoked?)</string>
<string name="msg_mf_error_noexist_primary">Bad primary user id specified!</string>
<string name="msg_mf_error_noexist_revoke">Bad user id for revocation specified!</string>
<string name="msg_mf_error_revoked_primary">Revoked user ids cannot be primary!</string>
@ -651,7 +651,7 @@
<string name="msg_mf_primary_replace_old">Replacing certificate of previous primary user id</string>
<string name="msg_mf_primary_new">Generating new certificate for new primary user id</string>
<string name="msg_mf_subkey_change">Modifying subkey %s</string>
<string name="msg_mf_subkey_missing">Tried to operate on missing subkey %s!</string>
<string name="msg_mf_error_subkey_missing">Tried to operate on missing subkey %s!</string>
<string name="msg_mf_subkey_new">Generating new %1$s bit %2$s subkey</string>
<string name="msg_mf_subkey_new_id">New subkey ID: %s</string>
<string name="msg_mf_error_past_expiry">Expiry date cannot be in the past!</string>