From 41ddd7e05a44a75923fae81e5b3439375251619a Mon Sep 17 00:00:00 2001 From: Adam Stoler Date: Tue, 18 Jan 2022 13:51:22 -0500 Subject: [PATCH] Remove incorrect check that required at least one param to be specified for ServiceMode records Add unit tests to verify that ServiceMode records without any params are allowed and can be properly converted between text and wire formats --- src/main/java/org/xbill/DNS/SVCBBase.java | 4 --- .../java/org/xbill/DNS/SVCBRecordTest.java | 25 ++++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/xbill/DNS/SVCBBase.java b/src/main/java/org/xbill/DNS/SVCBBase.java index e2aba92b..e3331c33 100644 --- a/src/main/java/org/xbill/DNS/SVCBBase.java +++ b/src/main/java/org/xbill/DNS/SVCBBase.java @@ -789,10 +789,6 @@ protected void rdataFromString(Tokenizer st, Name origin) throws IOException { } st.unget(); - if (svcPriority > 0 && svcParams.isEmpty()) { - throw new TextParseException( - "At least one parameter value must be specified for ServiceMode"); - } if (svcPriority == 0 && !svcParams.isEmpty()) { throw new TextParseException("No parameter values allowed for AliasMode"); } diff --git a/src/test/java/org/xbill/DNS/SVCBRecordTest.java b/src/test/java/org/xbill/DNS/SVCBRecordTest.java index 966c7a67..d2a8ec13 100644 --- a/src/test/java/org/xbill/DNS/SVCBRecordTest.java +++ b/src/test/java/org/xbill/DNS/SVCBRecordTest.java @@ -117,6 +117,15 @@ void aliasMode() throws IOException { assertEquals(str, wireToString(bytes)); } + @Test + void serviceModeWithoutParameters() throws IOException { + String str = "1 ."; + byte[] bytes = stringToWire(str); + byte[] expected = new byte[] {0, 1, 0}; + assertArrayEquals(expected, bytes); + assertEquals(str, wireToString(bytes)); + } + @Test void serviceModePort() throws IOException { String str = "1 . port=8443"; @@ -319,6 +328,7 @@ void masterFormatParsing() throws IOException { + "test.net. 86400 IN NS ns1.test.net.\n" + "test.net. 300 IN HTTPS 0 www.test.net.\n" + "test.net. 300 IN SVCB 1 . alpn=h2\n" + + "test.net. 300 IN HTTPS 1 .\n" + "www.test.net. 300 IN A 1.2.3.4\n"; Master m = new Master(new ByteArrayInputStream(str.getBytes())); @@ -333,6 +343,9 @@ void masterFormatParsing() throws IOException { assertEquals(Type.SVCB, r.getType()); assertEquals("1 . alpn=h2", r.rdataToString()); r = m.nextRecord(); + assertEquals(Type.HTTPS, r.getType()); + assertEquals("1 .", r.rdataToString()); + r = m.nextRecord(); assertEquals(Type.A, r.getType()); assertEquals("1.2.3.4", r.rdataToString()); r = m.nextRecord(); @@ -351,12 +364,6 @@ void extraQuotesInParamValues() { assertThrows(TextParseException.class, () -> stringToWire(str)); } - @Test - void serviceModeWithoutParameters() { - String str = "1 aliasmode.example.com."; - assertThrows(TextParseException.class, () -> stringToWire(str)); - } - @Test void aliasModeWithParameters() { String str = "0 . alpn=h3"; @@ -465,12 +472,6 @@ void emptyString() { assertThrows(TextParseException.class, () -> stringToWire(str)); } - @Test - void noParamValues() { - String str = "1 ."; - assertThrows(TextParseException.class, () -> stringToWire(str)); - } - @Test void svcPriorityTooHigh() { String str = "65536 . port=443";