Added unit test for the command handler.
git-svn-id: svn+ssh://svn.luon.net/svn/ildus/trunk@6 65a33f86-aa00-0410-91be-cd1bf5efb309
This commit is contained in:
parent
1254787d03
commit
046f4b7b1e
|
@ -18,7 +18,7 @@ port: 9000
|
||||||
### FILES/PATHS
|
### FILES/PATHS
|
||||||
#
|
#
|
||||||
# Directory for logging.
|
# Directory for logging.
|
||||||
logdir = /var/log/ildusd
|
logdir: /var/log/ildusd
|
||||||
|
|
||||||
# Pidfile to save the PID of the main daemon process to.
|
# Pidfile to save the PID of the main daemon process to.
|
||||||
pidfile: /tmp/
|
pidfile: /tmp/
|
||||||
|
@ -35,4 +35,3 @@ backend:
|
||||||
basedn: cn=somedomain.test,ou=DNS,dc=somedomain,dc=test
|
basedn: cn=somedomain.test,ou=DNS,dc=somedomain,dc=test
|
||||||
dnsdn: cn=admin,ou=People,dc=somedomain,dc=test
|
dnsdn: cn=admin,ou=People,dc=somedomain,dc=test
|
||||||
dnspw: secret
|
dnspw: secret
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
# Software Foundation; either version 2 of the License, or (at your option)
|
# Software Foundation; either version 2 of the License, or (at your option)
|
||||||
# any later version.
|
# any later version.
|
||||||
|
|
||||||
require 'gserver'
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
|
require 'ildus/server/handler'
|
||||||
|
|
||||||
module Ildus
|
module Ildus
|
||||||
|
|
||||||
class Server < GServer
|
class Server < GServer
|
||||||
|
@ -76,8 +77,3 @@ module Ildus
|
||||||
end # class Server
|
end # class Server
|
||||||
|
|
||||||
end # module Ildus
|
end # module Ildus
|
||||||
|
|
||||||
# Require the rest of the server library.
|
|
||||||
require 'ildus/server/account'
|
|
||||||
require 'ildus/server/backend'
|
|
||||||
require 'ildus/server/handler'
|
|
||||||
|
|
|
@ -7,9 +7,14 @@
|
||||||
# Software Foundation; either version 2 of the License, or (at your option)
|
# Software Foundation; either version 2 of the License, or (at your option)
|
||||||
# any later version.
|
# any later version.
|
||||||
|
|
||||||
|
require 'gserver'
|
||||||
|
|
||||||
|
require 'ildus/server/account'
|
||||||
|
require 'ildus/server/backend'
|
||||||
|
|
||||||
module Ildus
|
module Ildus
|
||||||
|
|
||||||
class Server < GServer
|
class Server
|
||||||
|
|
||||||
class Handler
|
class Handler
|
||||||
|
|
||||||
|
@ -107,7 +112,7 @@ module Ildus
|
||||||
private
|
private
|
||||||
#########
|
#########
|
||||||
|
|
||||||
def handle_command(cmd, args)
|
def handle_command(cmd, args=[])
|
||||||
method_name = cmd.downcase + "_cmd"
|
method_name = cmd.downcase + "_cmd"
|
||||||
meth = method(method_name)
|
meth = method(method_name)
|
||||||
meth.call(*args)
|
meth.call(*args)
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
require 'test/unit'
|
||||||
|
require 'ildus/server/handler'
|
||||||
|
|
||||||
|
class TC_HandlerTest < Test::Unit::TestCase
|
||||||
|
include Ildus
|
||||||
|
|
||||||
|
def setup
|
||||||
|
# Create a handler object.
|
||||||
|
@io = StringIO.new
|
||||||
|
@hdl = Server::Handler.new(nil, @io)
|
||||||
|
assert(@hdl)
|
||||||
|
|
||||||
|
class << @hdl
|
||||||
|
attr_reader :account
|
||||||
|
public :handle_command
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_auth
|
||||||
|
# "list" shouldn't be possible until authenticated.
|
||||||
|
assert_raises(Server::Handler::NotAuthError) { @hdl.handle_command("list") }
|
||||||
|
|
||||||
|
# Set the user.
|
||||||
|
@hdl.handle_command("user", ["test"])
|
||||||
|
assert_equal("test", @hdl.account.user)
|
||||||
|
|
||||||
|
# "list" still shouldn't be possible.
|
||||||
|
assert_raises(Server::Handler::NotAuthError) { @hdl.handle_command("list") }
|
||||||
|
|
||||||
|
# Set a different user.
|
||||||
|
@hdl.handle_command("user", ["test2"])
|
||||||
|
assert_equal("test2", @hdl.account.user)
|
||||||
|
|
||||||
|
# Nothing should be raised when setting the password,
|
||||||
|
# we should be authenticated afterwards.
|
||||||
|
assert_nothing_raised do
|
||||||
|
@hdl.handle_command("pass", ["secret"])
|
||||||
|
end
|
||||||
|
assert_equal("secret", @hdl.account.pass)
|
||||||
|
assert(@hdl.account.authenticated?)
|
||||||
|
|
||||||
|
# "list" should be possible now.
|
||||||
|
assert_nothing_raised do
|
||||||
|
@hdl.handle_command("list")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Setting a different user or password should result in an error.
|
||||||
|
assert_raise(Server::Handler::AlreadyAuthError) do
|
||||||
|
@hdl.handle_command("user", ["test3"])
|
||||||
|
end
|
||||||
|
assert_raise(Server::Handler::AlreadyAuthError) do
|
||||||
|
@hdl.handle_command("pass", ["secret2"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end # class TC_HandlerTest
|
Reference in New Issue