Skip to content

Commit 2cf542f

Browse files
kingleibauersachs
authored andcommitted
Add more tests for zone files (dnsjava#60)
* Add more tests for zone files * Split tests out
1 parent f358f1a commit 2cf542f

36 files changed

+781
-13
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class CAARecordTest {
10+
11+
Name n = Name.fromConstantString("my.name.");
12+
13+
@Test
14+
void ctor_6arg() {
15+
CAARecord record = new CAARecord(n, DClass.IN, 0, CAARecord.Flags.IssuerCritical, "", "");
16+
assertEquals(CAARecord.Flags.IssuerCritical, record.getFlags());
17+
assertEquals("", record.getTag());
18+
assertEquals("", record.getValue());
19+
20+
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
21+
() -> new CAARecord(n, DClass.IN, 0xABCDEL, CAARecord.Flags.IssuerCritical,
22+
new String(new char[256]), ""));
23+
assertEquals("text string too long", thrown.getMessage());
24+
}
25+
26+
@Test
27+
void rdataFromString() throws IOException {
28+
Tokenizer t = new Tokenizer(CAARecord.Flags.IssuerCritical + " issue entrust.net");
29+
CAARecord record = new CAARecord();
30+
record.rdataFromString(t, null);
31+
assertEquals("issue", record.getTag());
32+
assertEquals("entrust.net", record.getValue());
33+
}
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.xbill.DNS.utils.base64;
5+
6+
import java.io.IOException;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
class CERTRecordTest {
11+
12+
@Test
13+
void rdataFromString() throws IOException {
14+
Tokenizer t = new Tokenizer("PGP 0 0 CAFEBABE");
15+
CERTRecord record = new CERTRecord();
16+
record.rdataFromString(t, null);
17+
assertEquals(0, record.getAlgorithm());
18+
assertEquals(0, record.getKeyTag());
19+
assertArrayEquals(base64.fromString("CAFEBABE"), record.getCert());
20+
}
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class DLVRecordTest {
10+
11+
Name n = Name.fromConstantString("my.name.");
12+
13+
@Test
14+
void ctor_0arg() {
15+
DLVRecord record = new DLVRecord();
16+
assertEquals(0, record.getFootprint());
17+
assertEquals(0, record.getAlgorithm());
18+
assertEquals(0, record.getDigestID());
19+
assertNull(record.getDigest());
20+
}
21+
22+
@Test
23+
void ctor_7arg() {
24+
DLVRecord record = new DLVRecord(n, DClass.IN, 0, 1, 2, 3, "".getBytes());
25+
assertEquals(1, record.getFootprint());
26+
assertEquals(2, record.getAlgorithm());
27+
assertEquals(3, record.getDigestID());
28+
assertEquals(0, record.getDigest().length);
29+
}
30+
31+
@Test
32+
void rdataFromString() throws IOException {
33+
Tokenizer t = new Tokenizer("60485 5 1 CAFEBABE");
34+
DLVRecord record = new DLVRecord();
35+
record.rdataFromString(t, null);
36+
assertEquals(60485, record.getFootprint());
37+
assertEquals(5, record.getAlgorithm());
38+
assertEquals(1, record.getDigestID());
39+
assertEquals(4, record.getDigest().length);
40+
}
41+
}

src/test/java/org/xbill/DNS/DNSKEYRecordTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void test_rdataFromString() throws IOException {
100100
assertEquals(0x81, kr.getProtocol());
101101
assertEquals(DNSSEC.Algorithm.RSASHA1, kr.getAlgorithm());
102102
assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, kr.getKey());
103+
assertEquals(17895, kr.getFootprint());
103104

104105
// invalid algorithm
105106
assertThrows(TextParseException.class, () -> new DNSKEYRecord().rdataFromString(new Tokenizer(0x1212 + " " + 0xAA + " ZONE AQIDBAUGBwgJ"), null));
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.IOException;
6+
import java.net.InetAddress;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
class IPSECKEYRecordTest {
11+
12+
Name n = Name.fromConstantString("my.name.");
13+
14+
@Test
15+
void ctor_0arg() {
16+
IPSECKEYRecord record = new IPSECKEYRecord();
17+
assertEquals(0, record.getPrecedence());
18+
assertEquals(0, record.getGatewayType());
19+
assertEquals(0, record.getAlgorithmType());
20+
assertNull(record.getGateway());
21+
assertNull(record.getKey());
22+
}
23+
24+
@Test
25+
void ctor_8arg() {
26+
IPSECKEYRecord record = new IPSECKEYRecord(n, DClass.IN, 0, 1, IPSECKEYRecord.Gateway.Name, IPSECKEYRecord.Algorithm.DSA, n, "".getBytes());
27+
assertEquals(1, record.getPrecedence());
28+
assertEquals(IPSECKEYRecord.Gateway.Name, record.getGatewayType());
29+
assertEquals(IPSECKEYRecord.Algorithm.DSA, record.getAlgorithmType());
30+
assertEquals(n, record.getGateway());
31+
assertEquals(0, record.getKey().length);
32+
}
33+
34+
@Test
35+
void rdataFromString() throws IOException {
36+
Tokenizer t = new Tokenizer("10 0 2 . CAFEBABE");
37+
IPSECKEYRecord record = new IPSECKEYRecord();
38+
record.rdataFromString(t, null);
39+
assertEquals(10, record.getPrecedence());
40+
assertEquals(IPSECKEYRecord.Gateway.None, record.getGatewayType());
41+
assertEquals(IPSECKEYRecord.Algorithm.RSA, record.getAlgorithmType());
42+
assertNull(record.getGateway());
43+
assertEquals(6, record.getKey().length);
44+
record = new IPSECKEYRecord();
45+
t = new Tokenizer("( 10 1 2 192.0.2.3 CAFEBABE )");
46+
record.rdataFromString(t, null);
47+
assertEquals(1, record.getGatewayType());
48+
assertTrue(record.getGateway() instanceof InetAddress);
49+
record = new IPSECKEYRecord();
50+
t = new Tokenizer("10 2 2 2001:0DB8:0:8002::2000:1 CAFEBABE");
51+
record.rdataFromString(t, null);
52+
assertEquals(2, record.getGatewayType());
53+
assertTrue(record.getGateway() instanceof InetAddress);
54+
record = new IPSECKEYRecord();
55+
t = new Tokenizer("10 3 2 mygateway.example.com. CAFEBABE");
56+
record.rdataFromString(t, null);
57+
assertEquals(3, record.getGatewayType());
58+
assertEquals(Name.fromConstantString("mygateway.example.com."), record.getGateway());
59+
}
60+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class ISDNRecordTest {
10+
11+
Name n = Name.fromConstantString("my.name.");
12+
13+
@Test
14+
void ctor_5arg() {
15+
ISDNRecord record = new ISDNRecord(n, DClass.IN, 0, "foo", "bar");
16+
assertEquals("foo", record.getAddress());
17+
assertEquals("bar", record.getSubAddress());
18+
}
19+
20+
@Test
21+
void rdataFromString() throws IOException {
22+
Tokenizer t = new Tokenizer("150862028003217 004");
23+
ISDNRecord record = new ISDNRecord();
24+
record.rdataFromString(t, null);
25+
assertEquals("150862028003217", record.getAddress());
26+
assertEquals("004", record.getSubAddress());
27+
}
28+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class LOCRecordTest {
10+
11+
Name n = Name.fromConstantString("my.name.");
12+
13+
@Test
14+
void ctor_0arg() {
15+
LOCRecord record = new LOCRecord();
16+
assertEquals(0.0, record.getVPrecision());
17+
assertEquals(0.0, record.getHPrecision());
18+
assertEquals(-100000.0, record.getAltitude());
19+
assertEquals(-596.52323, record.getLongitude(), 0.1);
20+
assertEquals(-596.52323, record.getLatitude(), 0.1);
21+
assertEquals(0.0, record.getSize());
22+
}
23+
24+
@Test
25+
void ctor_9arg() {
26+
LOCRecord record = new LOCRecord(n, DClass.IN, 0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5);
27+
assertEquals(6.5, record.getVPrecision());
28+
assertEquals(5.5, record.getHPrecision());
29+
assertEquals(3.5, record.getAltitude());
30+
assertEquals(2.5, record.getLongitude());
31+
assertEquals(1.5, record.getLatitude());
32+
assertEquals(4.5, record.getSize());
33+
}
34+
35+
@Test
36+
void rdataFromString() throws IOException {
37+
Tokenizer t = new Tokenizer("52 22 23.000 N 4 53 32.000 E -2.00m 0.00m 10000m 10m");
38+
LOCRecord record = new LOCRecord();
39+
record.rdataFromString(t, null);
40+
assertEquals(10.0, record.getVPrecision());
41+
assertEquals(10000.0, record.getHPrecision());
42+
assertEquals(-2.0, record.getAltitude());
43+
assertEquals(4.892, record.getLongitude(), 0.1);
44+
assertEquals(52.373, record.getLatitude(), 0.1);
45+
assertEquals(0.0, record.getSize());
46+
}
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.xbill.DNS;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.io.IOException;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class MINFORecordTest {
10+
11+
Name n = Name.fromConstantString("my.name.");
12+
13+
@Test
14+
void ctor_5arg() {
15+
Name respAddress = Name.fromConstantString("example.com.");
16+
Name errorAddress = Name.fromConstantString("error.com.");
17+
MINFORecord record = new MINFORecord(n, DClass.IN, 0, respAddress, errorAddress);
18+
assertEquals(respAddress, record.getResponsibleAddress());
19+
assertEquals(errorAddress, record.getErrorAddress());
20+
}
21+
22+
@Test
23+
void rdataFromString() throws IOException {
24+
Tokenizer t = new Tokenizer("foo.com. bar.com.");
25+
MINFORecord record = new MINFORecord();
26+
record.rdataFromString(t, null);
27+
assertEquals(Name.fromConstantString("foo.com."), record.getResponsibleAddress());
28+
assertEquals(Name.fromConstantString("bar.com."), record.getErrorAddress());
29+
}
30+
}

src/test/java/org/xbill/DNS/MXRecordTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636

3737
import org.junit.jupiter.api.Test;
3838

39+
import java.io.IOException;
40+
3941
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4042
import static org.junit.jupiter.api.Assertions.assertEquals;
43+
import static org.junit.jupiter.api.Assertions.assertNull;
4144
import static org.junit.jupiter.api.Assertions.assertTrue;
4245

4346
class MXRecordTest
@@ -88,4 +91,14 @@ void test_rrToWire() throws TextParseException
8891
exp = new byte[] { 0x1F, 0x2B, 1, 'M', 1, 'O', 1, 'n', 0 };
8992
assertArrayEquals(exp, out);
9093
}
94+
95+
@Test
96+
void rdataFromString_nullMXRecord() throws IOException {
97+
Tokenizer t = new Tokenizer("0 .");
98+
MXRecord record = new MXRecord();
99+
record.rdataFromString(t, null);
100+
assertEquals(Name.fromConstantString("."), record.getTarget());
101+
assertEquals(record.getTarget(), record.getAdditionalName());
102+
assertEquals(0, record.getPriority());
103+
}
91104
}

0 commit comments

Comments
 (0)