commit 7efb97ffe9809344f007e82b693bb6190c8381d0
parent 1d211abf5960635bd4c3135f80c0231120897b66
Author: rexxnor <rexxnor+gnunet@brief.li>
Date: Fri, 21 Sep 2018 20:11:13 +0200
fixes, added a few tests, updated README and requirements
Diffstat:
5 files changed, 127 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
@@ -2,3 +2,26 @@
The main goal is to develop a tool to easily migrate existing DNS Zones to the
GNU Name System
+
+## How to use
+
+To use the program simply execute python3 on the gnsmigrator.py file.
+At a later stage this will be possible to do by installing the program and after execute it directly using "gnsmigrator"
+
+
+Taken from the dosctring of the gnsmigrator.py file:
+```
+GNS Migrator
+
+Usage:
+ gnsmigrator.py <file>
+ gnsmigrator.py -h | --help
+ gnsmigrator.py --version
+
+Options:
+ <file> CSV File containing domains to transfer
+ -h --help Show this screen.
+ --version Show version.
+```
+
+
diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py
@@ -7,8 +7,9 @@ Usage:
gnsmigrator.py --version
Options:
+ <file> CSV File containing domains to transfer
-h --help Show this screen.
- --version Show version.
+ -v --version Show version.
"""
# imports
@@ -28,7 +29,6 @@ class GNSMigrator():
"""
Class that provides functionality to migrate zones
"""
-
@classmethod
def __init__(cls, domainlist):
cls.domainlist = domainlist
@@ -108,8 +108,9 @@ class GNSMigrator():
def add_records_to_gns(zonename, zone, domain):
"""
Checks if records are present
- :param param1: zone to lookup
- :returns: parts of zone that are not in GNS
+ :param zonename: zonename of zone to add records to
+ :param zone: the transfered zone
+ :param domain: full domain of zone
"""
# can optimize with for record in zone.iterate_rdatas.filter()
for record in zone.iterate_rdatas():
@@ -134,7 +135,7 @@ class GNSMigrator():
'-V', value,
'-e', '%ds' % ttl])
if rtype_str in ['A', 'AAAA']:
- # This is EXPERIMENTAL
+ # This is EXPERIMENTAL LEgacy HOstname implementation
subprocess.run([GNUNET_NAMESTORE_COMMAND,
'-z', zonename,
'-a', '-n', dnsname_str,
@@ -155,7 +156,7 @@ def main():
"""
Initializes object and handles arguments
"""
- args = docopt.docopt(__doc__, version='GNS Migrator 0.1a')
+ args = docopt.docopt(__doc__, version='GNS Migrator 0.0.1')
csvfile = args['<file>']
domainlist = []
with open(csvfile, 'r') as openedcsv:
@@ -171,10 +172,10 @@ def main():
zone, xfrinfo = zonetuple
zonename = gnsmigrator.get_lowest_domain_part(domain)
gnsmigrator.add_records_to_gns(zonename, zone, domain)
- print(xfrinfo)
- # gnsmigrator.add_records_to_gns(remaining_records)
+ # retain the information needed for a second zone transfer
+ #print(xfrinfo)
if __name__ == '__main__':
- # ensure gnunet is runnning
+ # TODO ensure gnunet is runnning
main()
diff --git a/gnsmigrator/gnsmigrator_unit_tests.py b/gnsmigrator/gnsmigrator_unit_tests.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+"""
+Tests of gnsmigrator
+"""
+
+import subprocess
+import unittest
+from unittest import TestCase
+import dns.exception
+import dns.resolver
+import gnsmigrator
+
+
+class TestGNSMigrator(TestCase):
+ """
+ Short Unit Tests for WebArchiver
+ """
+
+ def setUp(self):
+ """
+ Prepare data for tests
+ """
+ self.gnsmigrator = gnsmigrator.GNSMigrator(["example.fantasy"])
+ self.gnsmigrator2 = gnsmigrator.GNSMigrator(["example.com"])
+ self.gnsmigrator3 = gnsmigrator.GNSMigrator(["bfh.ch"])
+
+ def test_constructor(self):
+ """
+ Tests constructor
+ """
+ self.assertEqual("example.fantasy", self.gnsmigrator.domainlist)
+
+ def test_get_lowest_domain_part(self):
+ """
+ Tests constructor
+ """
+ self.assertEqual("example", self.gnsmigrator.get_lowest_domain_part(
+ self.gnsmigrator.domainlist[0]))
+
+ def test_bootstrap_zones(self):
+ """
+ Tests bootstrapping of zones
+ """
+ self.gnsmigrator.bootstrap_zones()
+ self.assertIn('example', subprocess.check_output(['gnunet-identity', '-d']))
+ self.assertIn('fantasy', subprocess.check_output(['gnunet-identity', '-d']))
+
+ def test_initial_zone_transfer(self):
+ """
+ Tests different ways of zone transfer not working
+ """
+ self.assertRaises(dns.resolver.NoAnswer, self.gnsmigrator.initial_zone_transfer())
+ self.assertRaises(dns.resolver.NoAnswer, self.gnsmigrator2.initial_zone_transfer())
+ self.assertRaises(dns.exception.FormError, self.gnsmigrator3.initial_zone_transfer())
+
+def main():
+ """
+ Main method
+ """
+ unittest.main()
+
+
+if __name__ == "__main__":
+ main()
diff --git a/requirements.txt b/requirements.txt
@@ -1,4 +1,5 @@
cffi==1.11.5
+coverage==4.5.1
dnspython==1.15.0
docopt==0.6.2
pycparser==2.18
diff --git a/setup.py b/setup.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+"""
+Setup file for installing the package
+"""
+
+import setuptools
+
+with open("README.md", "r") as fh:
+ long_description = fh.read()
+
+setuptools.setup(
+ name="gnsmigrator",
+ version="0.0.1",
+ author="Patrick Gerber",
+ author_email="patrick.gerber@students.bfh.ch",
+ description="Tool to migrate DNS Zones to the GNU Name System",
+ long_description=long_description,
+ long_description_content_type="text/markdown",
+ url="https://gitlab.ti.bfh.ch/gerbp6/gnsmigrator",
+ packages=setuptools.find_packages(),
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ ],
+ entry_points={
+ 'console_scripts': [
+ 'gnsmigrator=gnsmigrator:main',
+ ],
+ },
+)