diff --git a/documentation/developer/building.md b/documentation/developer/building.md
index 2e35e634b..84163fc7f 100644
--- a/documentation/developer/building.md
+++ b/documentation/developer/building.md
@@ -48,16 +48,3 @@ git clone git@github.com:igniterealtime/Smack.git
cd Smack
gradle assemble
```
-
-IDE Config
-----------
-
-### Eclipse
-
-Import IDE settings from `./resources/eclipse/` to configure proper ordering of imports and correct formatting that should pass the CheckStyle rules.
-
-### IntelliJ IDEA
-
-Import Java Code Style settings from `./resources/intellij/smack_formatter.xml` to configure import optimisation and code formatting to pass the CheckStyle rules when building or submitting PRs.
-
-_We've noticed, at time of writing, that IntelliJ often requires a restart when applying new rules - no amount of OK/Apply will do the trick._
diff --git a/documentation/developer/integrationtest.md b/documentation/developer/integrationtest.md
index 60f3142b8..fe006b58c 100644
--- a/documentation/developer/integrationtest.md
+++ b/documentation/developer/integrationtest.md
@@ -4,8 +4,8 @@ Smack's Integration Test Framework
Introduction
------------
-Smack's Integration Test Framework is used to run a set of tests against a real XMPP service.
-The framework discovers on start-up the available tests by reflection.
+Smack's Integration Test Framwork is used to run a set of tests against a real XMPP service.
+The framework discovers on startup the available tests by reflection.
Quickstart
----------
@@ -120,7 +120,7 @@ The methods are supposed to throw an exception if their integration test fails.
### `TestNotPossibleException`
-Can be thrown by test methods or constructors to signal that their test is not possible, e.g. because the service does not support the required feature.
+Can be thrown by test methods or constructors to signal that their test it no possible, e.g. because the service does not support the required feature.
Running the integration tests
-----------------------------
@@ -130,7 +130,6 @@ Smack's Gradle build system is configured with a special task called `integratio
```bash
$ gradle integrationTest -Dsinttest.service=my.xmppservice.org
```
-
If one of `accountOneUsername`, `accountOnePassword`, `accountTwoUsername` or `accountTwoPassword` is not configured, then the framework will automatically create the accounts on the service. Of course this requires account registration (IBR) to be enabled.
If the accounts got created automatically by the framework, then they will also be deleted at the end of the test.
@@ -162,19 +161,6 @@ The test methods can declare as many parameters as they need to, but every param
The framework will automatically create, register and login the connections.
After the test is finished, the connections will be unregistered with the XMPP service and terminated.
-Debugging Integration Tests
-------------------------------
-
-A test, like any other code, may not be perfect on the first attempt, and you may require more information in order to ascertain quite what's wrong.
-
-### Smack Debugger options
-
-As listed in the main Smack [Debugging](../debugging.md) doc, there are two built-in debuggers that could surface you more information. Using the 'enhanced' debugger config option listed above, you'll get the Smack Debug Window launching when your tests launch, and you'll get a stanza-by-stanza account of what happened on each connection, hopefully enough to diagnose what went wrong.
-
-### Debugging in the IDE
-
-If the output isn't enough, you may need to debug and inspect running code within the IDE. Depending on the IDE, in order to get execution to pause at your breakpoints, you may need to switch your configuration. Instead of running `gradle integrationTest`, instead run the `SmackIntegrationTestFramework` class directly with the same command-line options.
-
Running your own integration tests
----------------------------------
diff --git a/documentation/extensions/muc.md b/documentation/extensions/muc.md
index 40d7e2024..a89f2b22f 100644
--- a/documentation/extensions/muc.md
+++ b/documentation/extensions/muc.md
@@ -472,7 +472,7 @@ muc = manager.getMultiUserChat("myroom@conference.jabber.org");
muc.create("testbot");
// User1 (which is the room owner) configures the room as a moderated room
Form form = muc.getConfigurationForm();
-FillableForm answerForm = configForm.getFillableForm();
+Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_moderatedroom", "1");
muc.sendConfigurationForm(answerForm);
@@ -612,7 +612,7 @@ muc = manager.getMultiUserChat("myroom@conference.jabber.org");
muc.create("testbot");
// User1 (which is the room owner) configures the room as a moderated room
Form form = muc.getConfigurationForm();
-FillableForm answerForm = configForm.getFillableForm();
+Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_moderatedroom", "1");
muc.sendConfigurationForm(answerForm);
diff --git a/resources/intellij/Smack Import Order.xml b/resources/intellij/Smack Import Order.xml
new file mode 100644
index 000000000..3209e4f5f
--- /dev/null
+++ b/resources/intellij/Smack Import Order.xml
@@ -0,0 +1,18 @@
+
From XEP-0045 § 5.1.3:
+ *+ * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change + * to all occupants... + *+ * + *
From XEP-0045 § 9.6:
+ *+ * The service MUST then send updated presence from this individual to all occupants, indicating the addition of + * moderator status... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucRoleTestForReceivingModerator() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.1.3:
+ *+ * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change + * to all occupants... + *+ * + *
From XEP-0045 § 9.6:
+ *+ * The service MUST then send updated presence from this individual to all occupants, indicating the addition of + * moderator status... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucRoleTestForWitnessingModerator() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.1.3:
+ *+ * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change + * to all occupants... + *+ * + *
From XEP-0045 § 9.7:
+ *+ * The service MUST then send updated presence from this individual to all occupants, indicating the removal of + * moderator status... + *+ * + * @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
From XEP-0045 § 5.1.3:
+ *+ * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change + * to all occupants... + *+ * + *
From XEP-0045 § 9.7:
+ *+ * The service MUST then send updated presence from this individual to all occupants, indicating the removal of + * moderator status... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucRoleTestForWitnessingModeratorRemoval() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.1.3:
+ *+ * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change + * to all occupants... + *+ * + *
From XEP-0045 § 8.4:
+ *+ * The service MUST then send updated presence from this individual to all occupants, indicating the removal of + * voice privileges... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucRoleTestForRevokingVoice() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.1.3:
+ *+ * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change + * to all occupants... + *+ * + *
From XEP-0045 § 8.4:
+ *+ * The service MUST then send updated presence from this individual to all occupants, indicating the removal of + * voice privileges... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucRoleTestForWitnessingRevokingVoice() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.2.2:
+ *+ * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that + * to all occupants... + *+ * + *
From XEP-0045 § 10.6:
+ *+ * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, + * indicating the granting of admin status... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucAffiliationTestForReceivingAdmin() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.2.2:
+ *+ * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that + * to all occupants... + *+ * + *
From XEP-0045 § 10.6:
+ *+ * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, + * indicating the granting of admin status... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucAffiliationTestForWitnessingAdmin() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.2.2:
+ *+ * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that to + * all occupants... + *+ * + *
From XEP-0045 § 10.7:
+ *+ * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, + * indicating the loss of admin status by sending a presence element... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucAffiliationTestForRemovingAdmin() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 5.2.2:
+ *+ * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that to + * all occupants... + *+ * + *
From XEP-0045 § 10.7:
+ *+ * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, + * indicating the loss of admin status by sending a presence element... + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucAffiliationTestForWitnessingAdminRemoval() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); + + final ResultSyncPoint
From XEP-0045 § 8.2:
+ *+ * The kick is performed based on the occupant's room nickname and is completed by setting the role of a + * participant or visitor to a value of "none". + * + * The service MUST remove the kicked occupant by sending a presence stanza of type "unavailable" to each kicked + * occupant, including status code 307 in the extended presence information, optionally along with the reason (if + * provided) and the roomnick or bare JID of the user who initiated the kick. + *+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucPresenceTestForGettingKicked() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + + createMUC(mucAsSeenByOne, "one-" + randomString); + final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); + mucAsSeenByTwo.join(nicknameTwo); + + final ResultSyncPoint
From XEP-0045 § 8.2:
+ *+ * ...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 (<room@service/nick>) 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. + *+ * + * @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); + final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); + final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); + mucAsSeenByTwo.join(nicknameTwo); + mucAsSeenByThree.join(nicknameThree); + + final ResultSyncPoint
From XEP-0045 § 10.9:
*@@ -158,7 +760,7 @@ public class MultiUserChatIntegrationTest extends AbstractMultiUserChatIntegrati @SmackIntegrationTest public void mucDestroyTest() throws TimeoutException, Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest-destroy"); + EntityBareJid mucAddress = getRandomRoom("smack-inttest-join-leave"); MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress); muc.join(Resourcepart.from("nick-one")); @@ -191,6 +793,37 @@ public class MultiUserChatIntegrationTest extends AbstractMultiUserChatIntegrati assertNull(muc.getNickname()); } + /** + * Gets a random room name + * + * @param prefix A prefix to add to the room name for descriptive purposes + */ + private EntityBareJid getRandomRoom(String prefix) throws XmppStringprepException { + final String roomNameLocal = String.join("-", prefix, testRunId, StringUtils.insecureRandomString(6)); + return JidCreate.entityBareFrom(Localpart.from(roomNameLocal), mucService.getDomain()); + } + /** + * Destroys a MUC room, ignoring any exceptions. + * + * @param muc The room to destroy (can be null). + * @throws InterruptedException if the calling thread was interrupted. + * @throws NotConnectedException if the XMPP connection is not connected. + * @throws XMPPErrorException if there was an XMPP error returned. + * @throws NoResponseException if there was no response from the remote entity. + */ + static void tryDestroy(final MultiUserChat muc) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + if (muc == null) { + return; + } + muc.destroy("test fixture teardown", null); + } + + private static void createMUC(MultiUserChat muc, String resourceName) throws NoResponseException, XMPPErrorException, InterruptedException, MultiUserChatException.MucAlreadyJoinedException, NotConnectedException, MultiUserChatException.MissingMucCreationAcknowledgeException, MultiUserChatException.NotAMucServiceException, XmppStringprepException { + MucCreateConfigFormHandle handle = muc.create(Resourcepart.from(resourceName)); + if (handle != null) { + handle.makeInstant(); + } + } } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatRolesAffiliationsPrivilegesIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatRolesAffiliationsPrivilegesIntegrationTest.java deleted file mode 100644 index 966ec3e97..000000000 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatRolesAffiliationsPrivilegesIntegrationTest.java +++ /dev/null @@ -1,622 +0,0 @@ -/** - * - * Copyright 2021 Florian Schmaus - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jivesoftware.smackx.muc; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smackx.muc.packet.MUCUser; - -import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; -import org.igniterealtime.smack.inttest.TestNotPossibleException; -import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest; -import org.igniterealtime.smack.inttest.util.ResultSyncPoint; -import org.jxmpp.jid.EntityBareJid; -import org.jxmpp.jid.EntityFullJid; -import org.jxmpp.jid.Jid; -import org.jxmpp.jid.parts.Resourcepart; - - -public class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest extends AbstractMultiUserChatIntegrationTest{ - - public MultiUserChatRolesAffiliationsPrivilegesIntegrationTest(SmackIntegrationTestEnvironment environment) - throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, - InterruptedException, TestNotPossibleException { - super(environment); - } - - /** - * Asserts that a user who undergoes a role change receives that change as a presence update - * - *From XEP-0045 § 5.1.3:
- *- * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change - * to all occupants... - *- * - *From XEP-0045 § 9.6:
- *- * The service MUST then send updated presence from this individual to all occupants, indicating the addition of - * moderator status... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucRoleTestForReceivingModerator() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() { - @Override - public void moderatorGranted() { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - - // This implicitly tests "The service MUST add the user to the moderator list and then inform the admin of - // success" in §9.6, since it'll throw on either an error IQ or on no response. - mucAsSeenByOne.grantModerator(nicknameTwo); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who is present when another user undergoes a role change receives that change as a presence update - * - * From XEP-0045 § 5.1.3:
- *- * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change - * to all occupants... - *- * - *From XEP-0045 § 9.6:
- *- * The service MUST then send updated presence from this individual to all occupants, indicating the addition of - * moderator status... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucRoleTestForWitnessingModerator() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByThree.addParticipantStatusListener(new ParticipantStatusListener() { - @Override - public void moderatorGranted(EntityFullJid participant) { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByThree.join(nicknameThree); - - mucAsSeenByOne.grantModerator(nicknameTwo); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - - } - - /** - * Asserts that a user who undergoes a role change receives that change as a presence update - * - * From XEP-0045 § 5.1.3:
- *- * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change - * to all occupants... - *- * - *From XEP-0045 § 9.7:
- *- * The service MUST then send updated presence from this individual to all occupants, indicating the removal of - * moderator status... - *- * - * @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 ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() { - @Override - public void moderatorRevoked() { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - - mucAsSeenByOne.grantModerator(nicknameTwo); - mucAsSeenByOne.revokeModerator(nicknameTwo); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who is present when another user undergoes a role change receives that change as a presence update - * - * From XEP-0045 § 5.1.3:
- *- * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change - * to all occupants... - *- * - *From XEP-0045 § 9.7:
- *- * The service MUST then send updated presence from this individual to all occupants, indicating the removal of - * moderator status... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucRoleTestForWitnessingModeratorRemoval() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByThree.addParticipantStatusListener(new ParticipantStatusListener() { - @Override - public void moderatorRevoked(EntityFullJid participant) { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByThree.join(nicknameThree); - - mucAsSeenByOne.grantModerator(nicknameTwo); - mucAsSeenByOne.revokeModerator(nicknameTwo); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user in an unmoderated room who undergoes an afilliation change receives that change as a presence update - * - * From XEP-0045 § 5.1.3:
- *- * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change - * to all occupants... - *- * - *From XEP-0045 § 8.4:
- *- * The service MUST then send updated presence from this individual to all occupants, indicating the removal of - * voice privileges... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucRoleTestForRevokingVoice() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() { - @Override - public void voiceRevoked() { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByOne.revokeVoice(nicknameTwo); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who is present when another user undergoes a role change receives that change as a presence update - * - * From XEP-0045 § 5.1.3:
- *- * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change - * to all occupants... - *- * - *From XEP-0045 § 8.4:
- *- * The service MUST then send updated presence from this individual to all occupants, indicating the removal of - * voice privileges... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucRoleTestForWitnessingRevokingVoice() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByThree.addParticipantStatusListener(new ParticipantStatusListener() { - @Override - public void voiceRevoked(EntityFullJid participant) { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByThree.join(nicknameThree); - - mucAsSeenByOne.revokeVoice(nicknameTwo); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who undergoes an affiliation change receives that change as a presence update - * - * From XEP-0045 § 5.2.2:
- *- * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that - * to all occupants... - *- * - *From XEP-0045 § 10.6:
- *- * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, - * indicating the granting of admin status... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucAffiliationTestForReceivingAdmin() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - - mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() { - @Override - public void adminGranted() { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - - // This implicitly tests "The service MUST add the user to the admin list and then inform the owner of success" in §10.6, since it'll throw on either an error IQ or on no response. - mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid()); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who is present when another user undergoes an affiliation change receives that change as a - * presence update - * - * From XEP-0045 § 5.2.2:
- *- * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that - * to all occupants... - *- * - *From XEP-0045 § 10.6:
- *- * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, - * indicating the granting of admin status... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucAffiliationTestForWitnessingAdmin() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByThree.addParticipantStatusListener(new ParticipantStatusListener() { - @Override - public void adminGranted(EntityFullJid participant) { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByThree.join(nicknameThree); - - mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid()); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who undergoes an affiliation change receives that change as a presence update - * - * From XEP-0045 § 5.2.2:
- *- * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that to - * all occupants... - *- * - *From XEP-0045 § 10.7:
- *- * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, - * indicating the loss of admin status by sending a presence element... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucAffiliationTestForRemovingAdmin() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() { - @Override - public void adminRevoked() { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - - mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid()); - mucAsSeenByOne.revokeAdmin(conTwo.getUser().asEntityBareJid()); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who is present when another user undergoes an affiliation change receives that change as a presence update - * - * From XEP-0045 § 5.2.2:
- *- * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that to - * all occupants... - *- * - *From XEP-0045 § 10.7:
- *- * If the user is in the room, the service MUST then send updated presence from this individual to all occupants, - * indicating the loss of admin status by sending a presence element... - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucAffiliationTestForWitnessingAdminRemoval() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - - mucAsSeenByThree.addParticipantStatusListener(new ParticipantStatusListener() { - @Override - public void adminRevoked(EntityFullJid participant) { - resultSyncPoint.signal("done"); - } - }); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByThree.join(nicknameThree); - mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid()); - - mucAsSeenByOne.revokeAdmin(conTwo.getUser().asEntityBareJid()); - try { - resultSyncPoint.waitForResult(timeout); - } finally { - tryDestroy(mucAsSeenByOne); - } - } - - /** - * Asserts that a user who gets kicked receives that change as a presence update - * - * From XEP-0045 § 8.2:
- *- * The kick is performed based on the occupant's room nickname and is completed by setting the role of a - * participant or visitor to a value of "none". - * - * The service MUST remove the kicked occupant by sending a presence stanza of type "unavailable" to each kicked - * occupant, including status code 307 in the extended presence information, optionally along with the reason (if - * provided) and the roomnick or bare JID of the user who initiated the kick. - *- * - * @throws Exception when errors occur - */ - @SmackIntegrationTest - public void mucPresenceTestForGettingKicked() throws Exception { - EntityBareJid mucAddress = getRandomRoom("smack-inttest"); - - MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); - MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); - - createMuc(mucAsSeenByOne, "one-" + randomString); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - mucAsSeenByTwo.addParticipantListener(kickPresence -> resultSyncPoint.signal(kickPresence)); - - mucAsSeenByOne.kickParticipant(nicknameTwo, "Nothing personal. Just a test."); - try { - Presence kickPresence = resultSyncPoint.waitForResult(timeout); - MUCUser mucUser = MUCUser.from(kickPresence); - assertNotNull(mucUser); - assertAll( - () -> assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110), "Missing 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); - } - } - - /** - * Asserts that a user who is present when another user gets kicked receives that change as a presence update - * - * From XEP-0045 § 8.2:
- *- * ...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 (<room@service/nick>) 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. - *- * - * @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); - final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); - final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); - mucAsSeenByTwo.join(nicknameTwo); - mucAsSeenByThree.join(nicknameThree); - - final ResultSyncPointresultSyncPoint = new ResultSyncPoint<>(); - mucAsSeenByThree.addParticipantListener(kickPresence -> resultSyncPoint.signal(kickPresence)); - - mucAsSeenByOne.kickParticipant(nicknameTwo, "Nothing personal. Just a test."); - try { - 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); - } - - } - -} diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java index 1720c0725..1057e695c 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; @@ -64,7 +63,7 @@ public abstract class AbstractTwoUsersOmemoIntegrationTest extends AbstractOmemo } @AfterClass - public void cleanUp() throws IOException, NotConnectedException, InterruptedException { + public void cleanUp() throws IOException { alice.stopStanzaAndPEPListeners(); bob.stopStanzaAndPEPListeners(); OmemoManagerSetupHelper.cleanUpPubSub(alice); diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java index 1a8093d63..467650409 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java @@ -22,10 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.HashMap; -import java.util.List; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.roster.Roster; @@ -33,9 +31,12 @@ import org.jivesoftware.smack.roster.RosterEntry; import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException; import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException; +import org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList; import org.jivesoftware.smackx.omemo.internal.OmemoDevice; import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint; +import org.jivesoftware.smackx.omemo.util.OmemoConstants; import org.jivesoftware.smackx.pubsub.PubSubException; +import org.jivesoftware.smackx.pubsub.PubSubManager; import com.google.common.collect.Maps; @@ -123,10 +124,48 @@ public class OmemoManagerSetupHelper { } } - public static void cleanUpPubSub(OmemoManager omemoManager) - throws IOException, NotConnectedException, InterruptedException { - List exceptions = omemoManager.purgeEverything(); - assertTrue(exceptions.isEmpty(), "There where exceptions while purging OMEMO: " + exceptions); + public static void cleanUpPubSub(OmemoManager omemoManager) throws IOException { + PubSubManager pm = PubSubManager.getInstanceFor(omemoManager.getConnection(), omemoManager.getOwnJid()); + try { + omemoManager.requestDeviceListUpdateFor(omemoManager.getOwnJid()); + } catch (SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException e) { + // ignore + } + + OmemoCachedDeviceList deviceList = OmemoService.getInstance().getOmemoStoreBackend() + .loadCachedDeviceList(omemoManager.getOwnDevice(), omemoManager.getOwnJid()); + + for (int id : deviceList.getAllDevices()) { + try { + pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems(); + } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | + PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException | + PubSubException.NotAPubSubNodeException e) { + // Silent + } + + try { + pm.deleteNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)); + } catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException + | XMPPException.XMPPErrorException e) { + // Silent + } + } + + try { + pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems(); + } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | + PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException | + PubSubException.NotAPubSubNodeException e) { + // Silent + } + + try { + pm.deleteNode(OmemoConstants.PEP_NODE_DEVICE_LIST); + } catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | + XMPPException.XMPPErrorException e) { + // Silent + } } public static void cleanUpRoster(OmemoManager omemoManager) { diff --git a/smack-java8-full/src/test/java/org/jivesoftware/smack/full/ModularXmppClientToServerConnectionStateGraphTest.java b/smack-java8-full/src/test/java/org/jivesoftware/smack/full/ModularXmppClientToServerConnectionStateGraphTest.java index 961e7527d..624679481 100644 --- a/smack-java8-full/src/test/java/org/jivesoftware/smack/full/ModularXmppClientToServerConnectionStateGraphTest.java +++ b/smack-java8-full/src/test/java/org/jivesoftware/smack/full/ModularXmppClientToServerConnectionStateGraphTest.java @@ -1,6 +1,6 @@ /** * - * Copyright 2020-2021 Florian Schmaus + * Copyright 2020 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.jivesoftware.smack.full; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.io.PrintWriter; @@ -26,8 +25,6 @@ import java.io.StringWriter; import java.net.URL; import java.nio.charset.StandardCharsets; -import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration; -import org.jivesoftware.smack.compression.CompressionModuleDescriptor; import org.jivesoftware.smack.util.EqualsUtil; import org.jivesoftware.smack.util.HashCode; @@ -37,7 +34,6 @@ import org.jgrapht.graph.DirectedPseudograph; import org.jgrapht.io.DOTImporter; import org.jgrapht.io.ImportException; import org.junit.jupiter.api.Test; -import org.jxmpp.stringprep.XmppStringprepException; public class ModularXmppClientToServerConnectionStateGraphTest { @@ -84,24 +80,4 @@ public class ModularXmppClientToServerConnectionStateGraphTest { assertEquals(expectedStateGraph, currentStateGraph); } - @Test - public void testNoUnknownStates() throws XmppStringprepException { - ModularXmppClientToServerConnectionConfiguration.builder() - .setUsernameAndPassword("user", "password") - .setXmppDomain("example.org") - .failOnUnknownStates() // This is the actual option that enableds this test. - .build(); - } - - @Test - public void throwsOnUnknownStates() throws XmppStringprepException { - assertThrows(IllegalStateException.class, () -> - ModularXmppClientToServerConnectionConfiguration.builder() - .setUsernameAndPassword("user", "password") - .setXmppDomain("example.org") - .removeModule(CompressionModuleDescriptor.class) - .failOnUnknownStates() // This is the actual option that enableds this test. - .build() - ); - } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java index 6bc5efcde..0d3131231 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java @@ -340,6 +340,7 @@ public class RTPBridge extends IQ { boolean done = false; XmlPullParser.Event eventType; + String elementName; if (!parser.getNamespace().equals(RTPBridge.NAMESPACE)) // TODO: Should be SmackParseException. @@ -355,9 +356,9 @@ public class RTPBridge extends IQ { // Start processing sub-elements while (!done) { eventType = parser.next(); + elementName = parser.getName(); if (eventType == XmlPullParser.Event.START_ELEMENT) { - String elementName = parser.getName(); if (elementName.equals("candidate")) { for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeName(i).equals("ip")) diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java index c6980994a..4980dc726 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java @@ -66,13 +66,14 @@ public abstract class JingleContentDescriptionProvider extends ExtensionElementP public JingleContentDescription parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { + boolean done = false; JingleContentDescription desc = getInstance(); - outerloop: while (true) { + while (!done) { XmlPullParser.Event eventType = parser.next(); + String name = parser.getName(); if (eventType == XmlPullParser.Event.START_ELEMENT) { - String name = parser.getName(); if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) { desc.addJinglePayloadType(parsePayload(parser)); } else { @@ -80,8 +81,8 @@ public abstract class JingleContentDescriptionProvider extends ExtensionElementP throw new IOException("Unknow element \"" + name + "\" in content."); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { - if (parser.getDepth() == initialDepth) { - break outerloop; + if (name.equals(JingleContentDescription.NODENAME)) { + done = true; } } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleDescriptionProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleDescriptionProvider.java index 2d912e020..3b15e4f90 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleDescriptionProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleDescriptionProvider.java @@ -65,12 +65,14 @@ public abstract class JingleDescriptionProvider extends ExtensionElementProvider */ @Override public JingleDescription parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { + boolean done = false; JingleDescription desc = getInstance(); - outerloop: while (true) { + while (!done) { XmlPullParser.Event eventType = parser.next(); + String name = parser.getName(); + if (eventType == XmlPullParser.Event.START_ELEMENT) { - String name = parser.getName(); if (name.equals(PayloadType.NODENAME)) { desc.addPayloadType(parsePayload(parser)); } else { @@ -78,8 +80,8 @@ public abstract class JingleDescriptionProvider extends ExtensionElementProvider throw new IOException("Unknow element \"" + name + "\" in content."); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { - if (parser.getDepth() == initialDepth) { - break outerloop; + if (name.equals(JingleDescription.NODENAME)) { + done = true; } } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java index 9f4627e26..0d6003351 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleProvider.java @@ -84,10 +84,10 @@ public class JingleProvider extends IQProvider { // Start processing sub-elements while (!done) { eventType = parser.next(); + elementName = parser.getName(); + namespace = parser.getNamespace(); if (eventType == XmlPullParser.Event.START_ELEMENT) { - elementName = parser.getName(); - namespace = parser.getNamespace(); // Parse some well know subelements, depending on the namespaces // and element names... diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java index 0edb7d887..1fe825482 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleTransportProvider.java @@ -54,13 +54,14 @@ public abstract class JingleTransportProvider extends ExtensionElementProvider purgeEverything() throws NotConnectedException, InterruptedException, IOException { - List exceptions = new ArrayList<>(5); - PubSubManager pm = PubSubManager.getInstanceFor(getConnection(), getOwnJid()); - try { - requestDeviceListUpdateFor(getOwnJid()); - } catch (SmackException.NoResponseException | PubSubException.NotALeafNodeException - | XMPPException.XMPPErrorException e) { - exceptions.add(e); - } - - OmemoCachedDeviceList deviceList = OmemoService.getInstance().getOmemoStoreBackend() - .loadCachedDeviceList(getOwnDevice(), getOwnJid()); - - for (int id : deviceList.getAllDevices()) { - try { - pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems(); - } catch (SmackException.NoResponseException | PubSubException.NotALeafNodeException - | XMPPException.XMPPErrorException | PubSubException.NotAPubSubNodeException e) { - exceptions.add(e); - } - - try { - pm.deleteNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)); - } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException e) { - exceptions.add(e); - } - } - - try { - pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems(); - } catch (SmackException.NoResponseException | PubSubException.NotALeafNodeException - | XMPPException.XMPPErrorException | PubSubException.NotAPubSubNodeException e) { - exceptions.add(e); - } - - try { - pm.deleteNode(OmemoConstants.PEP_NODE_DEVICE_LIST); - } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException e) { - exceptions.add(e); - } - - return exceptions; - } - /** * Rotate the signedPreKey published in our OmemoBundle and republish it. This should be done every now and * then (7-14 days). The old signedPreKey should be kept for some more time (a month or so) to enable decryption diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/provider/OmemoBundleVAxolotlProvider.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/provider/OmemoBundleVAxolotlProvider.java index 2a3b1739e..e45d35a48 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/provider/OmemoBundleVAxolotlProvider.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/provider/OmemoBundleVAxolotlProvider.java @@ -16,6 +16,7 @@ */ package org.jivesoftware.smackx.omemo.provider; +import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.BUNDLE; import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.IDENTITY_KEY; import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEYS; import static org.jivesoftware.smackx.omemo.element.OmemoBundleElement.PRE_KEY_ID; @@ -42,6 +43,7 @@ import org.jivesoftware.smackx.omemo.element.OmemoBundleElement_VAxolotl; public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider { @Override public OmemoBundleElement_VAxolotl parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { + boolean stop = false; boolean inPreKeys = false; int signedPreKeyId = -1; @@ -50,11 +52,11 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider preKeys = new HashMap<>(); - outerloop: while (true) { + while (!stop) { XmlPullParser.Event tag = parser.next(); + String name = parser.getName(); switch (tag) { case START_ELEMENT: - String name = parser.getName(); final int attributeCount = parser.getAttributeCount(); // if (name.equals(SIGNED_PRE_KEY_PUB)) { @@ -89,8 +91,8 @@ public class OmemoBundleVAxolotlProvider extends ExtensionElementProvider deviceListIds = new HashSet<>(); - outerloop: while (true) { + boolean stop = false; + while (!stop) { XmlPullParser.Event tag = parser.next(); + String name = parser.getName(); switch (tag) { case START_ELEMENT: - String name = parser.getName(); if (name.equals(DEVICE)) { for (int i = 0; i < parser.getAttributeCount(); i++) { if (parser.getAttributeName(i).equals(ID)) { @@ -55,8 +57,8 @@ public class OmemoDeviceListVAxolotlProvider extends ExtensionElementProvider keys = new ArrayList<>(); byte[] iv = null; byte[] payload = null; - outerloop: while (true) { + while (inEncrypted) { XmlPullParser.Event tag = parser.next(); + String name = parser.getName(); switch (tag) { case START_ELEMENT: - String name = parser.getName(); switch (name) { case OmemoHeaderElement.ELEMENT: for (int i = 0; i < parser.getAttributeCount(); i++) { @@ -80,8 +82,8 @@ public class OmemoVAxolotlProvider extends ExtensionElementProvider