Skip to content

Commit

Permalink
Update lease_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
juddin927 authored Jun 12, 2024
1 parent dc1723b commit b23bb69
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions dhcp-service/spec/lease_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,48 @@ def wait_for_leases(expected_count, retries = 5, delay = 2)
return if db_client[:lease4].count == expected_count
sleep delay
end
#raise "Expected #{expected_count} leases, got #{db_client[:lease4].count}"
raise "Expected #{expected_count} leases, got #{db_client[:lease4].count}"
end

def wait_for_packet_capture(process, packets, delay = 5)
sleep delay
sleep(packets * 0.1)
sleep delay # Ensure packet capture process has started
sleep(packets * 0.1) # Additional wait time based on number of packets
Process.wait(process) # Ensure the packet capture process has finished
end

before do
db_client[:lease4].truncate
db_client.disconnect
Process.fork { `tshark -iany -f 'ip src 172.1.0.10 and udp port 67' -w ./dhcp_offer_packet.pcap -q -a packets:10` }
sleep 10 # Adding a delay to ensure the process is ready
end

after { db_client.disconnect }

context "when ordinary dhcp clients send DHCP requests" do
it "provides 10 leases to 10 clients, leases persist in the DB and provides DHCP options from global options" do
pid = Process.fork { exec "tshark -iany -f 'ip src 172.1.0.10 and udp port 67' -w ./dhcp_offer_packet.pcap -q -a packets:10" }
sleep 5 # Ensure the process is ready

`perfdhcp -r 2 \
-n 10 \
-R 10 \
-d 2 \
-4 \
-W 20000000 \
172.1.0.10`

wait_for_leases(10)
wait_for_packet_capture()
expect(db_client[:lease4].count).to eq(10)
wait_for_packet_capture(pid, 10)
expect(dhcp_offer_packet_content).to include(File.read("./spec/fixtures/expected_lease_options_ordinary.txt"))
expect(dhcp_offer_packet_content).not_to include("Option: (234) Private")
end
end

context "when Windows 10 devices with client class value of 'W10TEST' send DHCP requests" do
it "provides a lease with DHCP options from global options but overrides dns-name option from client class options" do
`perfdhcp -r 2 \
pid = Process.fork { exec "tshark -iany -f 'ip src 172.1.0.10 and udp port 67' -w ./dhcp_offer_packet.pcap -q -a packets:3" }
sleep 5 # Ensure the process is ready

`perfdhcp -r 2 \
-n 3 \
-R 1 \
-b mac=00:0c:01:02:03:04 \
Expand All @@ -56,15 +61,19 @@ def wait_for_packet_capture(process, packets, delay = 5)
-o 77,57313054455354 \
-W 20000000 \
172.1.0.10`

wait_for_leases(3)
wait_for_packet_capture()
wait_for_packet_capture(pid, 3)
expect(dhcp_offer_packet_content).to include(File.read("./spec/fixtures/expected_lease_options_client_class.txt"))
end
end

context "when Windows 10 devices with delivery optimisation enabled send DHCP requests" do
it "provides a lease with DHCP options from global options as well as an additional option: private option 234" do
`perfdhcp -r 2 \
pid = Process.fork { exec "tshark -iany -f 'ip src 172.1.0.10 and udp port 67' -w ./dhcp_offer_packet.pcap -q -a packets:3" }
sleep 5 # Ensure the process is ready

`perfdhcp -r 2 \
-n 3 \
-R 1 \
-b mac=00:0c:01:02:03:04 \
Expand All @@ -73,8 +82,9 @@ def wait_for_packet_capture(process, packets, delay = 5)
-o 55,00EA \
-W 20000000 \
172.1.0.10`

wait_for_leases(3)
wait_for_packet_capture()
wait_for_packet_capture(pid, 3)
expect(dhcp_offer_packet_content).to include(File.read("./spec/fixtures/expected_lease_options_delivery_optimised.txt"))
end
end
Expand Down

0 comments on commit b23bb69

Please sign in to comment.