Search in sources :

Example 1 with FillableConfigureForm

use of org.jivesoftware.smackx.pubsub.form.FillableConfigureForm 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 2 with FillableConfigureForm

use of org.jivesoftware.smackx.pubsub.form.FillableConfigureForm 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 3 with FillableConfigureForm

use of org.jivesoftware.smackx.pubsub.form.FillableConfigureForm in project Smack by igniterealtime.

the class OpenPgpPubSubUtil method changeAccessModelIfNecessary.

/**
 * Query the access model of {@code node}. If it is different from {@code accessModel}, change the access model
 * of the node to {@code accessModel}.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0060.html#accessmodels">XEP-0060 §4.5 - Node Access Models</a>
 *
 * @param node {@link LeafNode} whose PubSub access model we want to change
 * @param accessModel new access model.
 *
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error.
 * @throws SmackException.NotConnectedException if we are not connected.
 * @throws InterruptedException if the thread is interrupted.
 * @throws SmackException.NoResponseException if the server doesn't respond.
 */
public static void changeAccessModelIfNecessary(LeafNode node, AccessModel accessModel) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
    ConfigureForm current = node.getNodeConfiguration();
    if (current.getAccessModel() != accessModel) {
        FillableConfigureForm updateConfig = current.getFillableForm();
        updateConfig.setAccessModel(accessModel);
        node.sendConfigurationForm(updateConfig);
    }
}
Also used : FillableConfigureForm(org.jivesoftware.smackx.pubsub.form.FillableConfigureForm) ConfigureForm(org.jivesoftware.smackx.pubsub.form.ConfigureForm) FillableConfigureForm(org.jivesoftware.smackx.pubsub.form.FillableConfigureForm)

Aggregations

ConfigureForm (org.jivesoftware.smackx.pubsub.form.ConfigureForm)3 FillableConfigureForm (org.jivesoftware.smackx.pubsub.form.FillableConfigureForm)3 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)1