From 17d9b742fc81398e453f01ff829fff14352add05 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 14 Jul 2024 12:10:34 +0200 Subject: [PATCH] [sinttest] Try to find MUC service where MUC creation is possible --- .../AbstractMultiUserChatIntegrationTest.java | 42 +++++++++++++++++-- .../MultiUserChatEntityIntegrationTest.java | 6 ++- .../muc/MultiUserChatIntegrationTest.java | 2 +- .../MultiUserChatLowLevelIntegrationTest.java | 10 ++++- .../MultiUserChatOccupantIntegrationTest.java | 6 ++- ...AffiliationsPrivilegesIntegrationTest.java | 8 +++- 6 files changed, 64 insertions(+), 10 deletions(-) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/AbstractMultiUserChatIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/AbstractMultiUserChatIntegrationTest.java index 0f803e97fc..b13b4df6eb 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/AbstractMultiUserChatIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/AbstractMultiUserChatIntegrationTest.java @@ -18,10 +18,16 @@ package org.jivesoftware.smackx.muc; import java.util.List; +import java.util.logging.Level; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.XMPPException.XMPPErrorException; +import org.jivesoftware.smack.packet.StanzaError; import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.muc.MultiUserChatException.MissingMucCreationAcknowledgeException; +import org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException; +import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; import org.jivesoftware.smackx.xdata.form.FillableForm; import org.jivesoftware.smackx.xdata.form.Form; @@ -47,7 +53,7 @@ public abstract class AbstractMultiUserChatIntegrationTest extends AbstractSmack public AbstractMultiUserChatIntegrationTest(SmackIntegrationTestEnvironment environment) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, - InterruptedException, TestNotPossibleException { + InterruptedException, TestNotPossibleException, MucAlreadyJoinedException, MissingMucCreationAcknowledgeException, NotAMucServiceException, XmppStringprepException { super(environment); mucManagerOne = MultiUserChatManager.getInstanceFor(conOne); mucManagerTwo = MultiUserChatManager.getInstanceFor(conTwo); @@ -55,10 +61,40 @@ public AbstractMultiUserChatIntegrationTest(SmackIntegrationTestEnvironment envi List services = mucManagerOne.getMucServiceDomains(); if (services.isEmpty()) { - throw new TestNotPossibleException("No MUC (XEP-45) service found"); + throw new TestNotPossibleException("No MUC (XEP-0045) service found"); } - mucService = services.get(0); + DomainBareJid needle = null; + for (final DomainBareJid service : services) { + MultiUserChat multiUserChat = null; + try { + String roomNameLocal = String.join("-", "smack-inttest-abstract", testRunId, StringUtils.insecureRandomString(6)); + EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from(roomNameLocal), service.getDomain()); + multiUserChat = mucManagerOne.getMultiUserChat(mucAddress); + + createMuc(multiUserChat, "test"); + + needle = service; + break; + } catch (XMPPException.XMPPErrorException e) { + mucCreationDisallowedOrThrow(e); + LOGGER.log(Level.FINER, "MUC service " + service + " does not allow MUC creation", e); + } finally { + tryDestroy(multiUserChat); + } + } + + if (needle == null) { + throw new TestNotPossibleException("No MUC (XEP-0045) service found that allows test users to createa new room. Considered MUC services: " + services); + } + mucService = needle; + } + + static void mucCreationDisallowedOrThrow(XMPPException.XMPPErrorException e) throws XMPPErrorException { + StanzaError.Condition condition = e.getStanzaError().getCondition(); + if (condition == StanzaError.Condition.not_allowed) + return; + throw e; } /** diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatEntityIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatEntityIntegrationTest.java index 54083165b7..aa30d5b78a 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatEntityIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatEntityIntegrationTest.java @@ -31,6 +31,9 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jivesoftware.smackx.muc.MultiUserChatException.MissingMucCreationAcknowledgeException; +import org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException; +import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; @@ -42,13 +45,14 @@ import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityFullJid; import org.jxmpp.jid.parts.Resourcepart; +import org.jxmpp.stringprep.XmppStringprepException; @SpecificationReference(document = "XEP-0045", version = "1.34.6") public class MultiUserChatEntityIntegrationTest extends AbstractMultiUserChatIntegrationTest { public MultiUserChatEntityIntegrationTest(SmackIntegrationTestEnvironment environment) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, - SmackException.NotConnectedException, InterruptedException, TestNotPossibleException { + SmackException.NotConnectedException, InterruptedException, TestNotPossibleException, MucAlreadyJoinedException, MissingMucCreationAcknowledgeException, NotAMucServiceException, XmppStringprepException { super(environment); } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java index 406f5e1649..e97cf4ac50 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java @@ -50,7 +50,7 @@ public class MultiUserChatIntegrationTest extends AbstractMultiUserChatIntegrati public MultiUserChatIntegrationTest(SmackIntegrationTestEnvironment environment) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, - InterruptedException, TestNotPossibleException { + InterruptedException, TestNotPossibleException, MucAlreadyJoinedException, MissingMucCreationAcknowledgeException, NotAMucServiceException, XmppStringprepException { super(environment); } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatLowLevelIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatLowLevelIntegrationTest.java index 3b81ce8401..c70e61c7eb 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatLowLevelIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatLowLevelIntegrationTest.java @@ -1,6 +1,6 @@ /** * - * Copyright 2015-2020 Florian Schmaus + * Copyright 2015-2024 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,13 @@ public void testMucBookmarksAutojoin(AbstractXMPPConnection connection) throws I final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom( Localpart.from(randomMucName), mucComponent)); - MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname); + MucCreateConfigFormHandle handle; + try { + handle = muc.createOrJoin(mucNickname); + } catch (XMPPException.XMPPErrorException e) { + AbstractMultiUserChatIntegrationTest.mucCreationDisallowedOrThrow(e); + throw new TestNotPossibleException("MUC service " + mucComponent + " does not allow MUC creation", e); + } if (handle != null) { handle.makeInstant(); } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java index c662ef3f1f..04ea0253c1 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java @@ -41,7 +41,10 @@ import org.jivesoftware.smack.packet.StanzaError; import org.jivesoftware.smack.sm.predicates.ForEveryMessage; import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.muc.MultiUserChatException.MissingMucCreationAcknowledgeException; +import org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException; import org.jivesoftware.smackx.muc.MultiUserChatException.MucConfigurationNotSupportedException; +import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; import org.jivesoftware.smackx.muc.packet.MUCItem; import org.jivesoftware.smackx.muc.packet.MUCUser; @@ -56,13 +59,14 @@ import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.parts.Resourcepart; +import org.jxmpp.stringprep.XmppStringprepException; @SpecificationReference(document = "XEP-0045", version = "1.34.6") public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatIntegrationTest { public MultiUserChatOccupantIntegrationTest(SmackIntegrationTestEnvironment environment) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, - SmackException.NotConnectedException, InterruptedException, TestNotPossibleException { + SmackException.NotConnectedException, InterruptedException, TestNotPossibleException, MucAlreadyJoinedException, MissingMucCreationAcknowledgeException, NotAMucServiceException, XmppStringprepException { super(environment); } 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 index 9c4eab22b0..9c88f47fe4 100644 --- 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 @@ -1,6 +1,6 @@ /** * - * Copyright 2021 Florian Schmaus, Dan Caseley + * Copyright 2021-2024 Florian Schmaus, Dan Caseley * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,9 @@ import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smackx.muc.MultiUserChatException.MissingMucCreationAcknowledgeException; +import org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException; +import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; import org.jivesoftware.smackx.muc.packet.MUCUser; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; @@ -45,6 +48,7 @@ import org.jxmpp.jid.Jid; import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.parts.Resourcepart; +import org.jxmpp.stringprep.XmppStringprepException; @SpecificationReference(document = "XEP-0045", version = "1.34.6") @@ -52,7 +56,7 @@ public class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest extends Abs public MultiUserChatRolesAffiliationsPrivilegesIntegrationTest(SmackIntegrationTestEnvironment environment) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, - InterruptedException, TestNotPossibleException { + InterruptedException, TestNotPossibleException, MucAlreadyJoinedException, MissingMucCreationAcknowledgeException, NotAMucServiceException, XmppStringprepException { super(environment); }