[roster-dns-management] r1167 committed - Fixing some unittests

0 views
Skip to first unread message

roster-dns...@googlecode.com

unread,
Aug 16, 2013, 10:09:39 AM8/16/13
to roster-...@googlegroups.com
Revision: 1167
Author: J.S.P...@gmail.com
Date: Fri Aug 16 07:09:21 2013
Log: Fixing some unittests
http://code.google.com/p/roster-dns-management/source/detail?r=1167

Added:
/trunk/test/fakeldap.py
Modified:
/trunk/roster-config-manager/scripts/dnsconfigsync
/trunk/roster-server/roster_server/auth_developer.py
/trunk/test/dnscheckconfig_test.py
/trunk/test/dnsexportconfig_test.py
/trunk/test/dnslsdnsserver_test.py
/trunk/test/end_to_end_test.py
/trunk/test/roster_client_lib_test.py
/trunk/test/tree_exporter_test.py

=======================================
--- /dev/null
+++ /trunk/test/fakeldap.py Fri Aug 16 07:09:21 2013
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+
+# Copyright (c) 2009, Purdue University
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
met:
+#
+# Redistributions of source code must retain the above copyright notice,
this
+# list of conditions and the following disclaimer.
+#
+# Redistributions in binary form must reproduce the above copyright
notice, this
+# list of conditions and the following disclaimer in the documentation
and/or
+# other materials provided with the distribution.
+#
+# Neither the name of the Purdue University nor the names of its
contributors
+# may be used to endorse or promote products derived from this software
without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Fake ldap library with limited functionality"""
+
+__copyright__ = 'Copyright (C) 2009, Purdue University'
+__license__ = 'BSD'
+__version__ = '#TRUNK#'
+
+
+import roster_core
+
+
+OPT_X_TLS = None
+OPT_X_TLS_CACERTFILE = None
+
+def set_option(option, value):
+ pass
+
+def VERSION3(self):
+ pass
+
+class LDAPError(roster_core.CoreError):
+ pass
+
+class AuthenticationMethod(object):
+
+ def __init__(self, server=None):
+ self.protocol_version = 0
+
+ def Authenticate(self, user_name=None, binddn=None, password=None,
+ server=None):
+ binddn = binddn % user_name
+ if( binddn == 'uid=shuey,ou=People,dc=dc,dc=university,'
+ 'dc=edu' and password == 'testpass' ):
+ return True
+ elif( binddn == 'uid=sharrell,ou=People,dc=dc,dc=university,'
+ 'dc=edu' and password == 'test' ):
+ return True
+ elif( binddn == 'uid=jcollins,ou=People,dc=dc,dc=university,'
+ 'dc=edu' and password == 'test' ):
+ return True
+ elif( binddn.startswith('uid=user') and password == 'tost' ):
+ return True
+ else:
+ return False
+
+ def unbind_s(self):
+ pass
+
+ def simple_bind_s(self, binddn, password):
+ if( binddn == 'uid=jcollins,ou=People,dc=dc,dc=university,dc=edu' and
+ password == 'test' ):
+ pass
+ else:
+ raise LDAPError()
+
+initialize = AuthenticationMethod
=======================================
--- /trunk/roster-config-manager/scripts/dnsconfigsync Fri Aug 2 10:46:36
2013
+++ /trunk/roster-config-manager/scripts/dnsconfigsync Fri Aug 16 07:09:21
2013
@@ -161,7 +161,7 @@
for out in fabric_state.output:
fabric_state.output[out] = False
fabric_api.env.host_string = self.ssh_host
- fabric_api.run('rm -rf %s/*' % self.test_dir)
+ fabric_api.run('rm -rf %s' % os.path.join(self.test_dir, '*'))

retry_methods = [self.MoveFilesAndUnTar, self.ReplaceBindDir,
self.ReloadBindServer]
@@ -262,7 +262,7 @@

#Making sure self.bind_dir exists
result = fabric_api.run('file %s' % self.bind_dir)
- if( result.stdout == "%s: ERROR: cannot open `%s' (No such file or
directory)" % (
+ if( result.stdout == "%s: cannot open `%s' (No such file or
directory)" % (
self.bind_dir, self.bind_dir) ):
raise config_lib.ServerCheckError(
'BIND directory %s does not exist on server %s' % (self.bind_dir,
=======================================
--- /trunk/roster-server/roster_server/auth_developer.py Thu May 30
12:54:01 2013
+++ /trunk/roster-server/roster_server/auth_developer.py Fri Aug 16
07:09:21 2013
@@ -28,7 +28,8 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-"""Roster Developer Authentication module that will always return True"""
+"""Roster Developer Authentication module that will always return True
except
+for user 'fakeuser' or password 'fakepass'"""

__copyright__ = 'Copyright (C) 2010, Purdue Univeristy'
__license__ = 'BSD'
@@ -45,6 +46,8 @@
user_name: string of user name.
password: string of password
Outputs:
- boolean: True
+ boolean: True unless username is fakeuser or password is fakepass
"""
+ if( user_name == u'fakeuser' or password == u'fakepass'):
+ return False
return True
=======================================
--- /trunk/test/dnscheckconfig_test.py Fri Aug 9 10:24:40 2013
+++ /trunk/test/dnscheckconfig_test.py Fri Aug 16 07:09:21 2013
@@ -73,8 +73,9 @@
tar_contents = {}
exported_file = tarfile.open(tar_file_name, 'r:bz2')
for current_member in exported_file.getmembers():
- tar_contents[current_member.name] = exported_file.extractfile(
- current_member.name).read()
+ if( current_member.isfile() ):
+ tar_contents[current_member.name] = exported_file.extractfile(
+ current_member.name).read()
tarred_file_handle = exported_file.extractfile(member)
tarred_file = tarred_file_handle.read()
tarred_file_handle.close()
=======================================
--- /trunk/test/dnsexportconfig_test.py Fri Jul 19 13:56:34 2013
+++ /trunk/test/dnsexportconfig_test.py Fri Aug 16 07:09:21 2013
@@ -106,6 +106,11 @@
while( self.rndc_port == self.port ):
self.rndc_port = PickUnusedPort()

+ if( not os.path.exists(BINDDIR) ):
+ os.mkdir(BINDDIR)
+ if( not os.path.exists(TESTDIR) ):
+ os.mkdir(TESTDIR)
+
rndc_key = open(RNDC_KEY, 'w')
rndc_key.write(RNDC_KEY_DATA)
rndc_key.close()
@@ -161,10 +166,8 @@
shutil.rmtree(self.backup_dir)
if( os.path.exists(self.root_config_dir) ):
shutil.rmtree(self.root_config_dir)
- if( os.path.exists('%s/named' % BINDDIR.rstrip('/')) ):
- shutil.rmtree('%s/named' % BINDDIR.rstrip('/'))
- if( os.path.exists('%s/named.conf' % BINDDIR.rstrip('/')) ):
- os.remove('%s/named.conf' % BINDDIR.rstrip('/'))
+ if( os.path.exists(BINDDIR) ):
+ shutil.rmtree(BINDDIR)
if( os.path.exists(self.lockfile) ):
os.remove(self.lockfile)
if( os.path.exists('/etc/resolv.conf.unittest_backup') ):
@@ -216,7 +219,7 @@
os.system('sudo mv /etc/resolv.conf /etc/resolv.conf.unittest_backup')
os.system("""sudo sh -c "echo 'search %s\nnameserver 127.0.0.1\n' >
/etc/resolv.conf"\n""" % zone_name)

- num_test_machines = 30
+ num_test_machines = 30
ports = []
test_dns_servers = []

=======================================
--- /trunk/test/dnslsdnsserver_test.py Wed Jan 2 11:01:38 2013
+++ /trunk/test/dnslsdnsserver_test.py Fri Aug 16 07:09:21 2013
@@ -133,7 +133,6 @@
self.core_instance.MakeDnsServerSet(u'set1')
self.core_instance.MakeDnsServerSet(u'set2')
self.core_instance.MakeDnsServerSetAssignments(u'dns1', u'set1')
- self.core_instance.MakeDnsServerSetAssignments(u'dns2', u'set1')
self.core_instance.MakeDnsServerSetAssignments(u'dns2', u'set2')
command = os.popen('python %s assignment -u %s '
'-p %s --config-file %s -s %s' % (
@@ -141,7 +140,7 @@
self.server_name))
self.assertEqual(command.read(), 'set dns_servers\n'
'----------------\n'
- 'set1 dns1,dns2\n'
+ 'set1 dns1\n'
'set2 dns2\n\n')
command.close()
command = os.popen('python %s assignment -e set2 -u %s '
@@ -158,7 +157,6 @@
self.server_name))
self.assertEqual(command.read(), 'set dns_servers\n'
'----------------\n'
- 'set1 dns2\n'
'set2 dns2\n\n')
command.close()
command = os.popen('python %s assignment -u %s -d dns1 '
=======================================
--- /trunk/test/end_to_end_test.py Thu Aug 15 08:06:22 2013
+++ /trunk/test/end_to_end_test.py Fri Aug 16 07:09:21 2013
@@ -67,15 +67,15 @@
CREDFILE = '%s/.dnscred' % os.getcwd()
USERNAME = 'shuey'
PASSWORD = 'testpass'
-TESTDIR = u'%s/unittest_dir/' % os.getcwd()
+TESTDIR = u'%s/test_data/unittest_dir/' % os.getcwd()
BINDDIR = u'%s/test_data/bind_dir/' % os.getcwd()
-NAMED_DIR = u'%s/test_data/bind_dir/named/' % os.getcwd()
+NAMED_DIR = unicode(os.path.join(BINDDIR, 'named'))
#bind binary files
CHECKZONE_EXEC = '/usr/sbin/named-checkzone'
CHECKCONF_EXEC = '/usr/sbin/named-checkconf'
-#SSH
SSH_ID = 'test_data/roster_id_dsa'
SSH_USER = unicode(getpass.getuser())
+
TEST_DNS_SERVER = u'localhost' # change this to real bind servers
TEST_DNS_SERVER2 = u'testns2'
SESSION_KEYFILE = 'test_data/session.key'
@@ -169,12 +169,8 @@
## kill rosterd deamon threads
if( os.path.exists(LOCKFILE) ):
os.remove(LOCKFILE)
- if( os.path.exists('%s/named' % BINDDIR) ):
- shutil.rmtree('%s/named' % BINDDIR)
- if( os.path.exists('%s/named.conf' % BINDDIR) ):
- os.remove('%s/named.conf' % BINDDIR)
- if( os.path.exists('./temp_dir') ):
- shutil.rmtree('./temp_dir')
+ if( os.path.exists(BINDDIR) ):
+ shutil.rmtree(BINDDIR)

def testEndToEnd(self):
## Bootstraps
@@ -236,17 +232,16 @@
self.fail('User tools config file was not created.')

# Copy blank named.conf to start named with
- shutil.copyfile('test_data/named.blank.conf', '%snamed.conf' % BINDDIR)
- named_file_contents = open('%s/named.conf' % BINDDIR, 'r').read()
+ shutil.copyfile('test_data/named.blank.conf',
os.path.join(BINDDIR, 'named.conf'))
+ named_file_contents =
open(os.path.join(BINDDIR, 'named.conf'), 'r').read()
named_file_contents =
named_file_contents.replace('RNDC_KEY', '%s/test_data/rndc.key' %
os.getcwd())
- named_file_contents =
named_file_contents.replace('NAMED_DIR', '%s/test_data/named' % os.getcwd())
+ named_file_contents = named_file_contents.replace('NAMED_DIR',
os.path.join(BINDDIR, 'named'))
named_file_contents =
named_file_contents.replace('NAMED_PID', '%s/test_data/named.pid' %
os.getcwd())
named_file_contents = named_file_contents.replace('RNDC_PORT',
str(self.rndc_port))
named_file_contents =
named_file_contents.replace('SESSION_KEYFILE', '%s/%s' % (os.getcwd(),
str(SESSION_KEYFILE)))
- named_file_handle = open('%s/named.conf' % BINDDIR, 'w')
+ named_file_handle = open(os.path.join(BINDDIR, 'named.conf'), 'w')
named_file_handle.write(named_file_contents)
named_file_handle.close()
- named_file_contents = open('%s/named.conf' % BINDDIR, 'r').read()
# Start named
named_proc = os.popen('/usr/sbin/named -p %s -u %s -c %s/named.conf' %
(
self.named_port, SSH_USER, BINDDIR))
@@ -378,7 +373,7 @@
USERNAME, PASSWORD, self.server_name, self.toolsconfig))
command = os.popen(command_string)
self.assertEqual(command.read(),
- 'ADDED DNS SERVER SET ASSIGNMENT: dns_server: %s dns_server_set:
set2\n' % TEST_DNS_SERVER)
+ 'CLIENT ERROR: DNS Server "%s" is already assigned to DNS Server
Set "set1"\n' % TEST_DNS_SERVER)
command.close()
## User tool: dnsmkdnsserver
## dnsmkdnsserver dns_server_set -e set4
@@ -392,7 +387,7 @@
'ADDED DNS SERVER SET: set4\n')
command.close()
## User tool: dnsmkdnsserver
- ## dnsmkdnsserver assignment -d dns2 -e set4
+ ## dnsmkdnsserver assignment -d dns1 -e set4
command_string = (
'python ../roster-user-tools/scripts/dnsmkdnsserver '
'assignment -d %s -e set4 '
@@ -401,7 +396,7 @@
USERNAME, PASSWORD, self.server_name, self.toolsconfig))
command = os.popen(command_string)
self.assertEqual(command.read(),
- 'ADDED DNS SERVER SET ASSIGNMENT: dns_server: %s dns_server_set:
set4\n' % TEST_DNS_SERVER2)
+ 'CLIENT ERROR: DNS Server "%s" is already assigned to DNS Server
Set "set3"\n' % TEST_DNS_SERVER2)
command.close()
## User tool: dnsmkdnsserver
## dnsmkdnsserver dns_server -d dns3
@@ -472,18 +467,6 @@
self.assertTrue(BINDDIR in output)
self.assertTrue(TESTDIR in output)
command.close()
- ## User tool: dnsrmdnsserver
- ## dnsrmdnsserver assignment -d dns2 -e set4
- command_string = (
- 'python ../roster-user-tools/scripts/dnsrmdnsserver '
- 'assignment -d %s -e set4 '
- '-u %s -p %s -s %s --config-file %s ' % (
- TEST_DNS_SERVER2,
- USERNAME, PASSWORD, self.server_name, self.toolsconfig))
- command = os.popen(command_string)
- self.assertEqual(command.read(),
- 'REMOVED DNS SERVER SET ASSIGNMENT: dns_server_set: set4
dns_server: %s\n' % TEST_DNS_SERVER2)
- command.close()
## User tool: dnsrmdnsserver
## dnsrmdnsserver dns_server -d dns3
command_string = (
@@ -507,7 +490,7 @@
'REMOVED DNS SERVER SET: set4\n')
command.close()
## User tool: dnsrmdnsserver
- ## dnsrmdnsserver dns_server_set -e set4
+ ## dnsrmdnsserver dns_server_set -e set5
command_string = (
'python ../roster-user-tools/scripts/dnsrmdnsserver '
'dns_server_set -e set5 '
@@ -586,25 +569,10 @@
'set dns_servers\n'
'----------------\n'
'set1 %s\n'
- 'set2 %s\n'
'set3 %s\n\n' % (
- TEST_DNS_SERVER, TEST_DNS_SERVER, TEST_DNS_SERVER2))
+ TEST_DNS_SERVER, TEST_DNS_SERVER2))
command.close()

- ## User tool: dnsauditlog
- ## dnslsauditlog --success 0
- command_string = (
- 'python ../roster-user-tools/scripts/dnslsauditlog '
- '--success 0 '
- '-u %s -p %s -s %s --config-file %s ' % (
- USERNAME, PASSWORD, self.server_name, self.toolsconfig))
- command = os.popen(command_string)
- output = command.read()
- output = re.sub("\s+"," ",output)
- output = output.split(' ')
- self.assertEqual(output[10:16],
- ['shuey', '0', "{'dns_server_name':", "u'%s'," %
TEST_DNS_SERVER2, "'dns_server_set_name':", "u'set4'}"])
- command.close()
## User tool: dnsauditlog
## dnslsauditlog --success 1
command_string = (
@@ -1112,7 +1080,7 @@
USERNAME, PASSWORD, self.server_name, self.toolsconfig))
command = os.popen(command_string)
self.assertEqual(command.read(),
- 'REMOVED VIEW view_name: view_name: test_view3 options None\n')
+ 'REMOVED VIEW view_name: view_name: test_view3\n')
command.close()
## User tool: dnslsview
## dnslsview view
@@ -2810,19 +2778,6 @@
'#192.168.2.7\n')
handle.close()

- ## User tool: dnsrmdnsserver
- ## dnsrmdnsserver dns_server_set -e set2
- command_string = (
- 'python ../roster-user-tools/scripts/dnsrmdnsserver '
- 'assignment -d %s -e set2 '
- '-u %s -p %s -s %s --config-file %s ' % (
- TEST_DNS_SERVER,
- USERNAME, PASSWORD, self.server_name, self.toolsconfig))
- command = os.popen(command_string)
- self.assertEqual(command.read(),
- 'REMOVED DNS SERVER SET ASSIGNMENT: dns_server_set: set2
dns_server: %s\n' % (
- TEST_DNS_SERVER))
- command.close()
## User tool: dnsrmdnsserver
## dnsrmdnsserver dns_server_set -e set2
command_string = (
@@ -3179,9 +3134,9 @@
self.assertEqual(command.read(),
'')
command.close()
- id = 146
+ id = 144
os.rename('%s/full_database_dump-%s.bz2' % (self.backup_dir, id),
- '%s/origdb.bz2' % self.backup_dir)
+ '%s/origdb.bz2' % self.backup_dir)
dbdump = glob.glob('%s/*-%s.*' % (self.backup_dir, id))
for db in dbdump:
if( os.path.exists(db) ):
=======================================
--- /trunk/test/roster_client_lib_test.py Fri Jul 26 00:39:54 2013
+++ /trunk/test/roster_client_lib_test.py Fri Aug 16 07:09:21 2013
@@ -176,7 +176,7 @@
self.assertRaises(
SystemExit, roster_client_lib.RunFunction,
u'ListZones', USERNAME, CREDFILE,
- server_name=self.server_name, password='wrong')
+ server_name=self.server_name, password='fakepass')

invalid_credfile = '/fake/credfile'
self.assertEqual(sys.stdout.flush(),
@@ -184,7 +184,7 @@
self.assertRaises(
SystemExit, roster_client_lib.RunFunction,
u'ListZones', USERNAME, CREDFILE,
- server_name=self.server_name, password='wrong')
+ server_name=self.server_name, password='fakepass')
self.assertEqual(sys.stdout.flush(),
'ERROR: Incorrect username/password.\n')
sys.stdout = oldstdout
@@ -216,11 +216,12 @@
cred_stat.st_mode & stat.S_IRWXO)

def testNotStarted(self):
- if( os.path.exists('/var/lock/rosterd') ):
- os.remove('/var/lock/rosterd')
+ lock_file = self.config_instance.config_file['server']['lock_file']
+ if( os.path.exists(lock_file) ):
+ os.remove(lock_file)
time.sleep(1)
- command = os.popen('python %s all' % (
- '../roster-user-tools/scripts/dnslszone'))
+ command = os.popen('python %s all -s https://%s:0' % (
+ '../roster-user-tools/scripts/dnslszone', HOST))
self.assertEqual(command.read(),
'ERROR: Roster not started.\n')
command.close()
=======================================
--- /trunk/test/tree_exporter_test.py Wed Aug 14 13:43:31 2013
+++ /trunk/test/tree_exporter_test.py Fri Aug 16 07:09:21 2013
@@ -309,7 +309,7 @@

self.assertEqual(binary_named_conf,
'#This named.conf file is autogenerated. DO NOT EDIT\n'
- 'options {
directory "/home/jpavlick/Roster/sethbug4.0/tree/trunk/test/test_data/bind_dir/named";\n'
+ 'options { directory "%s";\n'
'masterfile-format raw; };\n'
'acl secret {\n'
'\t10.10/32;\n'
@@ -360,7 +360,7 @@
'\t\tfile "internal/168.192.in-addr.aa";\n'
'\t\tallow-update { none; };\n'
'\t};\n'
- '};')
+ '};' % tree_exporter_test_lib.NAMED_DIR)

def testTreeExporterMakeNamedConf(self):
self.core_instance.SetMaintenanceFlag(1)
Reply all
Reply to author
Forward
0 new messages