Search in sources :

Example 26 with SmackIntegrationTest

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());
}
Also used : MamManager(org.jivesoftware.smackx.mam.MamManager) MessageOrOmemoMessage(org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) MessageOrOmemoMessage(org.jivesoftware.smackx.omemo.util.MessageOrOmemoMessage) XMPPConnection(org.jivesoftware.smack.XMPPConnection) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 27 with SmackIntegrationTest

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();
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 28 with SmackIntegrationTest

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 &lt;bad-request/&gt; error
 * and a pubsub-specific error condition of &lt;item-forbidden/&gt;.
 * </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);
    }
}
Also used : FillableConfigureForm(org.jivesoftware.smackx.pubsub.form.FillableConfigureForm) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) ConfigureForm(org.jivesoftware.smackx.pubsub.form.ConfigureForm) FillableConfigureForm(org.jivesoftware.smackx.pubsub.form.FillableConfigureForm) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 29 with SmackIntegrationTest

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);
    }
}
Also used : FillableConfigureForm(org.jivesoftware.smackx.pubsub.form.FillableConfigureForm) ConfigureForm(org.jivesoftware.smackx.pubsub.form.ConfigureForm) FillableConfigureForm(org.jivesoftware.smackx.pubsub.form.FillableConfigureForm) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 30 with SmackIntegrationTest

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);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) URI(java.net.URI) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)66 EntityBareJid (org.jxmpp.jid.EntityBareJid)30 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)25 XMPPException (org.jivesoftware.smack.XMPPException)23 SmackException (org.jivesoftware.smack.SmackException)20 Resourcepart (org.jxmpp.jid.parts.Resourcepart)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)17 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)17 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 Message (org.jivesoftware.smack.packet.Message)9 TimeoutException (java.util.concurrent.TimeoutException)8 Presence (org.jivesoftware.smack.packet.Presence)7 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)6 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)6 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)6 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)6 Assertions (org.junit.jupiter.api.Assertions)6