use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class OmemoMamDecryptionTest method mamDecryptionTest.
@SmackIntegrationTest
public void mamDecryptionTest() throws XMPPException.XMPPErrorException, SmackException.NotLoggedInException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, CryptoFailedException, UndecidedOmemoIdentityException, IOException {
// Make sure, Bobs server stores messages in the archive
MamManager bobsMamManager = MamManager.getInstanceFor(bob.getConnection());
bobsMamManager.enableMamForAllMessages();
bobsMamManager.setDefaultBehavior(MamPrefsIQ.DefaultBehavior.always);
// Prevent bob from automatically decrypting MAM messages.
bob.stopStanzaAndPEPListeners();
String body = "This message will be stored in MAM!";
OmemoMessage.Sent encrypted = alice.encrypt(bob.getOwnJid(), body);
XMPPConnection alicesConnection = alice.getConnection();
MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
alicesConnection.sendStanza(encrypted.buildMessage(messageBuilder, bob.getOwnJid()));
MamManager.MamQuery query = bobsMamManager.queryArchive(MamManager.MamQueryArgs.builder().limitResultsToJid(alice.getOwnJid()).build());
assertEquals(1, query.getMessageCount());
List<MessageOrOmemoMessage> decryptedMamQuery = bob.decryptMamQueryResult(query);
assertEquals(1, decryptedMamQuery.size());
assertEquals(body, decryptedMamQuery.get(decryptedMamQuery.size() - 1).getOmemoMessage().getBody());
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class StreamManagementTest method testStreamManagement.
@SmackIntegrationTest
public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException {
final String body1 = "Hi, what's up? " + testRunId;
final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId;
final String body3 = "Hi, what's up? I've been just resumed" + testRunId;
final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter(MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser())));
try {
send(body1, conOne, conTwo);
assertMessageWithBodyReceived(body1, collector);
conOne.instantShutdown();
send(body2, conOne, conTwo);
// Reconnect with xep198
conOne.connect().login();
assertMessageWithBodyReceived(body2, collector);
send(body3, conOne, conTwo);
assertMessageWithBodyReceived(body3, collector);
} finally {
collector.cancel();
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class PubSubIntegrationTest method transientNotificationOnlyNodeWithItemTest.
/**
*/
/**
* Asserts that an error is returned when a publish request to a node that is both
* 'notification-only' as well as 'transient' contains an item element.
*
* <p>From XEP-0060 ยง 7.1.3.6:</p>
* <blockquote>
* If the event type is notification + transient and the publisher provides an item,
* the service MUST bounce the publication request with a <bad-request/> error
* and a pubsub-specific error condition of <item-forbidden/>.
* </blockquote>
*
* @throws NoResponseException if there was no response from the remote entity.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @see <a href="https://xmpp.org/extensions/xep-0060.html#publisher-publish-error-badrequest">
* 7.1.3.6 Request Does Not Match Configuration</a>
*/
@SmackIntegrationTest
public void transientNotificationOnlyNodeWithItemTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final String nodename = "sinttest-transient-notificationonly-withitem-nodename-" + testRunId;
final String itemId = "sinttest-transient-notificationonly-withitem-itemid-" + testRunId;
ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
FillableConfigureForm config = defaultConfiguration.getFillableForm();
// Configure the node as "Notification-Only Node".
config.setDeliverPayloads(false);
// Configure the node as "transient" (set persistent_items to 'false')
config.setPersistentItems(false);
Node node = pubSubManagerOne.createNode(nodename, config);
// Add a dummy payload. If there is no payload, but just an item ID, then ejabberd will *not* return an error,
// which I believe to be non-compliant behavior (although, granted, the XEP is not very clear about this). A user
// which sends an empty item with ID to an node that is configured to be notification-only and transient probably
// does something wrong, as the item's ID will never appear anywhere. Hence it would be nice if the user would be
// made aware of this issue by returning an error. Sadly ejabberd does not do so.
// See also https://github.com/processone/ejabberd/issues/2864#issuecomment-500741915
final StandardExtensionElement dummyPayload = StandardExtensionElement.builder("dummy-payload", SmackConfiguration.SMACK_URL_STRING).setText(testRunId).build();
try {
XMPPErrorException e = assertThrows(XMPPErrorException.class, () -> {
LeafNode leafNode = (LeafNode) node;
Item item = new PayloadItem<>(itemId, dummyPayload);
leafNode.publish(item);
});
assertEquals(StanzaError.Type.MODIFY, e.getStanzaError().getType());
assertNotNull(e.getStanzaError().getExtension("item-forbidden", "http://jabber.org/protocol/pubsub#errors"));
} finally {
pubSubManagerOne.deleteNode(nodename);
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class PubSubIntegrationTest method transientNotificationOnlyNodeWithoutItemTest.
/**
* Asserts that an event notification (publication without item) can be published to
* a node that is both 'notification-only' as well as 'transient'.
*
* @throws NoResponseException if there was no response from the remote entity.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
@SmackIntegrationTest
public void transientNotificationOnlyNodeWithoutItemTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final String nodename = "sinttest-transient-notificationonly-withoutitem-nodename-" + testRunId;
ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
FillableConfigureForm config = defaultConfiguration.getFillableForm();
// Configure the node as "Notification-Only Node".
config.setDeliverPayloads(false);
// Configure the node as "transient" (set persistent_items to 'false')
config.setPersistentItems(false);
Node node = pubSubManagerOne.createNode(nodename, config);
try {
LeafNode leafNode = (LeafNode) node;
leafNode.publish();
} finally {
pubSubManagerOne.deleteNode(nodename);
}
}
use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.
the class UserTuneIntegrationTest method testNotificationAfterFilterChange.
/**
* Verifies that a notification for a previously sent publication is received as soon as notification filtering
* has been adjusted to allow for the notification to be delivered.
*
* @throws Exception if the test fails
*/
@SmackIntegrationTest
public void testNotificationAfterFilterChange() throws Exception {
URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#8");
UserTuneElement.Builder builder = UserTuneElement.getBuilder();
UserTuneElement data = builder.setArtist("No").setLength(306).setRating(3).setSource("NoSongs").setTitle("Sunrise of the Heart").setTrack("2").setUri(uri).build();
IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
final SimpleResultSyncPoint userTuneReceived = new SimpleResultSyncPoint();
final PepEventListener<UserTuneElement> userTuneListener = (jid, userTune, id, message) -> {
if (userTune.equals(data)) {
userTuneReceived.signal();
}
};
// TODO Ensure that pre-existing filtering notification excludes userTune.
try {
// Publish the data
publishAndWait(utm1, ServiceDiscoveryManager.getInstanceFor(conOne), data);
// Adds listener, which implicitly publishes a disco/info filter for userTune notification.
registerListenerAndWait(utm2, ServiceDiscoveryManager.getInstanceFor(conTwo), userTuneListener);
// Wait for the data to be received.
try {
Object result = userTuneReceived.waitForResult(timeout);
// Explicitly assert the success case.
Assertions.assertNotNull(result, "Expected to receive a PEP notification, but did not.");
} catch (TimeoutException e) {
Assertions.fail("Expected to receive a PEP notification, but did not.");
}
} finally {
unregisterListener(utm2, userTuneListener);
}
}
Aggregations