Commit d6f57908 authored by Jelte Jansen's avatar Jelte Jansen
Browse files
parents cba9add1 f7d2e629
......@@ -723,7 +723,7 @@ AC_OUTPUT([doc/version.ent
src/bin/bind10/tests/bind10_test.py
src/bin/bind10/run_bind10.sh
src/bin/bindctl/run_bindctl.sh
src/bin/bindctl/bindctl-source.py
src/bin/bindctl/bindctl_main.py
src/bin/bindctl/tests/bindctl_test
src/bin/loadzone/run_loadzone.sh
src/bin/loadzone/tests/correct/correct_test.sh
......@@ -751,6 +751,7 @@ AC_OUTPUT([doc/version.ent
tests/system/conf.sh
tests/system/glue/setup.sh
tests/system/glue/nsx1/b10-config.db
tests/system/bindctl/nsx1/b10-config.db.template
], [
chmod +x src/bin/cmdctl/run_b10-cmdctl.sh
chmod +x src/bin/xfrin/run_b10-xfrin.sh
......
......@@ -5,12 +5,13 @@ man_MANS = bindctl.1
EXTRA_DIST = $(man_MANS) bindctl.xml
python_PYTHON = __init__.py bindcmd.py cmdparse.py exception.py moduleinfo.py mycollections.py
python_PYTHON = __init__.py bindcmd.py cmdparse.py exception.py moduleinfo.py \
mycollections.py
pythondir = $(pyexecdir)/bindctl
bindctldir = $(pkgdatadir)
CLEANFILES = bindctl
CLEANFILES = bindctl bindctl_main.pyc
if ENABLE_MAN
......@@ -19,8 +20,8 @@ bindctl.1: bindctl.xml
endif
bindctl: bindctl-source.py
bindctl: bindctl_main.py
$(SED) -e "s|@@PYTHONPATH@@|@pyexecdir@|" \
-e "s|@@SYSCONFDIR@@|@sysconfdir@|" \
-e "s|@@LIBEXECDIR@@|$(pkglibexecdir)|" bindctl-source.py >$@
-e "s|@@LIBEXECDIR@@|$(pkglibexecdir)|" bindctl_main.py >$@
chmod a+x $@
......@@ -87,7 +87,8 @@ class ValidatedHTTPSConnection(http.client.HTTPSConnection):
class BindCmdInterpreter(Cmd):
"""simple bindctl example."""
def __init__(self, server_port = 'localhost:8080', pem_file = None):
def __init__(self, server_port='localhost:8080', pem_file=None,
csv_file_dir=None):
Cmd.__init__(self)
self.location = ""
self.prompt_end = '> '
......@@ -103,7 +104,12 @@ class BindCmdInterpreter(Cmd):
ca_certs=pem_file)
self.session_id = self._get_session_id()
self.config_data = None
if csv_file_dir is not None:
self.csv_file_dir = csv_file_dir
else:
self.csv_file_dir = pwd.getpwnam(getpass.getuser()).pw_dir + \
os.sep + '.bind10' + os.sep
def _get_session_id(self):
'''Generate one session id for the connection. '''
rand = os.urandom(16)
......@@ -175,9 +181,7 @@ class BindCmdInterpreter(Cmd):
time, username and password saved in 'default_user.csv' will be
used first.
'''
csv_file_dir = pwd.getpwnam(getpass.getuser()).pw_dir
csv_file_dir += os.sep + '.bind10' + os.sep
users = self._get_saved_user_info(csv_file_dir, CSV_FILE_NAME)
users = self._get_saved_user_info(self.csv_file_dir, CSV_FILE_NAME)
for row in users:
param = {'username': row[0], 'password' : row[1]}
try:
......@@ -211,7 +215,8 @@ class BindCmdInterpreter(Cmd):
raise FailToLogin()
if response.status == http.client.OK:
self._save_user_info(username, passwd, csv_file_dir, CSV_FILE_NAME)
self._save_user_info(username, passwd, self.csv_file_dir,
CSV_FILE_NAME)
return True
def _update_commands(self):
......
......@@ -51,6 +51,7 @@
<arg><option>--address <replaceable>address</replaceable></option></arg>
<arg><option>--help</option></arg>
<arg><option>--certificate-chain <replaceable>file</replaceable></option></arg>
<arg><option>--csv-file-dir<replaceable>file</replaceable></option></arg>
<arg><option>--port <replaceable>number</replaceable></option></arg>
<arg><option>--version</option></arg>
</cmdsynopsis>
......@@ -109,6 +110,22 @@
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--csv-file-dir</option><replaceable>file</replaceable>
</term>
<listitem>
<para>
The directory name in which the user/password CSV file
is stored (see AUTHENTICATION).
By default this option doesn't have any value,
in which case the ".bind10" directory under the user's
home directory will be used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option>,
<option>--help</option></term>
......@@ -148,8 +165,10 @@
<para>
The tool will authenticate using a username and password.
On the first successful login, it will save the details to
<filename>~/.bind10/default_user.csv</filename>
a comma-separated-value (CSV) file
which will be used for later uses of <command>bindctl</command>.
The file name is <filename>default_user.csv</filename>
located under the directory specified by the --csv-file-dir option.
</para>
<!-- TODO: mention HTTPS? -->
......
......@@ -111,25 +111,28 @@ def check_addr(option, opt_str, value, parser):
parser.values.addr = value
def set_bindctl_options(parser):
parser.add_option('-p', '--port', dest = 'port', type = 'int',
action = 'callback', callback=check_port,
default = '8080', help = 'port for cmdctl of bind10')
parser.add_option('-p', '--port', dest='port', type='int',
action='callback', callback=check_port,
default='8080', help='port for cmdctl of bind10')
parser.add_option('-a', '--address', dest = 'addr', type = 'string',
action = 'callback', callback=check_addr,
default = '127.0.0.1', help = 'IP address for cmdctl of bind10')
parser.add_option('-a', '--address', dest='addr', type='string',
action='callback', callback=check_addr,
default='127.0.0.1', help='IP address for cmdctl of bind10')
parser.add_option('-c', '--certificate-chain', dest = 'cert_chain',
type = 'string', action = 'store',
help = 'PEM formatted server certificate validation chain file')
parser.add_option('-c', '--certificate-chain', dest='cert_chain',
type='string', action='store',
help='PEM formatted server certificate validation chain file')
parser.add_option('--csv-file-dir', dest='csv_file_dir', type='string',
default=None, action='store',
help='Directory to store the password CSV file')
if __name__ == '__main__':
parser = OptionParser(version = VERSION)
set_bindctl_options(parser)
(options, args) = parser.parse_args()
server_addr = options.addr + ':' + str(options.port)
tool = BindCmdInterpreter(server_addr, pem_file=options.cert_chain)
tool = BindCmdInterpreter(server_addr, pem_file=options.cert_chain,
csv_file_dir=options.csv_file_dir)
prepare_config_commands(tool)
tool.run()
......@@ -11,6 +11,6 @@ if ENABLE_PYTHON_COVERAGE
endif
for pytest in $(PYTESTS) ; do \
echo Running test: $$pytest ; \
env PYTHONPATH=$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_srcdir)/src/bin \
env PYTHONPATH=$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/bin/bindctl:$(abs_top_srcdir)/src/bin \
$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
done
......@@ -17,8 +17,12 @@
import unittest
import isc.cc.data
import os
import pwd
import getpass
from optparse import OptionParser
from isc.config.config_data import ConfigData, MultiConfigData
from isc.config.module_spec import ModuleSpec
from bindctl_main import set_bindctl_options
from bindctl import cmdparse
from bindctl import bindcmd
from bindctl.moduleinfo import *
......@@ -332,13 +336,6 @@ class TestConfigCommands(unittest.TestCase):
cmd = cmdparse.BindCmdParse("config set identifier=\"foo/a_list\" value=[1]")
self.assertRaises(isc.cc.data.DataTypeError, self.tool.apply_config_cmd, cmd)
class FakeBindCmdInterpreter(bindcmd.BindCmdInterpreter):
def __init__(self):
pass
class TestBindCmdInterpreter(unittest.TestCase):
def _create_invalid_csv_file(self, csvfilename):
......@@ -349,9 +346,22 @@ class TestBindCmdInterpreter(unittest.TestCase):
writer.writerow(['name2'])
csvfile.close()
def test_csv_file_dir(self):
# Checking default value
if "HOME" in os.environ:
home_dir = os.environ["HOME"]
else:
home_dir = pwd.getpwnam(getpass.getuser()).pw_dir
self.assertEqual(home_dir + os.sep + '.bind10' + os.sep,
bindcmd.BindCmdInterpreter().csv_file_dir)
new_csv_dir = '/something/different/'
custom_cmd = bindcmd.BindCmdInterpreter(csv_file_dir=new_csv_dir)
self.assertEqual(new_csv_dir, custom_cmd.csv_file_dir)
def test_get_saved_user_info(self):
cmd = FakeBindCmdInterpreter()
users = cmd._get_saved_user_info('/notexist', 'cvs_file.cvs')
cmd = bindcmd.BindCmdInterpreter()
users = cmd._get_saved_user_info('/notexist', 'csv_file.csv')
self.assertEqual([], users)
csvfilename = 'csv_file.csv'
......@@ -360,6 +370,40 @@ class TestBindCmdInterpreter(unittest.TestCase):
self.assertEqual([], users)
os.remove(csvfilename)
class TestCommandLineOptions(unittest.TestCase):
class FakeParserError(Exception):
"""An exception thrown from FakeOptionParser on parser error.
"""
pass
class FakeOptionParser(OptionParser):
"""This fake class emulates the OptionParser class with customized
error handling for the convenient of tests.
"""
def __init__(self):
OptionParser.__init__(self)
def error(self, msg):
raise TestCommandLineOptions.FakeParserError
def setUp(self):
self.parser = self.FakeOptionParser()
set_bindctl_options(self.parser)
def test_csv_file_dir(self):
# by default the option is "undefined"
(options, _) = self.parser.parse_args([])
self.assertEqual(None, options.csv_file_dir)
# specify the option, valid case.
(options, _) = self.parser.parse_args(['--csv-file-dir', 'some_dir'])
self.assertEqual('some_dir', options.csv_file_dir)
# missing option arg; should trigger parser error.
self.assertRaises(self.FakeParserError, self.parser.parse_args,
['--csv-file-dir'])
if __name__== "__main__":
unittest.main()
......@@ -7,7 +7,10 @@ distclean-local:
# Most of the files under this directory (including test subdirectories)
# must be listed in EXTRA_DIST.
EXTRA_DIST = README cleanall.sh ifconfig.sh start.pl stop.pl run.sh runall.sh
EXTRA_DIST += common/default_user.csv
EXTRA_DIST += glue/auth.good glue/example.good glue/noglue.good glue/test.good
EXTRA_DIST += glue/tests.sh glue/clean.sh
EXTRA_DIST += glue/nsx1/com.db glue/nsx1/net.db glue/nsx1/root-servers.nil.db
EXTRA_DIST += glue/nsx1/root.db
EXTRA_DIST += bindctl/tests.sh bindctl/clean.sh bindctl/setup.sh
EXTRA_DIST += bindctl/nsx1/root.db bindctl/nsx1/example-normalized.db
......@@ -18,6 +18,7 @@ set to point to the top directory of the source tree.
There are multiple test suites, each in a separate subdirectory and
involving a different DNS setup. They are:
bindctl/ Some basic management operations using the bindctl tool
glue/ Glue handling tests
(the following tests are planned to be added soon)
dnssec/ DNSSEC tests
......
#!/bin/sh
#
# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
# Copyright (C) 2000, 2001 Internet Software Consortium.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
rm -f */b10-config.db
rm -f dig.out.* bindctl.out.*
rm -f */msgq_socket */zone.sqlite3
{"version": 2,
"Auth": {
"listen_on": [{"address": "10.53.0.1", "port": 53210}],
"database_file": "@abs_builddir@/zone.sqlite3",
"statistics-interval": 1
},
"Xfrout": {
"log_file": "@abs_builddir@/Xfrout.log"
}
}
com. 300 IN SOA postmaster.example. ns.example.com. 2000042100 600 600 1200 600
com. 300 IN NS ns.example.com.
ns.example.com. 300 IN A 192.0.2.2
; Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
; Copyright (C) 2000, 2001 Internet Software Consortium.
;
; Permission to use, copy, modify, and/or distribute this software for any
; purpose with or without fee is hereby granted, provided that the above
; copyright notice and this permission notice appear in all copies.
;
; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
; AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
; PERFORMANCE OF THIS SOFTWARE.
$TTL 300
. IN SOA postmaster.example. a.root.servers.nil. (
2000042100 ; serial
600 ; refresh
600 ; retry
1200 ; expire
600 ; minimum
)
. NS ns.example.com.
ns.example.com. A 192.0.2.1
#!/bin/sh
#
# Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
SUBTEST_TOP=${TEST_TOP}/bindctl
cp ${SUBTEST_TOP}/nsx1/b10-config.db.template ${SUBTEST_TOP}/nsx1/b10-config.db
rm -f ${SUBTEST_TOP}/*/zone.sqlite3
${B10_LOADZONE} -o . -d ${SUBTEST_TOP}/nsx1/zone.sqlite3 \
${SUBTEST_TOP}//nsx1/root.db
#!/bin/sh
#
# Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
SYSTEMTESTTOP=..
. $SYSTEMTESTTOP/conf.sh
#
# Do bindctl tests.
#
status=0
n=0
echo "I:Checking b10-auth is working by default ($n)"
$DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
# perform a simple check on the output (digcomp would be too much for this)
grep 192.0.2.1 dig.out.$n > /dev/null || status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:Checking BIND 10 statistics after a pose ($n)"
# wait for 2sec to make sure b10-stats gets the latest statistics.
# note that we set statistics-interval to 1.
sleep 2
echo 'Stats show
' | $RUN_BINDCTL \
--csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
# the server should have received 1 UDP and 1 TCP queries (TCP query was
# sent from the server startup script)
grep "\"auth.queries.tcp\": 1," bindctl.out.$n > /dev/null || status=1
grep "\"auth.queries.udp\": 1," bindctl.out.$n > /dev/null || status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:Stopping b10-auth and checking that ($n)"
echo 'config set Boss/start_auth false
config commit
quit
' | $RUN_BINDCTL \
--csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
# dig should exit with a failure code.
$DIG +tcp +norec @10.53.0.1 -p 53210 ns.example.com. A && status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:Restarting b10-auth and checking that ($n)"
echo 'config set Boss/start_auth true
config commit
quit
' | $RUN_BINDCTL \
--csv-file-dir=$BINDCTL_CSV_DIR 2>&1 > /dev/null || status=1
$DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
grep 192.0.2.1 dig.out.$n > /dev/null || status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:Rechecking BIND 10 statistics after a pose ($n)"
sleep 2
echo 'Stats show
' | $RUN_BINDCTL \
--csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
# The statistics counters should have been reset while stop/start.
grep "\"auth.queries.tcp\": 0," bindctl.out.$n > /dev/null || status=1
grep "\"auth.queries.udp\": 1," bindctl.out.$n > /dev/null || status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:Changing the data source from sqlite3 to in-memory ($n)"
DATASRC_SPEC='[{"type": "memory", "zones": [{"origin": "com","file":'
DATASRC_SPEC="${DATASRC_SPEC} \"${TEST_TOP}/bindctl/nsx1/example-normalized.db\"}]}]"
echo "config set Auth/datasources ${DATASRC_SPEC}
config commit
quit
" | $RUN_BINDCTL \
--csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
$DIG +norec @10.53.0.1 -p 53210 ns.example.com. A >dig.out.$n || status=1
grep 192.0.2.2 dig.out.$n > /dev/null || status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:Rechecking BIND 10 statistics after changing the datasource ($n)"
sleep 2
echo 'Stats show
' | $RUN_BINDCTL \
--csv-file-dir=$BINDCTL_CSV_DIR > bindctl.out.$n || status=1
# The statistics counters shouldn't be reset due to hot-swapping datasource.
grep "\"auth.queries.tcp\": 0," bindctl.out.$n > /dev/null || status=1
grep "\"auth.queries.udp\": 2," bindctl.out.$n > /dev/null || status=1
if [ $status != 0 ]; then echo "I:failed"; fi
n=`expr $n + 1`
echo "I:exit status: $status"
exit $status
......@@ -34,10 +34,13 @@ if [ -z $BIND9_TOP ]; then
exit 1
fi
# Find the top of the source tree.
# Find the top of the source and test trees.
TOP=@abs_top_srcdir@
TEST_TOP=@abs_builddir@
RUN_BIND10=$TOP/src/bin/bind10/run_bind10.sh
RUN_BINDCTL=$TOP/src/bin/bindctl/run_bindctl.sh
BINDCTL_CSV_DIR=@abs_srcdir@/common/
B10_LOADZONE=$TOP/src/bin/loadzone/run_loadzone.sh
BIND9_NAMED=$BIND9_TOP/bin/named/named
DIG=$BIND9_TOP/bin/dig/dig
......@@ -45,8 +48,8 @@ DIG=$BIND9_TOP/bin/dig/dig
TESTSOCK=$BIND9_TOP/bin/tests/system/testsock.pl
DIGCOMP=$BIND9_TOP/bin/tests/system/digcomp.pl
SUBDIRS="glue"
#SUBDIRS="dnssec glue masterfile xfer"
SUBDIRS="bindctl glue"
#SUBDIRS="dnssec masterfile xfer"
# PERL will be an empty string if no perl interpreter was found.
PERL=@PERL@
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment