public static EntityBareJid getBareJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException { final String jidString = parser.getAttributeValue("", name); if (jidString == null) { return null; } return JidCreate.entityBareFrom(jidString); }
public static void tlsTest(int runs, CharSequence jidCs, String password, String host, int port, String tlsPin, boolean shouldThrow) throws XmppStringprepException, KeyManagementException, NoSuchAlgorithmException { EntityBareJid jid = JidCreate.entityBareFrom(jidCs); for (int i = 0; i < runs; i++) { boolean res = tlsTest(jid, password, host, port, tlsPin, shouldThrow); if (!res) { throw new IllegalStateException(); } } }
public static boolean tlsTest(CharSequence jidCs, String password, String host, int port, String tlsPin, boolean shouldThrow) throws XmppStringprepException, KeyManagementException, NoSuchAlgorithmException { EntityBareJid jid = JidCreate.entityBareFrom(jidCs); return tlsTest(jid, password, host, port, tlsPin, shouldThrow); }
invitation.room = JidCreate.entityBareFrom(roomString);
@SmackIntegrationTest public void mucJoinLeaveTest() throws XmppStringprepException, NotAMucServiceException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException { EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-join-leave-" + randomString), mucService.getDomain()); MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress); muc.join(Resourcepart.from("nick-one")); Presence reflectedLeavePresence = muc.leave(); MUCUser mucUser = MUCUser.from(reflectedLeavePresence); assertNotNull(mucUser); assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110)); }
private static void populateStore(RosterStore store) throws IOException { store.addEntry(new RosterPacket.Item(JidCreate.entityBareFrom("geoff@example.com"), "geoff hurley"), ""); RosterPacket.Item item = new RosterPacket.Item(JidCreate.entityBareFrom("joe@example.com"), "joe stevens"); item.addGroupName("friends"); item.addGroupName("partners"); store.addEntry(item, ""); item = new RosterPacket.Item(JidCreate.entityBareFrom("higgins@example.com"), "higgins mcmann"); item.addGroupName("all"); item.addGroupName("friends"); store.addEntry(item, "v96"); }
public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection, String username, String password, String adminAccountUsername, String adminAccountPassword) throws InterruptedException, XMPPException, SmackException, IOException { connection.login(adminAccountUsername, adminAccountPassword); ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection); EntityBareJid userJid = JidCreate.entityBareFrom(Localpart.from(username), connection.getXMPPServiceDomain()); adminManager.addUser(userJid, password); connection.disconnect(); connection.connect(); return new UsernameAndPassword(username, password); }
protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException, UnsupportedEncodingException { EntityBareJid authzid = null; if (useAuthzid) { authzid = JidCreate.entityBareFrom("shazbat@xmpp.org"); } saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null); byte[] response = saslMechanism.evaluateChallenge(challengeBytes); String responseString = new String(response, StringUtils.UTF8); String[] responseParts = responseString.split(","); Map<String, String> responsePairs = new HashMap<String, String>(); for (String part : responseParts) { String[] keyValue = part.split("=", 2); String key = keyValue[0]; String value = keyValue[1].replace("\"", ""); responsePairs.put(key, value); } if (useAuthzid) { assertMapValue("authzid", "shazbat@xmpp.org", responsePairs); } else { assertTrue (!responsePairs.containsKey("authzid")); } assertMapValue("username", "florian", responsePairs); assertMapValue("realm", "xmpp.org", responsePairs); assertMapValue("digest-uri", "xmpp/xmpp.org", responsePairs); assertMapValue("qop", "auth", responsePairs); }
final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com"); assertNotNull("Can't get the roster from the provided connection!", roster); final StringBuilder sb = new StringBuilder(); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com"); assertNotNull("Can't get the roster from the provided connection!", roster); final StringBuilder sb = new StringBuilder(); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
private static Item vaglafItem() throws XmppStringprepException { Item item = new Item(JidCreate.entityBareFrom("vaglaf@example.com"), "vaglaf the only"); item.setItemType(ItemType.both); item.addGroupName("all"); item.addGroupName("friends"); item.addGroupName("partners"); return item; }
verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 3, roster.getEntries().size());
public void testDeleteRosterItem() throws Throwable { final BareJid contactJID = JidCreate.entityBareFrom("romeo@example.net"); assertTrue("The roster listener wasn't invoked for the deleted contact!", rosterListener.getDeletedAddresses().contains(contactJID)); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net"))); assertSame("Wrong number of roster entries (" + roster.getEntries() + ").", 2,
public void testAddRosterItem() throws Throwable { final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com"); final String contactName = "Nurse"; final String[] contactGroup = {"Servants"}; verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net"))); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString, String readingThingPassword, IotScenario scenario) throws Exception { final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString); final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString); final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder() .setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword) .setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled) .enableDefaultDebugger().build(); final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration .builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword) .setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled) .enableDefaultDebugger().build(); final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration); final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration); dataThingConnection.setReplyTimeout(TIMEOUT); readingThingConnection.setReplyTimeout(TIMEOUT); dataThingConnection.setUseStreamManagement(false); readingThingConnection.setUseStreamManagement(false); try { dataThingConnection.connect().login(); readingThingConnection.connect().login(); scenario.iotScenario(dataThingConnection, readingThingConnection); } finally { dataThingConnection.disconnect(); readingThingConnection.disconnect(); } }
@SmackIntegrationTest public void mucTest() throws Exception { EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain());
@SmackIntegrationTest public void testMucBookmarksAutojoin(XMPPTCPConnection connection) throws InterruptedException, TestNotPossibleException, XMPPException, SmackException, IOException { final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection); if (!bookmarkManager.isSupported()) { throw new TestNotPossibleException("Private data storage not supported"); } final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection); final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6)); final String randomMucName = StringUtils.randomString(6); final DomainBareJid mucComponent = multiUserChatManager.getMucServiceDomains().get(0); final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom( Localpart.from(randomMucName), mucComponent)); MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname); if (handle != null) { handle.makeInstant(); } muc.leave(); bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true, mucNickname, null); connection.disconnect(); connection.connect().login(); // MucBookmarkAutojoinManager is also able to do its task automatically // after every login, it's not deterministic when this will be finished. // So we trigger it manually here. MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences(); assertTrue(muc.isJoined()); // If the test went well, leave the MUC muc.leave(); }
/** * Tests that roster pushes with invalid from are ignored. * @throws XmppStringprepException * * @see <a href="http://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push">RFC 6121, Section 2.1.6</a> */ @Test public void testIgnoreInvalidFrom() throws XmppStringprepException { final BareJid spammerJid = JidCreate.entityBareFrom("spam@example.com"); RosterPacket packet = new RosterPacket(); packet.setType(Type.set); packet.setTo(connection.getUser()); packet.setFrom(JidCreate.entityBareFrom("mallory@example.com")); packet.addRosterItem(new Item(spammerJid, "Cool products!")); final String requestId = packet.getStanzaId(); // Simulate receiving the roster push connection.processStanza(packet); // Smack should reply with an error IQ ErrorIQ errorIQ = connection.getSentPacket(); assertEquals(requestId, errorIQ.getStanzaId()); assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition()); assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry(spammerJid)); }
final Item romeo = new Item(JidCreate.entityBareFrom("romeo@example.net"), "Romeo"); romeo.addGroupName("Friends"); romeo.setItemType(ItemType.both); final Item mercutio = new Item(JidCreate.entityBareFrom("mercutio@example.com"), "Mercutio"); mercutio.setItemType(ItemType.from); rosterResult.addRosterItem(mercutio); final Item benvolio = new Item(JidCreate.entityBareFrom("benvolio@example.net"), "Benvolio"); benvolio.setItemType(ItemType.both); rosterResult.addRosterItem(benvolio);
rosterPush.setVersion("v98"); Item item = new Item(JidCreate.entityBareFrom("vaglaf@example.com"), "vaglaf the only"); item.setItemType(ItemType.remove); rosterPush.addRosterItem(item); rosterListener.waitAndReset(); assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.entityBareFrom("vaglaf@example.com"))); assertEquals("Expect store version after push", "v98", store.getRosterVersion());