commit 44514ef6e9139cd675ad8a4d85a93ca91b61aac9
parent 8e08bdf35704a93f6266bf0d39569c8b7703f04c
Author: rexxnor <rexxnor+gnunet@brief.li>
Date: Mon, 12 Nov 2018 17:38:18 +0100
added testing for gnunet -K option and more
Diffstat:
7 files changed, 229 insertions(+), 2 deletions(-)
diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py
@@ -499,7 +499,7 @@ def main():
logging.critical('GNUnet Services are not running!')
sys.exit(1)
- # Not ideal as this will always be
+ # argument parsing
debug = args['--debug']
domain = args.get('<domain>', None)
transferns = args['<transferns>'] if args['<transferns>'] else None
diff --git a/gnsmigrator/gnunet.py b/gnsmigrator/gnunet.py
@@ -0,0 +1,61 @@
+from ctypes import c_char_p
+from ctypes import c_size_t
+from ctypes import c_uint32
+from ctypes import c_uint64
+from ctypes import c_void_p
+from ctypes import CDLL
+from ctypes import Structure
+from enum import Enum
+from dataclasses import dataclass
+
+class GNUnetGNSRecordFlags(Enum):
+ """
+ Flags that can be set for a record.
+ """
+ GNUNET_GNSRECORD_RF_NONE = 0
+ GNUNET_GNSRECORD_RF_PRIVATE = 2
+ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 8
+ GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16
+
+class GNUnetGNSRecordData():
+ """
+ Representation of a GNS Record in python
+ """
+ _fields_ = [("data", c_void_p),
+ ("expiration_time", c_uint64),
+ ("data_size", c_size_t),
+ ("record_type", c_uint32),
+ ("flags", GNUnetGNSRecordFlags)]
+
+class GNUnetEcdsaPrivateKey(Structure):
+ """
+ Representation of GNUNET_CRYPTO_EcdsaPrivateKey
+ """
+ _fields_ = [("d", c_char_p)]
+
+class GNUnetConfigurationHandle(Structure):
+ """
+ Representation of GNUNET_CONFIGURATION_HANDLE
+ """
+ pass
+
+class GNUnetMQHandle(Structure):
+ """
+ Representation of GNUNET_CONFIGURATION_HANDLE
+ """
+ pass
+
+class GNUnetNamestoreHandle():
+ """
+ Representation of GNUNET_NAMESTORE_Handle
+ """
+ _fields_ = [("cfg": GNUnetConfigurationHandle),
+ ("mq": GNUnetMQHandle),
+ ("op_head": GNUnetNamestoreQueueEntry),
+ ("op_tail": GNUnetNamestoreQueueEntry),
+ ("z_head": GNUnetNamestoreZoneIterator),
+ ("z_tail": GNUnetNamestoreZoneIterator),
+ ("reconnect_task": GNUnetSchedulerTask),
+ ("reconnect_delay": GNUnetTimeRelative),
+ ("reconnet": int),
+ ("last_op_id_used": c_uint32_t)]
diff --git a/gnsmigrator/test/basic_named.conf b/gnsmigrator/test/basic_named.conf
@@ -0,0 +1,25 @@
+options {
+ directory ".";
+ pid-file "/run/named/named.pid";
+
+ // Uncomment these to enable IPv6 connections support
+ // IPv4 will still work:
+ // listen-on-v6 { any; };
+ // Add this for no IPv4:
+ // listen-on { none; };
+
+ allow-recursion { 127.0.0.1; };
+ allow-transfer { 127.0.0.1; };
+ allow-update { none; };
+
+ version none;
+ hostname none;
+ server-id none;
+};
+
+zone "gnunet.org" IN {
+ type master;
+ file "gnunet.zone";
+ allow-query { any; };
+ allow-transfer { any; };
+};
diff --git a/gnsmigrator/test/gnunet.zone b/gnsmigrator/test/gnunet.zone
@@ -0,0 +1,18 @@
+$TTL 3600
+@ IN SOA ns1.gnunet.org. root.gnunet.org. (
+ 2018090830 ; Serial
+ 3600 ; Refresh
+ 1800 ; Retry
+ 604800 ; Expire
+ 3600 ) ; Negative Cache TTL
+@ IN NS ns1.gnunet.org.
+@ IN A 127.0.0.1
+www IN A 127.0.0.1
+owncloud IN A 127.0.0.1
+nextcloud IN A 127.0.0.1
+mail IN MX 10 mail.gnunet.org.
+mail IN A 127.0.0.1
+foo IN AAAA 2002::
+asdf IN CNAME www
+ns1 IN A 127.0.0.1
+ns2 IN A 37.35.124.161
diff --git a/gnsmigrator/test/test_gnsmigrator_simple.sh b/gnsmigrator/test/test_gnsmigrator_simple.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Check for required packages
+if ! [ -x "$(command -v named)" ]; then
+ echo 'bind/named is not installed' >&2
+ exit 1
+fi
+
+# Start named with a simple zone
+named -c basic_named.conf -p 5000
+
+# Check if domain resolves
+nslookup gnunet.org 127.0.0.1 -port=5000
+if $?; then
+ echo "Something went wrong with named"
+ exit 1
+fi
+
+# Let gnsmigrator run on gnunet.org test domain
+
+
+
+# Shutdown named
+pkill named
diff --git a/gnsmigrator/test/test_gnunet_multiple.sh b/gnsmigrator/test/test_gnunet_multiple.sh
@@ -0,0 +1,99 @@
+#!/bin/bash
+
+# Check for required packages
+if ! [ -x "$(command -v gnunet-namestore)" ]; then
+ echo 'bind/named is not installed' >&2
+ exit 1
+fi
+
+# Check if gnunet is running
+gnunet-arm -I 2&>1 /dev/null
+ret=$?
+if [ 0 -ne $ret ]; then
+ echo 'gnunet services are not running'
+ exit 1
+fi
+
+## GNUNET part
+# Check if identity exists and delets and readds it to get rid of entries in zone
+gnunet-identity -d | grep randomtestingid 2>&1 /dev/null
+ret=$?
+
+if [ 0 -ne $ret ]; then
+ gnunet-identity -D randomtestingid
+ gnunet-identity -C randomtestingid
+fi
+
+function minimize_ttl {
+ ttl=10000000
+ arr=$1
+ # parse each element and update ttl to smallest one
+ for i in "${arr[@]}"
+ do
+ currttl=$(echo -n "$i" | cut -d' ' -f1)
+ if [ "$currttl" -lt "$ttl" ]
+ then
+ ttl=$currttl
+ fi
+
+ done
+ echo "$ttl"
+}
+
+function get_record_type {
+ arr=$1
+ typ=$(echo -n "${arr[0]}" | cut -d' ' -f2)
+ echo "$typ"
+}
+
+function get_value {
+ arr=$1
+ val=$(echo -n "${arr[0]}" | cut -d' ' -f4)
+ echo "$val"
+}
+
+function testing {
+ label=$1
+ records=$2
+ recordstring=""
+ typ=$(get_record_type "${records[@]}")
+ for i in "${records[@]}"
+ do
+ recordstring+="-R $i"
+ done
+ #echo "$recordstring"
+ gnunet-namestore -z randomtestingid -n "$label" "$recordstring" 2>&1 /dev/null
+ if [ 0 -ne $ret ]; then
+ echo "failed to add record $label: $recordstring"
+ fi
+ gnunet-gns -t "$typ" -u foo2.randomtestingid 2>&1 /dev/null
+ if [ 0 -ne $ret ]; then
+ echo "record $label could not be found"
+ fi
+}
+
+# TEST CASES
+# 1
+echo "Testing adding of single A record with -R"
+declare -a arr=('1200 A n 127.0.0.1')
+testing test1 "${arr[@]}"
+# 2
+echo "Testing adding of multiple A records with -R"
+declare -a arr=('1200 A n 127.0.0.1' '2400 A n 127.0.0.2')
+testing test2 "${arr[@]}"
+# 3
+echo "Testing adding of multiple different records with -R"
+declare -a arr=('1200 A n 127.0.0.1' '2400 AAAA n 2002::')
+testing test3 "${arr[@]}"
+# 4
+echo "Testing adding of single GNS2DNS record with -R"
+declare -a arr=('86400 GNS2DNS n gnu.org@127.0.0.1')
+testing test4 "${arr[@]}"
+# 5
+echo "Testing adding of single GNS2DNS shadow record with -R"
+declare -a arr=('86409 GNS2DNS s gnu.org@127.0.0.250')
+testing test5 "${arr[@]}"
+# 6
+echo "Testing adding of multiple GNS2DNS record with -R"
+declare -a arr=('86400 GNS2DNS s gnunet.org@127.0.0.1' '86400 GNS2DNS s example.org@127.0.0.1')
+testing test6 "${arr[@]}"
diff --git a/setup.py b/setup.py
@@ -10,7 +10,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="gnsmigrator",
- version="0.1.1",
+ version="0.1.2",
author="Patrick Gerber",
author_email="patrick.gerber@students.bfh.ch",
description="Tool to migrate DNS Zones to the GNU Name System",