Skip to content

Commit f28e62b

Browse files
committed
Add a test for public bugs 2111 and 2136.
Bug: 22602137 Bug: 22104401 Change-Id: I5c994de53b5906416767a8a1abe38fe59afb7cc0
1 parent 87cfc70 commit f28e62b

1 file changed

Lines changed: 67 additions & 1 deletion

File tree

services/tests/servicestests/src/android/net/dhcp/DhcpPacketTest.java

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
import android.net.LinkAddress;
2222
import android.system.OsConstants;
2323
import android.test.suitebuilder.annotation.SmallTest;
24-
import junit.framework.TestCase;
24+
import com.android.internal.util.HexDump;
2525

2626
import java.net.Inet4Address;
2727
import java.nio.ByteBuffer;
2828
import java.util.ArrayList;
2929

30+
import junit.framework.TestCase;
3031
import libcore.util.HexEncoding;
3132

3233
import static android.net.dhcp.DhcpPacket.*;
@@ -370,4 +371,69 @@ public void testPadAndOverloadedOptionsOffer() throws Exception {
370371
assertDhcpResults("172.17.152.118/16", "172.17.1.1", "172.17.1.1",
371372
null, "1.1.1.1", null, 43200, false, dhcpResults);
372373
}
374+
375+
@SmallTest
376+
public void testBug2111() throws Exception {
377+
final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode((
378+
// IP header.
379+
"4500014c00000000ff119beac3eaf3880a3f5d04" +
380+
// UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
381+
"0043004401387464" +
382+
// BOOTP header.
383+
"0201060002554812000a0000000000000a3f5d040000000000000000" +
384+
// MAC address.
385+
"00904c00000000000000000000000000" +
386+
// Server name.
387+
"0000000000000000000000000000000000000000000000000000000000000000" +
388+
"0000000000000000000000000000000000000000000000000000000000000000" +
389+
// File.
390+
"0000000000000000000000000000000000000000000000000000000000000000" +
391+
"0000000000000000000000000000000000000000000000000000000000000000" +
392+
"0000000000000000000000000000000000000000000000000000000000000000" +
393+
"0000000000000000000000000000000000000000000000000000000000000000" +
394+
// Options.
395+
"638253633501023604c00002fe33040000bfc60104fffff00003040a3f50010608c0000201c0000202" +
396+
"0f0f646f6d61696e3132332e636f2e756b0000000000ff00000000"
397+
).toCharArray(), false));
398+
399+
DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
400+
assertTrue(offerPacket instanceof DhcpOfferPacket);
401+
DhcpResults dhcpResults = offerPacket.toDhcpResults();
402+
assertDhcpResults("10.63.93.4/20", "10.63.80.1", "192.0.2.1,192.0.2.2",
403+
"domain123.co.uk", "192.0.2.254", null, 49094, false, dhcpResults);
404+
}
405+
406+
@SmallTest
407+
public void testBug2136() throws Exception {
408+
final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode((
409+
// Ethernet header.
410+
"bcf5ac000000d0c7890000000800" +
411+
// IP header.
412+
"4500014c00000000ff119beac3eaf3880a3f5d04" +
413+
// UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
414+
"0043004401387574" +
415+
// BOOTP header.
416+
"0201060163339a3000050000000000000a209ecd0000000000000000" +
417+
// MAC address.
418+
"bcf5ac00000000000000000000000000" +
419+
// Server name.
420+
"0000000000000000000000000000000000000000000000000000000000000000" +
421+
"0000000000000000000000000000000000000000000000000000000000000000" +
422+
// File.
423+
"0000000000000000000000000000000000000000000000000000000000000000" +
424+
"0000000000000000000000000000000000000000000000000000000000000000" +
425+
"0000000000000000000000000000000000000000000000000000000000000000" +
426+
"0000000000000000000000000000000000000000000000000000000000000000" +
427+
// Options.
428+
"6382536335010236040a20ff80330400001c200104fffff00003040a20900106089458413494584135" +
429+
"0f0b6c616e63732e61632e756b000000000000000000ff00000000"
430+
).toCharArray(), false));
431+
432+
DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2);
433+
assertTrue(offerPacket instanceof DhcpOfferPacket);
434+
assertEquals("BCF5AC000000", HexDump.toHexString(offerPacket.getClientMac()));
435+
DhcpResults dhcpResults = offerPacket.toDhcpResults();
436+
assertDhcpResults("10.32.158.205/20", "10.32.144.1", "148.88.65.52,148.88.65.53",
437+
"lancs.ac.uk", "10.32.255.128", null, 7200, false, dhcpResults);
438+
}
373439
}

0 commit comments

Comments
 (0)