ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") require 'test_help' #------------------------------------------------------------------------ # Test XMLRPC client #------------------------------------------------------------------------ require "test/unit" require "xmlrpc/client" require "pp" =begin class TC_XMLRPCClient < Test::Unit::TestCase def setup @server = XMLRPC::Client.new( "localhost", "/mailservice/api", 3001) end def teardown end def test_1_user assert_equal(@server.call("UserLogin", "dagbrown", "blort"), false) assert_raises XMLRPC::FaultException do @server.call("UserLogin", "dagbrown", "foobar") end end def test_2_mailinglist assert_raises XMLRPC::FaultException do @server.call("MailinglistFindByName", "dagbrown") end assert_equal(@server.call("UserLogin", "dagbrown", "foobar"), true) assert_equal(@server.call("MailinglistFindByName", "dagbrown"), 1) end end =end class TC_XMLRPCClient_DomainLogin < Test::Unit::TestCase def setup @server = XMLRPC::Client.new( "localhost", "/mailservice/api", 3001) end def teardown end def test_baddomain # bad username, bad password assert_equal(false, @server.call("DomainLogin", "junkdomain", "blort")) # good username, bad password assert_equal(false, @server.call("DomainLogin", "bar.blut", "blort")) end def test_loggedout # now once again assert_equal(false, @server.call("DomainLogout")); end def test_good_domain # good username, good password assert_equal(true, @server.call("DomainLogin", "bar.blut", "foobar")) # now log out assert_equal(true, @server.call("DomainLogout")); end def test_permissions assert_raises XMLRPC::FaultException do @server.call("UserLogin", "dagbrown", "foobar") end assert_raises XMLRPC::FaultException do @server.call("FindMailinglistByName", 1) end end end class TC_XMLRPCClient_UserLogin < Test::Unit::TestCase def setup @server = XMLRPC::Client.new( "localhost", "/mailservice/api", 3001) @server.call "DomainLogin", "bar.blut", "foobar" end def teardown @server.call "DomainLogout" end def test_baduser assert_equal false, @server.call("UserLogin", "huaglhuagl", "blort") assert_equal false, @server.call("UserLogin", "dagbrown", "blort") end def test_gooduser assert_equal true, @server.call("UserLogin", "dagbrown", "foobar") end end class TC_XMLRPCClient_AdminTasks < Test::Unit::TestCase def setup @server = XMLRPC::Client.new "localhost", "/mailservice/api", 3001 @server.call "DomainLogin", "bar.blut", "foobar" @server.call "UserLogin", "root", "foobar" end def teardown @server.call "UserLogout" @server.call "DomainLogout" end def test_passwordmismatch # password doesn't match assert_raises XMLRPC::FaultException do @server.call("UserSignup", "flibbleuser", "password", "drowssap") end end def test_usercreate # user doesn't exist; gets created assert true, @server.call("UserSignup", "testuser", "password", "password") assert_equal true, @server.call("UserDelete","testuser","testuser") end def test_usercollection @server.call("UserDelete","testuser","testuser") assert @server.call("UserSignup","testuser","password","password") # user already exists; creation fails assert_raises XMLRPC::FaultException do @server.call("UserSignup", "testuser", "password", "password") end # user exists; deletion succeeds assert_equal true, @server.call("UserDelete", "testuser", "testuser") end def test_userlogin assert @server.call("UserSignup","testuser","password","password") # user exists, login succeeds assert @server.call("UserLogin","testuser","password") # let's get our session back assert @server.call("UserLogin","root","foobar") assert_equal true, @server.call("UserDelete","testuser","testuser") end def test_usernolongexists assert @server.call("UserSignup","testuser","password","password") # user exists; deletion succeeds assert_equal true, @server.call("UserDelete","testuser","testuser") # user doesn't exist; login fails assert_equal false, @server.call("UserLogin","testuser","password") # okay, our session's just been trashed again. Get it back. assert_equal true, @server.call("UserLogin","root","foobar") # user doesn't exist; deletion fails assert_equal false, @server.call("UserDelete","testuser","testuser") end # user doesn't exist; deletion fails #assert_equal true, @server.call("UserDelete", "testuser", "testuser") # user doesn't exist; login fails #assert_raises XMLRPC::FaultException do # @server.call("UserLogin", "flibbleuser", "password") #end #end end # class TC_XMLRPCClient_MailingLists < Test::Unit::TestCase # end # # Make an object to represent the XML-RPC server. # server = XMLRPC::Client.new( "localhost", "/mailservice/api", 3001) # # # # # Call the remote server and get our result # mailinglist1 = server.call("FindMailinglistByName","dagbrown") rescue nil # session_id = server.call("UserLogin", "dagbrown", "foobar") # mailinglist2 = server.call("FindMailinglistByName","dagbrown") # verify_session_id = server.call("SessionId") # server.call("UserLogout") # # puts mailinglist1.inspect # puts mailinglist2.inspect # puts session_id # puts verify_session_id