2013-02-07 15:19:47 +01:00
|
|
|
/**
|
|
|
|
*
|
2013-04-07 21:15:32 +02:00
|
|
|
* Copyright 2011 Robin Collier
|
2013-02-07 15:19:47 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-07 15:19:47 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2014-02-17 23:58:40 +01:00
|
|
|
package org.jivesoftware.smackx.pubsub;
|
2014-02-15 11:35:08 +01:00
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
import static org.junit.jupiter.api.Assertions.fail;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-12-17 13:31:22 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.SmackConfiguration;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException;
|
2014-01-31 04:41:25 +01:00
|
|
|
import org.jivesoftware.smack.ThreadedDummyConnection;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2019-10-29 11:14:55 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2018-04-07 21:25:40 +02:00
|
|
|
import org.jivesoftware.smack.packet.StanzaError;
|
|
|
|
import org.jivesoftware.smack.packet.StanzaError.Condition;
|
2020-04-12 09:34:08 +02:00
|
|
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
|
|
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity;
|
2019-10-29 11:14:55 +01:00
|
|
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2013-04-07 21:15:32 +02:00
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Configure form test.
|
2013-04-07 21:15:32 +02:00
|
|
|
* @author Robin Collier
|
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
2020-04-12 09:34:08 +02:00
|
|
|
public class ConfigureFormTest extends SmackTestSuite {
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
@Test
|
2018-04-06 10:21:46 +02:00
|
|
|
public void getConfigFormWithInsufficientPrivileges() throws XMPPException, SmackException, IOException, InterruptedException {
|
2017-02-07 22:02:40 +01:00
|
|
|
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
|
|
|
|
PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
|
2019-10-29 11:14:55 +01:00
|
|
|
DiscoverInfoBuilder info = DiscoverInfo.builder("disco-result")
|
|
|
|
.ofType(IQ.Type.result)
|
|
|
|
.from(PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
|
2017-02-07 22:02:40 +01:00
|
|
|
Identity ident = new Identity("pubsub", null, "leaf");
|
|
|
|
info.addIdentity(ident);
|
2019-10-29 11:14:55 +01:00
|
|
|
|
|
|
|
DiscoverInfo discoverInfo = info.build();
|
|
|
|
con.addIQReply(discoverInfo);
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
Node node = mgr.getNode("princely_musings");
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
PubSub errorIq = new PubSub();
|
2021-01-28 22:05:47 +01:00
|
|
|
errorIq.setType(IQ.Type.error);
|
2017-04-04 11:16:15 +02:00
|
|
|
errorIq.setFrom(PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
|
2019-10-24 15:45:08 +02:00
|
|
|
StanzaError error = StanzaError.getBuilder(Condition.forbidden).build();
|
2017-02-07 22:02:40 +01:00
|
|
|
errorIq.setError(error);
|
|
|
|
con.addIQReply(errorIq);
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2018-04-06 10:21:46 +02:00
|
|
|
try {
|
2017-02-07 22:02:40 +01:00
|
|
|
node.getNodeConfiguration();
|
2018-03-28 15:56:04 +02:00
|
|
|
fail();
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2018-04-06 10:21:46 +02:00
|
|
|
catch (XMPPErrorException e) {
|
2019-05-06 22:06:13 +02:00
|
|
|
assertEquals(StanzaError.Type.AUTH, e.getStanzaError().getType());
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
@Test
|
2020-04-28 10:26:24 +02:00
|
|
|
public void getConfigFormWithTimeout() throws XMPPException, InterruptedException, SmackException, IOException {
|
|
|
|
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
|
2017-02-07 22:02:40 +01:00
|
|
|
PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
|
2020-04-28 10:26:24 +02:00
|
|
|
DiscoverInfoBuilder info = DiscoverInfo.builder("disco-result")
|
|
|
|
.ofType(IQ.Type.result)
|
|
|
|
.from(PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
Identity ident = new Identity("pubsub", null, "leaf");
|
|
|
|
info.addIdentity(ident);
|
2019-10-29 11:14:55 +01:00
|
|
|
|
|
|
|
DiscoverInfo discoverInfo = info.build();
|
|
|
|
con.addIQReply(discoverInfo);
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2020-04-28 10:26:24 +02:00
|
|
|
Node node = mgr.getNode("princely_musings");
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2020-04-28 10:26:24 +02:00
|
|
|
SmackConfiguration.setDefaultReplyTimeout(100);
|
|
|
|
con.setTimeout();
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2020-04-28 10:26:24 +02:00
|
|
|
assertThrows(SmackException.class, () -> {
|
2020-04-06 13:25:07 +02:00
|
|
|
node.getNodeConfiguration();
|
|
|
|
});
|
2017-02-07 22:02:40 +01:00
|
|
|
}
|
2018-04-16 16:03:02 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|