Search in sources :

Example 16 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForRemovingModerator.

/**
 * Asserts that a user who undergoes a role change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.1.3:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change
 * to all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 9.7:</p>
 * <blockquote>
 * The service MUST then send updated presence from this individual to all occupants, indicating the removal of
 * moderator status...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucRoleTestForRemovingModerator() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() {

        @Override
        public void moderatorRevoked() {
            resultSyncPoint.signal("done");
        }
    });
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByOne.grantModerator(nicknameTwo);
        mucAsSeenByOne.revokeModerator(nicknameTwo);
        resultSyncPoint.waitForResult(timeout);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 17 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestPersistentAffiliation.

/**
 * Asserts that an affiliation is persistent between visits to the room.
 *
 * <p>From XEP-0045 § 5.2:</p>
 * <blockquote>
 * These affiliations are long-lived in that they persist across a user's visits to the room and are not affected
 * by happenings in the room...Affiliations are granted, revoked, and maintained based on the user's bare JID, not
 * the nick as with roles.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestPersistentAffiliation() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
    final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
    final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
    final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
    createMuc(mucAsSeenByOne, nicknameOne);
    try {
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        mucAsSeenByOne.grantOwnership(conTwo.getUser().asBareJid());
        mucAsSeenByOne.grantAdmin(conThree.getUser().asBareJid());
        mucAsSeenByTwo.leave();
        mucAsSeenByThree.leave();
        Presence p2 = mucAsSeenByTwo.join(nicknameTwo);
        Presence p3 = mucAsSeenByThree.join(nicknameThree);
        assertEquals(MUCAffiliation.owner, MUCUser.from(p2).getItem().getAffiliation());
        assertEquals(MUCAffiliation.admin, MUCUser.from(p3).getItem().getAffiliation());
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 18 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestModeratorCannotBeRevokedFromHigherAffiliation.

/**
 * Asserts that a moderator cannot revoke moderator privileges from a moderator with a higher affiliation
 * than themselves.
 *
 * <p>From XEP-0045 § 5.1.3 and §5.2.1:</p>
 * <blockquote>
 * A moderator SHOULD NOT be allowed to revoke moderation privileges from someone with a higher affiliation than
 * themselves (i.e., an unaffiliated moderator SHOULD NOT be allowed to revoke moderation privileges from an admin
 * or an owner, and an admin SHOULD NOT be allowed to revoke moderation privileges from an owner)
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestModeratorCannotBeRevokedFromHigherAffiliation() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
    final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
    final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
    final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
    createModeratedMuc(mucAsSeenByOne, nicknameOne);
    try {
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
        mucAsSeenByOne.grantModerator(nicknameThree);
        // Admin cannot revoke from Owner
        XMPPException.XMPPErrorException xe1 = assertThrows(XMPPException.XMPPErrorException.class, () -> mucAsSeenByTwo.revokeModerator(nicknameOne));
        // Moderator cannot revoke from Admin
        XMPPException.XMPPErrorException xe2 = assertThrows(XMPPException.XMPPErrorException.class, () -> mucAsSeenByThree.revokeModerator(nicknameOne));
        // Moderator cannot revoke from Owner
        XMPPException.XMPPErrorException xe3 = assertThrows(XMPPException.XMPPErrorException.class, () -> mucAsSeenByThree.revokeModerator(nicknameTwo));
        assertEquals(xe1.getStanzaError().getCondition().toString(), "not-allowed");
        assertEquals(xe2.getStanzaError().getCondition().toString(), "not-allowed");
        assertEquals(xe3.getStanzaError().getCondition().toString(), "not-allowed");
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 19 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestModeratorCannotRevokeVoiceFromOwner.

/**
 * Asserts that a moderator cannot revoke voice from an owner
 *
 * <p>From XEP-0045 § 5.1.1:</p>
 * <blockquote>
 * A moderator MUST NOT be able to revoke voice privileges from an admin or owner
 * </blockquote>
 *
 * <p>From XEP-0045 § 8.4:</p>
 * <blockquote>
 * A moderator MUST NOT be able to revoke voice from a user whose affiliation is at or above the moderator's level.
 * In addition, a service MUST NOT allow the voice privileges of an admin or owner to be removed by anyone. If a
 * moderator attempts to revoke voice privileges from such a user, the service MUST deny the request and return a
 * &lt;not-allowed/&gt; error to the sender along with the offending item(s)
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestModeratorCannotRevokeVoiceFromOwner() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
    final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
    createModeratedMuc(mucAsSeenByOne, nicknameOne);
    try {
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByOne.grantModerator(nicknameTwo);
        XMPPException.XMPPErrorException xe = assertThrows(XMPPException.XMPPErrorException.class, () -> mucAsSeenByTwo.revokeVoice(nicknameOne));
        assertEquals(xe.getStanzaError().getCondition().toString(), "not-allowed");
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 20 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucPresenceTestForWitnessingKick.

/**
 * Asserts that a user who is present when another user gets kicked receives that change as a presence update
 *
 * <p>From XEP-0045 § 8.2:</p>
 * <blockquote>
 * ...the service MUST then inform all of the remaining occupants that the kicked occupant is no longer in the room
 * by sending presence stanzas of type "unavailable" from the individual's roomnick (&lt;room@service/nick&gt;) to all
 * the remaining occupants (just as it does when occupants exit the room of their own volition), including the
 * status code and optionally the reason and actor.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucPresenceTestForWitnessingKick() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        final ResultSyncPoint<Presence, Exception> resultSyncPoint = new ResultSyncPoint<>();
        mucAsSeenByThree.addParticipantListener(kickPresence -> resultSyncPoint.signal(kickPresence));
        mucAsSeenByOne.kickParticipant(nicknameTwo, "Nothing personal. Just a test.");
        Presence kickPresence = resultSyncPoint.waitForResult(timeout);
        MUCUser mucUser = MUCUser.from(kickPresence);
        assertNotNull(mucUser);
        assertAll(() -> assertFalse(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110), "Incorrect self-presence status code in kick presence"), () -> assertTrue(mucUser.getStatus().contains(MUCUser.Status.KICKED_307), "Missing kick status code in kick presence"), () -> assertEquals(MUCRole.none, mucUser.getItem().getRole(), "Role other than 'none' in kick presence"));
        Jid itemJid = mucUser.getItem().getJid();
        if (itemJid != null) {
            assertEquals(conTwo.getUser().asEntityFullJidIfPossible(), itemJid, "Incorrect kicked user in kick presence");
        }
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) Presence(org.jivesoftware.smack.packet.Presence) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Aggregations

EntityBareJid (org.jxmpp.jid.EntityBareJid)56 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)30 XMPPException (org.jivesoftware.smack.XMPPException)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)21 SmackException (org.jivesoftware.smack.SmackException)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)16 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)15 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 Presence (org.jivesoftware.smack.packet.Presence)6 Jid (org.jxmpp.jid.Jid)6 Message (org.jivesoftware.smack.packet.Message)5 ArrayList (java.util.ArrayList)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)4 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)4 UserJid (com.xabber.android.data.entity.UserJid)3 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2