Skip to content

Commit ca6b51b

Browse files
added dns integration tests
1 parent 3b9e0b9 commit ca6b51b

File tree

7 files changed

+191
-0
lines changed

7 files changed

+191
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
subrequest @DNS::Query {
2+
#
3+
# Verify that the process layer copies ID and Opcode from the
4+
# request into the reply, and sets the QR and Authoritative bits.
5+
#
6+
# ID=9999 is deliberately unusual to confirm the copy, not a
7+
# coincidental default value.
8+
#
9+
Header = {
10+
ID = 9999
11+
Opcode = ::Query
12+
}
13+
14+
call dns {
15+
# ID must be the request's ID, not some default.
16+
if (reply.Header.ID != 9999) {
17+
test_fail
18+
}
19+
20+
# QR bit must be flipped to Response by dns_fields_restore().
21+
if (reply.Header.Query != ::Response) {
22+
test_fail
23+
}
24+
25+
# Opcode must be echoed back from the request.
26+
if (reply.Header.Opcode != ::Query) {
27+
test_fail
28+
}
29+
30+
# Authoritative must default to yes when not set by the user.
31+
if (reply.Header.Authoritative != yes) {
32+
test_fail
33+
}
34+
}
35+
}

src/tests/process/dns/Query

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
subrequest @DNS::Query {
2+
#
3+
# Minimal DNS query: ID=1 routes to ok -> No-Error.
4+
#
5+
Header = {
6+
ID = 1
7+
Opcode = ::Query
8+
}
9+
10+
call dns {
11+
# rcode must be No-Error for an ok return.
12+
if (reply.Header.Rcode != ::No-Error) {
13+
test_fail
14+
}
15+
16+
# QR bit must be flipped to Response.
17+
if (reply.Header.Query != ::Response) {
18+
test_fail
19+
}
20+
21+
# ID must be echoed back from the request.
22+
if (reply.Header.ID != 1) {
23+
test_fail
24+
}
25+
}
26+
}

src/tests/process/dns/Query-Fail

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
subrequest @DNS::Query {
2+
#
3+
# ID=4 routes to fail, which must map to Server-Failure.
4+
#
5+
Header = {
6+
ID = 4
7+
Opcode = ::Query
8+
}
9+
10+
call dns {
11+
if (reply.Header.Rcode != ::Server-Failure) {
12+
test_fail
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
subrequest @DNS::Query {
2+
#
3+
# ID=5 routes to invalid, which must map to Format-Error.
4+
#
5+
Header = {
6+
ID = 5
7+
Opcode = ::Query
8+
}
9+
10+
call dns {
11+
if (reply.Header.Rcode != ::Format-Error) {
12+
test_fail
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
subrequest @DNS::Query {
2+
#
3+
# ID=2 routes to notfound, which must map to Name-Error.
4+
#
5+
Header = {
6+
ID = 2
7+
Opcode = ::Query
8+
}
9+
10+
call dns {
11+
if (reply.Header.Rcode != ::Name-Error) {
12+
test_fail
13+
}
14+
}
15+
}

src/tests/process/dns/Query-Reject

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
subrequest @DNS::Query {
2+
#
3+
# ID=3 routes to reject, which must map to Refused.
4+
#
5+
Header = {
6+
ID = 3
7+
Opcode = ::Query
8+
}
9+
10+
call dns {
11+
if (reply.Header.Rcode != ::Refused) {
12+
test_fail
13+
}
14+
}
15+
}

src/tests/process/dns/server.conf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- text -*-
2+
#
3+
# test configuration file. Do not install.
4+
#
5+
# $Id$
6+
#
7+
8+
#
9+
# Minimal dns.conf for testing the DNS process state machine.
10+
#
11+
12+
output = $ENV{OUTPUT}
13+
run_dir = ${output}
14+
pidfile = ${run_dir}/radiusd.pid
15+
panic_action = "gdb -batch -x src/tests/panic.gdb %e %p > ${run_dir}/gdb.log 2>&1; cat ${run_dir}/gdb.log"
16+
17+
raddb = raddb
18+
radacctdir = ${run_dir}/radacct
19+
modconfdir = ${raddb}/mods-config
20+
certdir = ${raddb}/certs
21+
cadir = ${raddb}/certs
22+
test_port = $ENV{TEST_PORT}
23+
24+
# Only for testing!
25+
security {
26+
allow_vulnerable_openssl = yes
27+
allow_core_dumps = yes
28+
}
29+
30+
policy {
31+
$INCLUDE ../policy.conf
32+
}
33+
34+
server dns {
35+
namespace = dns
36+
37+
#
38+
# Route test scenarios by Header.ID so a single recv section
39+
# can exercise every rcode-to-DNS-rcode mapping:
40+
#
41+
# ID 1 -> ok -> No-Error (happy path)
42+
# ID 2 -> notfound -> Name-Error
43+
# ID 3 -> reject -> Refused
44+
# ID 4 -> fail -> Server-Failure
45+
# ID 5 -> invalid -> Format-Error
46+
#
47+
# All other IDs default to ok.
48+
#
49+
recv Query {
50+
if (request.Header.ID == 2) {
51+
notfound
52+
}
53+
elsif (request.Header.ID == 3) {
54+
reject
55+
}
56+
elsif (request.Header.ID == 4) {
57+
fail
58+
}
59+
elsif (request.Header.ID == 5) {
60+
invalid
61+
}
62+
else {
63+
ok
64+
}
65+
}
66+
67+
send Query-Response {
68+
ok
69+
}
70+
}

0 commit comments

Comments
 (0)