LoginTest::testSASLAnonymousLogin

Hi

The test in LoginTest::testSASLAnonymousLogin calls loginAnonymously(). The description of that method says:

“Logs in to the server anonymously. Very few servers are configured to support anonymous authentication, so it’s fairly likely logging in anonymously will fail. If anonymous login does succeed, your XMPP address will likely be in the form “123ABC@server/789XYZ” or “server/123ABC” (where “123ABC” and “789XYZ” is a random value generated by the server).”

The catch block is:

catch (XMPPException e) {

e.printStackTrace();

//fail(e.getMessage());

}

So, what is actually being tested here? Nothing it seems.

One idea might be to have a test property such that, psuedo code like:

catch (XMPPException e) {

if (testPropertyAnonymousLogin) {

//Which is to say, if the test property says anonymous login should work, then

e.printStackTrace();

fail(e.getMessage());

}

}

Thoughts?

Thanks

Nathan

1 Like

In the same vein, we also have LoginTest::testNonSASLAnonymousLogin(), which actually does fail if the login fails.

It is not obvious that, if anonymous login is not supported, whether it makes any difference whether the login is SASL or not.

So, is the testNonSASLAnonymousLogin() correct?

Thanks

Nathan

Here is a patch:

Index: test/config/test-case.xml

===================================================================

— test/config/test-case.xml (revision 12905)

+++ test/config/test-case.xml (working copy)

@@ -2,15 +2,20 @@

  • localhost

  • 5222

  • xcp.localhost

  • 5222

  • user

    • chat

    • conference

    • chat

    • conference

    • false

    \ No newline at end of file

    Index: test/org/jivesoftware/smack/test/SmackTestCase.java

    ===================================================================

    — test/org/jivesoftware/smack/test/SmackTestCase.java (revision 12905)

    +++ test/org/jivesoftware/smack/test/SmackTestCase.java (working copy)

    @@ -57,6 +57,7 @@

    private String usernamePrefix = “user”;

    private String passwordPrefix;

    private boolean samePassword;

    • private boolean testAnonymousLogin = false;

    private List createdUserIdx = new ArrayList();

    private String chatDomain = “chat”;

    @@ -416,6 +417,9 @@

    samePassword = “true”.equals(parser.getAttributeValue(0));

    passwordPrefix = parser.nextText();

    }

    •                else if (parser.getName().equals("testAnonymousLogin")) {
      
    •                    testAnonymousLogin = "true".equals(parser.nextText());
      
    •                }
      

    }

    eventType = parser.next();

    }

    @@ -476,4 +480,8 @@

    }

    }

    • public boolean isTestAnonymousLogin() {

    •    return testAnonymousLogin;
      
    • }

    }

    Index: test/org/jivesoftware/smack/LoginTest.java

    ===================================================================

    — test/org/jivesoftware/smack/LoginTest.java (revision 12905)

    +++ test/org/jivesoftware/smack/LoginTest.java (working copy)

    @@ -67,6 +67,11 @@

    • Check that the server handles anonymous users correctly.

    */

    public void testSASLAnonymousLogin() {

    •    if (!isTestAnonymousLogin()){
      
    •        return;
      
    •    }
      

    try {

    XMPPConnection conn1 = createConnection();

    XMPPConnection conn2 = createConnection();

    @@ -84,8 +89,8 @@

    assertNotNull(“Username is null”, StringUtils.parseName(conn2.getUser()));

    }

    catch (XMPPException e) {

    •            e.printStackTrace();
      
    •            //fail(e.getMessage());
      
    •          //  e.printStackTrace();
      
    •            fail(e.getMessage());
      

    }

    finally {

    // Close the connection

    @@ -103,6 +108,11 @@

    • Check that the server handles anonymous users correctly.

    */

    public void testNonSASLAnonymousLogin() {

    •    if (!isTestAnonymousLogin()){
      
    •        return;
      
    •    }
      

    try {

    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());

    config.setSASLAuthenticationEnabled(false);
    patch.txt.zip (1247 Bytes)