2004-12-29 03:17:27 +01:00
|
|
|
/**
|
|
|
|
* $RCSfile$
|
|
|
|
* $Revision$
|
|
|
|
* $Date$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jive Software. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is published under the terms of the GNU Public License (GPL),
|
|
|
|
* a copy of which is included in this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smack;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.test.SmackTestCase;
|
2005-09-13 22:05:29 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2004-12-29 03:17:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Includes set of login tests.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
public class LoginTest extends SmackTestCase {
|
|
|
|
|
|
|
|
public LoginTest(String arg0) {
|
|
|
|
super(arg0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the server is returning the correct error when trying to login using an invalid
|
|
|
|
* (i.e. non-existent) user.
|
|
|
|
*/
|
|
|
|
public void testInvalidLogin() {
|
|
|
|
try {
|
|
|
|
XMPPConnection connection = new XMPPConnection(getHost(), getPort());
|
|
|
|
try {
|
|
|
|
// Login with an invalid user
|
|
|
|
connection.login("invaliduser" , "invalidpass");
|
|
|
|
connection.close();
|
|
|
|
fail("Invalid user was able to log into the server");
|
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
2005-09-13 22:05:29 +02:00
|
|
|
if (e.getXMPPError() != null) {
|
|
|
|
assertEquals("Incorrect error code while login with an invalid user", 401,
|
|
|
|
e.getXMPPError().getCode());
|
|
|
|
}
|
2004-12-29 03:17:27 +01:00
|
|
|
}
|
|
|
|
// Wait here while trying tests with exodus
|
|
|
|
//Thread.sleep(300);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that the server handles anonymous users correctly.
|
|
|
|
*/
|
|
|
|
public void testAnonymousLogin() {
|
|
|
|
try {
|
2004-12-31 05:34:24 +01:00
|
|
|
XMPPConnection conn1 = new XMPPConnection(getHost(), getPort());
|
|
|
|
XMPPConnection conn2 = new XMPPConnection(getHost(), getPort());
|
2004-12-29 03:17:27 +01:00
|
|
|
try {
|
|
|
|
// Try to login anonymously
|
2004-12-31 05:34:24 +01:00
|
|
|
conn1.loginAnonymously();
|
|
|
|
conn2.loginAnonymously();
|
2004-12-29 03:17:27 +01:00
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
// Close the connection
|
2004-12-31 05:34:24 +01:00
|
|
|
conn1.close();
|
|
|
|
conn2.close();
|
2004-12-29 03:17:27 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-14 05:24:04 +02:00
|
|
|
/**
|
|
|
|
* Check that the server does not allow to log in without specifying a resource.
|
|
|
|
*/
|
|
|
|
public void testLoginWithNoResource() {
|
|
|
|
try {
|
|
|
|
XMPPConnection conn = new XMPPConnection(getHost(), getPort());
|
|
|
|
try {
|
|
|
|
conn.getAccountManager().createAccount("user_1", "user_1");
|
|
|
|
} catch (XMPPException e) {
|
|
|
|
// Do nothing if the accout already exists
|
|
|
|
if (e.getXMPPError().getCode() != 409) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conn.login("user_1", "user_1", null);
|
2005-09-13 22:05:29 +02:00
|
|
|
if (conn.getSASLAuthentication().isAuthenticated()) {
|
|
|
|
// Check that the server assigned a resource
|
|
|
|
assertNotNull("JID assigned by server is missing", conn.getUser());
|
|
|
|
assertNotNull("JID assigned by server does not have a resource",
|
|
|
|
StringUtils.parseResource(conn.getUser()));
|
|
|
|
conn.close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fail("User with no resource was able to log into the server");
|
|
|
|
}
|
2005-04-14 05:24:04 +02:00
|
|
|
|
|
|
|
} catch (XMPPException e) {
|
|
|
|
assertEquals("Wrong error code returned", 406, e.getXMPPError().getCode());
|
|
|
|
}
|
|
|
|
}
|
2004-12-29 03:17:27 +01:00
|
|
|
|
|
|
|
protected int getMaxConnections() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|