mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Merge branch '4.2'
This commit is contained in:
commit
81002c4fbd
63 changed files with 391 additions and 266 deletions
|
@ -58,7 +58,7 @@ public class MamIntegrationTest extends AbstractSmackIntegrationTest {
|
|||
EntityBareJid userOne = conOne.getUser().asEntityBareJid();
|
||||
EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
|
||||
|
||||
//Make sure MAM is archiving messages
|
||||
// Make sure MAM is archiving messages.
|
||||
mamManagerConTwo.updateArchivingPreferences(null, null, MamPrefsIQ.DefaultBehavior.always);
|
||||
|
||||
Message message = new Message(userTwo);
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractOmemoIntegrationTest extends AbstractSmackIntegrat
|
|||
throw new TestNotPossibleException("Server does not support OMEMO (PubSub)");
|
||||
}
|
||||
|
||||
//Check for OmemoService
|
||||
// Check for OmemoService
|
||||
if (!OmemoService.isServiceRegistered()) {
|
||||
throw new TestNotPossibleException("No OmemoService registered.");
|
||||
}
|
||||
|
|
|
@ -57,14 +57,14 @@ public class OmemoInitializationTest extends AbstractOmemoIntegrationTest {
|
|||
*/
|
||||
@SmackIntegrationTest
|
||||
public void initializationTest() throws XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, SmackException.NotLoggedInException, CorruptedOmemoKeyException, NotAPubSubNodeException {
|
||||
//test keys.
|
||||
// test keys.
|
||||
setUpOmemoManager(alice);
|
||||
assertNotNull("IdentityKey must not be null after initialization.", store.loadOmemoIdentityKeyPair(alice));
|
||||
assertTrue("We must have " + OmemoConstants.TARGET_PRE_KEY_COUNT + " preKeys.",
|
||||
store.loadOmemoPreKeys(alice).size() == OmemoConstants.TARGET_PRE_KEY_COUNT);
|
||||
assertNotNull("Our signedPreKey must not be null.", store.loadCurrentSignedPreKeyId(alice));
|
||||
|
||||
//Is deviceId published?
|
||||
// Is deviceId published?
|
||||
assertTrue("Published deviceList must contain our deviceId.",
|
||||
OmemoService.fetchDeviceList(alice, alice.getOwnJid())
|
||||
.getDeviceIds().contains(alice.getDeviceId()));
|
||||
|
|
|
@ -63,7 +63,7 @@ final class OmemoIntegrationTestHelper {
|
|||
try {
|
||||
omemoManager.requestDeviceListUpdateFor(omemoManager.getOwnJid());
|
||||
} catch (SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||
//ignore
|
||||
// ignore
|
||||
}
|
||||
|
||||
CachedDeviceList deviceList = OmemoService.getInstance().getOmemoStoreBackend().loadCachedDeviceList(omemoManager, omemoManager.getOwnJid());
|
||||
|
@ -71,26 +71,26 @@ final class OmemoIntegrationTestHelper {
|
|||
try {
|
||||
pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems();
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException | NotAPubSubNodeException e) {
|
||||
//Silent
|
||||
// Silent
|
||||
}
|
||||
|
||||
try {
|
||||
pm.deleteNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id));
|
||||
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
//Silent
|
||||
// Silent
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems();
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException | NotAPubSubNodeException e) {
|
||||
//Silent
|
||||
// Silent
|
||||
}
|
||||
|
||||
try {
|
||||
pm.deleteNode(OmemoConstants.PEP_NODE_DEVICE_LIST);
|
||||
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
//Silent
|
||||
// Silent
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ final class OmemoIntegrationTestHelper {
|
|||
try {
|
||||
roster.removeEntry(r);
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | SmackException.NotLoggedInException e) {
|
||||
//Silent
|
||||
// Silent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ final class OmemoIntegrationTestHelper {
|
|||
|
||||
|
||||
static void unidirectionalTrust(OmemoManager alice, OmemoManager bob) throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, CannotEstablishOmemoSessionException {
|
||||
//Fetch deviceList
|
||||
// Fetch deviceList
|
||||
alice.requestDeviceListUpdateFor(bob.getOwnJid());
|
||||
LOGGER.log(Level.INFO, "Current deviceList state: " + alice.getOwnDevice() + " knows " + bob.getOwnDevice() + ": "
|
||||
+ OmemoService.getInstance().getOmemoStoreBackend().loadCachedDeviceList(alice, bob.getOwnJid()));
|
||||
|
@ -136,12 +136,12 @@ final class OmemoIntegrationTestHelper {
|
|||
alice.getOmemoService().getOmemoStoreBackend().loadCachedDeviceList(alice, bob.getOwnJid())
|
||||
.getActiveDevices().contains(bob.getDeviceId()));
|
||||
|
||||
//Create sessions
|
||||
// Create sessions
|
||||
alice.buildSessionsWith(bob.getOwnJid());
|
||||
assertTrue("Trusting party must have a session with the other end at this point.",
|
||||
!alice.getOmemoService().getOmemoStoreBackend().loadAllRawSessionsOf(alice, bob.getOwnJid()).isEmpty());
|
||||
|
||||
//Trust the other party
|
||||
// Trust the other party
|
||||
alice.getOmemoService().getOmemoStoreBackend().trustOmemoIdentity(alice, bob.getOwnDevice(),
|
||||
alice.getOmemoService().getOmemoStoreBackend().getFingerprint(alice, bob.getOwnDevice()));
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class OmemoKeyTransportTest extends AbstractOmemoIntegrationTest {
|
|||
bob.addOmemoMessageListener(new OmemoMessageListener() {
|
||||
@Override
|
||||
public void onOmemoMessageReceived(String decryptedBody, Message encryptedMessage, Message wrappingMessage, OmemoMessageInformation omemoInformation) {
|
||||
//Don't care
|
||||
// Don't care
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -101,23 +101,23 @@ public class OmemoMessageSendingTest extends AbstractOmemoIntegrationTest {
|
|||
final SimpleResultSyncPoint messageOneSyncPoint = new SimpleResultSyncPoint();
|
||||
final SimpleResultSyncPoint messageTwoSyncPoint = new SimpleResultSyncPoint();
|
||||
|
||||
//Subscribe to one another
|
||||
// Subscribe to one another
|
||||
subscribe(alice, bob, "Bob");
|
||||
subscribe(bob, alice,"Alice");
|
||||
|
||||
//initialize OmemoManagers
|
||||
// initialize OmemoManagers
|
||||
setUpOmemoManager(alice);
|
||||
setUpOmemoManager(bob);
|
||||
|
||||
//Save initial bundles
|
||||
// Save initial bundles
|
||||
OmemoBundleElement aliceBundle = store.packOmemoBundle(alice);
|
||||
OmemoBundleElement bobsBundle = store.packOmemoBundle(bob);
|
||||
|
||||
//Trust
|
||||
// Trust
|
||||
unidirectionalTrust(alice, bob);
|
||||
unidirectionalTrust(bob, alice);
|
||||
|
||||
//Register messageListeners
|
||||
// Register messageListeners
|
||||
bob.addOmemoMessageListener(new OmemoMessageListener() {
|
||||
@Override
|
||||
public void onOmemoMessageReceived(String decryptedBody, Message encryptedMessage, Message wrappingMessage, OmemoMessageInformation omemoInformation) {
|
||||
|
@ -151,7 +151,7 @@ public class OmemoMessageSendingTest extends AbstractOmemoIntegrationTest {
|
|||
}
|
||||
});
|
||||
|
||||
//Prepare Alice message for Bob
|
||||
// Prepare Alice message for Bob
|
||||
Message encryptedA = alice.encrypt(bob.getOwnJid(), alicesSecret);
|
||||
ChatManager.getInstanceFor(alice.getConnection()).chatWith(bob.getOwnJid().asEntityBareJidIfPossible())
|
||||
.send(encryptedA);
|
||||
|
@ -163,11 +163,11 @@ public class OmemoMessageSendingTest extends AbstractOmemoIntegrationTest {
|
|||
TestCase.fail("Bob must have received Alice message.");
|
||||
}
|
||||
|
||||
//Check if Bob published a new Bundle
|
||||
// Check if Bob published a new Bundle
|
||||
assertNotSame("Bob must have published another bundle at this point, since we used a PreKeyMessage.",
|
||||
bobsBundle, OmemoService.fetchBundle(alice, bob.getOwnDevice()));
|
||||
|
||||
//Prepare Bobs response
|
||||
// Prepare Bobs response
|
||||
Message encryptedB = bob.encrypt(alice.getOwnJid(), bobsSecret);
|
||||
ChatManager.getInstanceFor(bob.getConnection()).chatWith(alice.getOwnJid().asEntityBareJidIfPossible())
|
||||
.send(encryptedB);
|
||||
|
|
|
@ -56,7 +56,7 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
@SmackIntegrationTest
|
||||
public void storeTest() throws Exception {
|
||||
|
||||
//########### PRE-INITIALIZATION ############
|
||||
// ########### PRE-INITIALIZATION ############
|
||||
|
||||
assertEquals("Creating an OmemoManager without MUST have set the default deviceId.", alice.getDeviceId(), OmemoService.getInstance().getOmemoStoreBackend().getDefaultDeviceId(alice.getOwnJid()));
|
||||
assertEquals("OmemoManager must be equal, since both got created without giving a deviceId.", alice, bob);
|
||||
|
@ -69,11 +69,11 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
|
||||
OmemoStore<?,?,?,?,?,?,?,?,?> store = OmemoService.getInstance().getOmemoStoreBackend();
|
||||
OmemoFingerprint finger = new OmemoFingerprint("FINGER");
|
||||
//DefaultDeviceId
|
||||
// DefaultDeviceId
|
||||
store.setDefaultDeviceId(alice.getOwnJid(), 777);
|
||||
assertEquals("defaultDeviceId setting/getting must equal.", 777, store.getDefaultDeviceId(alice.getOwnJid()));
|
||||
|
||||
//Trust/Distrust/Decide
|
||||
// Trust/Distrust/Decide
|
||||
bob.shutdown();
|
||||
bob = OmemoManager.getInstanceFor(conTwo, 998);
|
||||
assertFalse("Bobs device MUST be undecided at this point",
|
||||
|
@ -89,7 +89,7 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
assertFalse("Bobs device MUST be untrusted at this point.",
|
||||
store.isTrustedOmemoIdentity(alice, bob.getOwnDevice(), finger));
|
||||
|
||||
//Dates
|
||||
// Dates
|
||||
assertNull("Date of last received message must be null when no message was received ever.",
|
||||
store.getDateOfLastReceivedMessage(alice, bob.getOwnDevice()));
|
||||
Date now = new Date();
|
||||
|
@ -102,7 +102,7 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
assertEquals("Date of last signed prekey renewal must match our date.",
|
||||
now, store.getDateOfLastSignedPreKeyRenewal(alice));
|
||||
|
||||
//Keys
|
||||
// Keys
|
||||
assertNull("IdentityKeyPair must be null at this point.",
|
||||
store.loadOmemoIdentityKeyPair(alice));
|
||||
assertNull("IdentityKey of contact must be null at this point.",
|
||||
|
@ -118,7 +118,7 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
100, store.generateOmemoPreKeys(1, 100).size());
|
||||
|
||||
|
||||
//LastPreKeyId
|
||||
// LastPreKeyId
|
||||
assertEquals("LastPreKeyId must be 0 at this point.",
|
||||
0, store.loadLastPreKeyId(alice));
|
||||
store.storeLastPreKeyId(alice, 1234);
|
||||
|
@ -126,7 +126,7 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
assertEquals("LastPreKeyId set/get must equal.", 1234, store.loadLastPreKeyId(alice));
|
||||
store.storeLastPreKeyId(alice, 0);
|
||||
|
||||
//CurrentSignedPreKeyId
|
||||
// CurrentSignedPreKeyId
|
||||
assertEquals("CurrentSignedPreKeyId must be 0 at this point.",
|
||||
0, store.loadCurrentSignedPreKeyId(alice));
|
||||
store.storeCurrentSignedPreKeyId(alice, 554);
|
||||
|
@ -137,10 +137,10 @@ public class OmemoStoreTest extends AbstractOmemoIntegrationTest {
|
|||
|
||||
deletePath(alice);
|
||||
|
||||
//################# POST-INITIALIZATION #################
|
||||
// ################# POST-INITIALIZATION #################
|
||||
setUpOmemoManager(alice);
|
||||
|
||||
//Keys
|
||||
// Keys
|
||||
assertNotNull("IdentityKeyPair must not be null after initialization",
|
||||
store.loadOmemoIdentityKeyPair(alice));
|
||||
assertNotSame("LastPreKeyId must not be 0 after initialization.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue