More checks in the secret key backup inttest

This commit is contained in:
Paul Schaub 2018-06-27 11:55:41 +02:00
parent 322d3aebb2
commit 81167871b2
1 changed files with 18 additions and 4 deletions

View File

@ -16,6 +16,9 @@
*/ */
package org.jivesoftware.smackx.openpgp; package org.jivesoftware.smackx.openpgp;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
import java.io.File; import java.io.File;
@ -64,10 +67,10 @@ public class SecretKeyBackupRestoreIntegrationTest extends AbstractOpenPgpIntegr
public SecretKeyBackupRestoreIntegrationTest(SmackIntegrationTestEnvironment environment) public SecretKeyBackupRestoreIntegrationTest(SmackIntegrationTestEnvironment environment)
throws XMPPException.XMPPErrorException, TestNotPossibleException, SmackException.NotConnectedException, throws XMPPException.XMPPErrorException, TestNotPossibleException, SmackException.NotConnectedException,
InterruptedException, SmackException.NoResponseException, SmackException.NotLoggedInException { InterruptedException, SmackException.NoResponseException {
super(environment); super(environment);
if (!OpenPgpManager.serverSupportsSecretKeyBackups(aliceConnection)) { if (!OpenPgpManager.serverSupportsSecretKeyBackups(aliceConnection)) {
throw new TestNotPossibleException("Server does not support the whitelist access model."); throw new TestNotPossibleException("Server does not support the 'whitelist' PubSub access model.");
} }
} }
@ -98,8 +101,13 @@ public class SecretKeyBackupRestoreIntegrationTest extends AbstractOpenPgpIntegr
OpenPgpManager openPgpManager = OpenPgpManager.getInstanceFor(aliceConnection); OpenPgpManager openPgpManager = OpenPgpManager.getInstanceFor(aliceConnection);
openPgpManager.setOpenPgpProvider(beforeProvider); openPgpManager.setOpenPgpProvider(beforeProvider);
beforeStore.setPrimaryOpenPgpKeyPairFingerprint( assertNull(beforeStore.getPrimaryOpenPgpKeyPairFingerprint());
openPgpManager.generateAndImportKeyPair(alice));
OpenPgpV4Fingerprint keyFingerprint = openPgpManager.generateAndImportKeyPair(alice);
beforeStore.setPrimaryOpenPgpKeyPairFingerprint(keyFingerprint);
assertEquals(keyFingerprint, beforeStore.getPrimaryOpenPgpKeyPairFingerprint());
assertTrue(beforeStore.getAvailableKeyPairFingerprints(alice).contains(keyFingerprint));
openPgpManager.backupSecretKeyToServer(new DisplayBackupCodeCallback() { openPgpManager.backupSecretKeyToServer(new DisplayBackupCodeCallback() {
@Override @Override
@ -117,6 +125,9 @@ public class SecretKeyBackupRestoreIntegrationTest extends AbstractOpenPgpIntegr
PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(alice, afterStore); PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(alice, afterStore);
openPgpManager.setOpenPgpProvider(afterProvider); openPgpManager.setOpenPgpProvider(afterProvider);
assertNull(afterStore.getPrimaryOpenPgpKeyPairFingerprint());
assertFalse(afterStore.getAvailableKeyPairFingerprints(alice).contains(keyFingerprint));
OpenPgpV4Fingerprint fingerprint = openPgpManager.restoreSecretKeyServerBackup(new AskForBackupCodeCallback() { OpenPgpV4Fingerprint fingerprint = openPgpManager.restoreSecretKeyServerBackup(new AskForBackupCodeCallback() {
@Override @Override
public String askForBackupCode() { public String askForBackupCode() {
@ -129,8 +140,11 @@ public class SecretKeyBackupRestoreIntegrationTest extends AbstractOpenPgpIntegr
} }
}); });
assertTrue(afterStore.getAvailableKeyPairFingerprints(alice).contains(keyFingerprint));
afterStore.setPrimaryOpenPgpKeyPairFingerprint(fingerprint); afterStore.setPrimaryOpenPgpKeyPairFingerprint(fingerprint);
assertEquals(keyFingerprint, afterStore.getPrimaryOpenPgpKeyPairFingerprint());
assertTrue(Arrays.equals(beforeStore.getSecretKeyRings(alice).getEncoded(), afterStore.getSecretKeyRings(alice).getEncoded())); assertTrue(Arrays.equals(beforeStore.getSecretKeyRings(alice).getEncoded(), afterStore.getSecretKeyRings(alice).getEncoded()));
} }
} }