From 714907f6bc02164bf0995029174606cba11e2d8c Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Fri, 19 May 2006 12:47:47 +0000 Subject: [PATCH] Implemented Authorization Request/Response Formatting and spelling changes --- .../icq/ProtocolProviderServiceIcqImpl.java | 45 +++++---- .../protocol/icq/TestAccountInstallation.java | 91 +++++++++++-------- 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java index df259960e..067dd3958 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ProtocolProviderServiceIcqImpl.java @@ -15,18 +15,17 @@ import net.kano.joustsim.oscar.oscar.service.icbm.*; import net.java.sip.communicator.util.*; import net.kano.joustsim.oscar.oscar.loginstatus.*; -import net.java.sip.communicator.impl.protocol.icq.message.DefaultCmdFactory; -import net.kano.joscar.flap.FlapCommand; -import net.kano.joscar.flap.FlapPacketListener; -import net.kano.joscar.flap.FlapPacketEvent; -import net.kano.joscar.flapcmd.CloseFlapCmd; -import net.kano.joscar.snaccmd.auth.AuthResponse; -import net.kano.joustsim.oscar.oscar.service.Service; +import net.java.sip.communicator.impl.protocol.icq.message.*; +import net.kano.joscar.flap.*; +import net.kano.joscar.flapcmd.*; +import net.kano.joscar.snaccmd.auth.*; +import net.kano.joustsim.oscar.oscar.service.*; /** * An implementation of the protocol provider service over the AIM/ICQ protocol * * @author Emil Ivov + * @author Damian Minkov */ public class ProtocolProviderServiceIcqImpl implements ProtocolProviderService @@ -376,14 +375,15 @@ private void fireRegistrationStateChanged( State oldJoustSimState, if(newJoustSimStateInfo instanceof LoginFailureStateInfo) { - LoginFailureInfo loginFailer = + LoginFailureInfo loginFailure = ((LoginFailureStateInfo)newJoustSimStateInfo).getLoginFailureInfo(); - if(loginFailer instanceof AuthFailureInfo) + if(loginFailure instanceof AuthFailureInfo) { - - int code = ConnectionClosedListener. - convertAuthCodeToReasonCode((AuthFailureInfo)loginFailer); + AuthFailureInfo afi = (AuthFailureInfo)loginFailure; + logger.debug("AuthFailureInfo code : " + + afi.getErrorCode()); + int code = ConnectionClosedListener.convertAuthCodeToReasonCode(afi); reasonCode = ConnectionClosedListener. convertCodeToRegistrationStateChangeEvent(code); reason = ConnectionClosedListener.convertCodeToStringReason(code); @@ -586,7 +586,7 @@ public void gotMessage(Conversation c, MessageInfo minfo) } /** - * Fixture for late close conenction due to + * Fix for late close conenction due to * multiple logins. * Listening for incoming packets for the close command * when this is received we discconect the session to force it @@ -631,7 +631,7 @@ public void handleFlapPacket(FlapPacketEvent e) if (flapCommand instanceof CloseFlapCmd) { CloseFlapCmd closeCmd = (CloseFlapCmd)flapCommand; - logger.debug("received close command with code : " + closeCmd.getCode()); + logger.trace("received close command with code : " + closeCmd.getCode()); aimConnection.disconnect(); } @@ -641,6 +641,9 @@ public void handleFlapPacket(FlapPacketEvent e) * Converts the codes in the close command * or the lastCloseCode of OscarConnection to the states * which are registered in the service protocol events + * + * @param reasonCode int the reason of close connection + * @return int corresponding RegistrationStateChangeEvent */ static int convertCodeToRegistrationStateChangeEvent(int reasonCode) { @@ -674,6 +677,9 @@ static int convertCodeToRegistrationStateChangeEvent(int reasonCode) /** * returns the reason string corresponding to the code * in the close command + * + * @param reasonCode int the reason of close connection + * @return String describing the reason */ static String convertCodeToStringReason(int reasonCode) { @@ -705,12 +711,15 @@ static String convertCodeToStringReason(int reasonCode) } /** - * When receiving login failer - * the reasons for the failer are in the authorization + * When receiving login failure + * the reasons for the failure are in the authorization * part of the protocol ( 0x13 ) * In the AuthResponse are the possible reason codes * here they are converted to those in the ConnectionClosedListener * so the they can be converted to the one in service protocol events + * + * @param afi AuthFailureInfo the failure info + * @return int the corresponding code to this failure */ static int convertAuthCodeToReasonCode(AuthFailureInfo afi) { @@ -721,8 +730,8 @@ static int convertAuthCodeToReasonCode(AuthFailureInfo afi) case AuthResponse.ERROR_CONNECTING_TOO_MUCH_A : return REASON_CONNECTION_RATE_EXCEEDED; case AuthResponse.ERROR_CONNECTING_TOO_MUCH_B : return REASON_CONNECTION_RATE_EXCEEDED; - case AuthResponse.ERROR_INVALID_SN_OR_PASS_A : return REASON_BAD_PASSWORD_A; - case AuthResponse.ERROR_INVALID_SN_OR_PASS_B : return REASON_BAD_PASSWORD_A; + case AuthResponse.ERROR_INVALID_SN_OR_PASS_A : return REASON_NON_EXISTING_ICQ_UIN_A; + case AuthResponse.ERROR_INVALID_SN_OR_PASS_B : return REASON_NON_EXISTING_ICQ_UIN_B; // 16 is also used for blocked from same IP case 16 : return REASON_MANY_CLIENTS_FROM_SAME_IP_A; case AuthResponse.ERROR_SIGNON_BLOCKED : return REASON_MANY_CLIENTS_FROM_SAME_IP_B; diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestAccountInstallation.java b/test/net/java/sip/communicator/slick/protocol/icq/TestAccountInstallation.java index bc2159c2b..6144d2a1b 100644 --- a/test/net/java/sip/communicator/slick/protocol/icq/TestAccountInstallation.java +++ b/test/net/java/sip/communicator/slick/protocol/icq/TestAccountInstallation.java @@ -17,6 +17,7 @@ /** * Tests basic account manager functionalitites * @author Emil Ivov + * @author Damian Minkov */ public class TestAccountInstallation extends TestCase { @@ -49,9 +50,9 @@ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest( - new TestAccountInstallation("testRegisterUrongUsername")); + new TestAccountInstallation("testRegisterWrongUsername")); suite.addTest( - new TestAccountInstallation("testRegisterUrongPassword")); + new TestAccountInstallation("testRegisterWrongPassword")); suite.addTest( new TestAccountInstallation("testInstallAccount")); @@ -64,7 +65,7 @@ public static Test suite() * we first install this account, then try to register and wait for the * supposed event. After all we unregister this account */ - public void testRegisterUrongUsername() + public void testRegisterWrongUsername() { ServiceReference[] serRefs = null; String osgiFilter = "(" + AccountManager.PROTOCOL_PROPERTY_NAME @@ -128,10 +129,12 @@ public void testRegisterUrongUsername() //save the service for other tests to use. ServiceReference icqServiceRef = icqProviderRefs[0]; - ProtocolProviderService provider = (ProtocolProviderService)IcqSlickFixture.bc.getService(icqServiceRef); + ProtocolProviderService provider = + (ProtocolProviderService)IcqSlickFixture.bc.getService(icqServiceRef); - RegistrationFailedEventCollector regFailedEvtCollector = new RegistrationFailedEventCollector(); + RegistrationFailedEventCollector regFailedEvtCollector = + new RegistrationFailedEventCollector(); logger.debug("install " + regFailedEvtCollector); @@ -163,8 +166,13 @@ public void testRegisterUrongUsername() ,regFailedEvtCollector.collectedNewStates .contains(RegistrationState.AUTHENTICATION_FAILED)); - assertTrue("Registration status must be auth failed as we are logging in with wrong uin", regFailedEvtCollector.failedCode == RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED); - assertNotNull("We must have reason for auth failed", regFailedEvtCollector.failedReason); + assertEquals( + "Registration status must be auth failed as we are logging in with wrong uin", + regFailedEvtCollector.failedCode, + RegistrationStateChangeEvent.REASON_NON_EXISTING_USER_ID); + + assertNotNull("We must have reason for auth failed", + regFailedEvtCollector.failedReason); provider.removeRegistrationStateChangeListener(regFailedEvtCollector); @@ -178,7 +186,7 @@ public void testRegisterUrongUsername() * We get the already installed account. Change the password and try to register * After all tests we must return the original password so we don't break the other tests */ - public void testRegisterUrongPassword() + public void testRegisterWrongPassword() { ServiceReference[] serRefs = null; String osgiFilter = "(" + AccountManager.PROTOCOL_PROPERTY_NAME @@ -245,7 +253,8 @@ public void testRegisterUrongPassword() ProtocolProviderService provider = (ProtocolProviderService)IcqSlickFixture. bc.getService(icqServiceRef); - RegistrationFailedEventCollector regFailedEvtCollector = new RegistrationFailedEventCollector(); + RegistrationFailedEventCollector regFailedEvtCollector = + new RegistrationFailedEventCollector(); logger.debug("install " + regFailedEvtCollector); @@ -277,7 +286,11 @@ public void testRegisterUrongPassword() ,regFailedEvtCollector.collectedNewStates .contains(RegistrationState.AUTHENTICATION_FAILED)); - assertTrue("Registration status must be auth failed as we are logging in with wrong pass", regFailedEvtCollector.failedCode == RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED); + assertEquals( + "Registration status must be auth failed as we are logging in with wrong pass", + regFailedEvtCollector.failedCode, + RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED); + assertNotNull("We must have reason for auth failed", regFailedEvtCollector.failedReason); provider.removeRegistrationStateChangeListener(regFailedEvtCollector); @@ -285,35 +298,6 @@ public void testRegisterUrongPassword() icqAccountManager.uninstallAccount(icqAccountID); } - public class RegistrationFailedEventCollector - implements RegistrationStateChangeListener - { - public List collectedNewStates = new LinkedList(); - - public int failedCode; - public String failedReason = null; - - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - collectedNewStates.add(evt.getNewState()); - - logger.debug("damencho col event - " + evt.getNewState()); - - if(evt.getNewState().equals( RegistrationState.AUTHENTICATION_FAILED)) - { - failedCode = evt.getReasonCode(); - failedReason = evt.getReason(); - - logger.debug("Our registration failed - " + failedCode + " = " + failedReason); - synchronized(registrationLock){ - logger.debug("."); - registrationLock.notifyAll(); - logger.debug("."); - } - } - } - } - /** * Installs an account and verifies whether the installation has gone well. */ @@ -443,4 +427,33 @@ public void testInstallAccount() + "the protocol provider service." ,icqProtocolProvider instanceof ProtocolProviderService); } + + public class RegistrationFailedEventCollector + implements RegistrationStateChangeListener + { + public List collectedNewStates = new LinkedList(); + + public int failedCode; + public String failedReason = null; + + public void registrationStateChanged(RegistrationStateChangeEvent evt) + { + collectedNewStates.add(evt.getNewState()); + + logger.debug("damencho col event - " + evt.getNewState()); + + if(evt.getNewState().equals( RegistrationState.AUTHENTICATION_FAILED)) + { + failedCode = evt.getReasonCode(); + failedReason = evt.getReason(); + + logger.debug("Our registration failed - " + failedCode + " = " + failedReason); + synchronized(registrationLock){ + logger.debug("."); + registrationLock.notifyAll(); + logger.debug("."); + } + } + } + } }