From: Jorge Pereira Date: Tue, 4 Jul 2023 01:33:55 +0000 (-0300) Subject: tests: Add process tests for dhcpv4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=154845785fe992f18934a0de3b2bd6a64aa261f6;p=thirdparty%2Ffreeradius-server.git tests: Add process tests for dhcpv4 --- diff --git a/src/tests/process/dhcpv4/Ack b/src/tests/process/dhcpv4/Ack new file mode 100644 index 00000000000..a027e4d2404 --- /dev/null +++ b/src/tests/process/dhcpv4/Ack @@ -0,0 +1,49 @@ +subrequest DHCPv4.Request { + # Client -> Server + &request += { + &Message-Type = Request + + &Hardware-Type = Ethernet + &Hardware-Address-Length = 6 + &Hop-Count = 0 + &Transaction-Id = 15646 + &Number-of-Seconds = 0 + &Flags = 0 + + &Client-IP-Address = 0.0.0.0 + &Your-IP-Address = 0.0.0.0 + &Server-IP-Address = 0.0.0.0 + &Gateway-IP-Address = 0.0.0.0 + &Client-Hardware-Address = ca:fe:ca:fe:ca:fe + &Client-Identifier = 0x01020304050607 + &Requested-IP-Address = 192.168.0.10 + + &Server-Identifier = 192.168.0.1 + &Parameter-Request-List = Subnet-Mask + &Parameter-Request-List = Router-Address + &Parameter-Request-List = Domain-Name + &Parameter-Request-List = Domain-Name-Server + &Parameter-Request-List = NTP-Servers + &Network-Subnet = 0.0.0.0/32 + } + + call dhcpv4 { + # 'Discover' expects 'Ack' + if (&reply.Packet-Type != Ack) { + test_fail + } + + # We should reply the below attributes... + if (!&reply.Transaction-Id) { + test_fail + } + + if (&reply.Subnet-Mask != "255.255.255.0") { + test_fail + } + + if (&reply.Gateway-IP-Address != "0.0.0.0") { + test_fail + } + } +} diff --git a/src/tests/process/dhcpv4/Discover b/src/tests/process/dhcpv4/Discover new file mode 100644 index 00000000000..10695773daa --- /dev/null +++ b/src/tests/process/dhcpv4/Discover @@ -0,0 +1,49 @@ +subrequest DHCPv4.Discover { + # Server -> Client + &request += { + &Message-Type = Discover + + &Hardware-Type = Ethernet + &Hardware-Address-Length = 6 + &Hop-Count = 0 + &Transaction-Id = 12345 + &Number-of-Seconds = 0 + &Flags = 0 + + &Client-IP-Address = 0.0.0.0 + &Your-IP-Address = 0.0.0.0 + &Server-IP-Address = 0.0.0.0 + &Gateway-IP-Address = 0.0.0.0 + &Client-Hardware-Address = ca:fe:ca:fe:ca:fe + &Client-Identifier = 0x01020304050607 + &Requested-IP-Address = 0.0.0.0 + + + &Parameter-Request-List = Subnet-Mask + &Parameter-Request-List = Router-Address + &Parameter-Request-List = Domain-Name + &Parameter-Request-List = Domain-Name-Server + &Parameter-Request-List = NTP-Servers + &Network-Subnet = 0.0.0.0/32 + } + + call dhcpv4 { + # 'Discover' expects 'Offer' + if (&reply.Packet-Type != Offer) { + test_fail + } + + # We should reply the below attributes... + if (!&reply.Transaction-Id) { + test_fail + } + + if (&reply.Subnet-Mask != "255.255.255.0") { + test_fail + } + + if (&reply.Gateway-IP-Address != "0.0.0.0") { + test_fail + } + } +} diff --git a/src/tests/process/dhcpv4/server.conf b/src/tests/process/dhcpv4/server.conf new file mode 100644 index 00000000000..4020d5e66a9 --- /dev/null +++ b/src/tests/process/dhcpv4/server.conf @@ -0,0 +1,115 @@ +# -*- text -*- +# +# test configuration file. Do not install. +# +# $Id$ +# + +# +# Minimal dhcpv6.conf for testing +# + +testdir = $ENV{TESTDIR} +output = $ENV{OUTPUT} +run_dir = ${output} +raddb = raddb +pidfile = ${run_dir}/radiusd.pid +panic_action = "gdb -batch -x src/tests/panic.gdb %e %p > ${run_dir}/gdb.log 2>&1; cat ${run_dir}/gdb.log" + +maindir = ${raddb} +radacctdir = ${run_dir}/radacct +modconfdir = ${maindir}/mods-config +certdir = ${maindir}/certs +cadir = ${maindir}/certs +test_port = $ENV{TEST_PORT} + +# Only for testing! +# Setting this on a production system is a BAD IDEA. +security { + allow_vulnerable_openssl = yes +} + +policy { + $INCLUDE ../policy.conf + $INCLUDE ${raddb}/policy.d/control + $INCLUDE ${raddb}/policy.d/dhcp +} + +modules { + dhcpv4 { + ipaddr = 127.0.0.1 + # port = 68 + # interface = eth0 + # max_packet_size = 576 + # send_buff = 1048576 + } +} + +# +# This virtual server is chosen for processing requests when using: +# +# radiusd -Xd src/tests/ -i 127.0.0.1 -p 12340 -n test +# +server dhcpv4 { + namespace = dhcpv4 + listen { + type = Discover + type = Request + transport = udp + udp { + ipaddr = 127.0.0.1 + port = 67 + broadcast = no + } + } + + recv Discover { + &reply += { + &Hardware-Type = Ethernet + &Hardware-Address-Length = 6 + &Hop-Count = 0 + &Transaction-Id = 15645 + &Number-of-Seconds = 0 + &Flags = 0 + &Client-IP-Address = 0.0.0.0 + &Your-IP-Address = 192.168.0.10 + &Server-IP-Address = 192.168.0.1 + &Gateway-IP-Address = 0.0.0.0 + &Client-Hardware-Address = ca:fe:ca:fe:ca:fe + &Message-Type = Offer + &Subnet-Mask = 255.255.255.0 + &Renewal-Time = 1800 + &Rebinding-Time = 3150 + &IP-Address-Lease-Time = 3600 + &Server-Identifier = 192.168.0.1 + &Network-Subnet = 0.0.0.0/32 + &Domain-Name = "lorisdoancapistao.com" + } + ok + } + + recv Request { + &reply += { + &Hardware-Type = Ethernet + &Hardware-Address-Length = 6 + &Hop-Count = 0 + &Transaction-Id = 15646 + &Number-of-Seconds = 0 + &Flags = 0 + &Client-IP-Address = 0.0.0.0 + &Your-IP-Address = 192.168.0.10 + &Server-IP-Address = 0.0.0.0 + &Gateway-IP-Address = 0.0.0.0 + &Client-Hardware-Address = ca:fe:ca:fe:ca:fe + &Message-Type = Ack + &Renewal-Time = 1800 + &Rebinding-Time = 3150 + &IP-Address-Lease-Time = 3600 + &Server-Identifier = 192.168.0.1 + &Subnet-Mask = 255.255.255.0 + &Network-Subnet = 0.0.0.0/32 + } + ok + } +} +