-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathTLSARecordTest.java
More file actions
65 lines (58 loc) · 2.13 KB
/
Copy pathTLSARecordTest.java
File metadata and controls
65 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: BSD-3-Clause
package org.xbill.DNS;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.xbill.DNS.utils.base16;
class TLSARecordTest {
@ParameterizedTest
@ValueSource(strings = {"CAFE", "CAFE CAFFEE"})
void rdataFromString(String rdata) throws IOException {
try (Tokenizer t = new Tokenizer("0 0 1 " + rdata)) {
TLSARecord tlsaRecord = new TLSARecord();
tlsaRecord.rdataFromString(t, null);
assertEquals(TLSARecord.CertificateUsage.CA_CONSTRAINT, tlsaRecord.getCertificateUsage());
assertEquals(TLSARecord.MatchingType.SHA256, tlsaRecord.getMatchingType());
assertEquals(TLSARecord.Selector.FULL_CERTIFICATE, tlsaRecord.getSelector());
assertArrayEquals(base16.fromString(rdata), tlsaRecord.getCertificateAssociationData());
}
}
@Test
void emptyAssociationDataFromWire() {
TLSARecord tlsaRecord = new TLSARecord();
DNSInput in = new DNSInput(new byte[] {0, 0, 1});
assertThrows(WireParseException.class, () -> tlsaRecord.rrFromWire(in));
}
@ParameterizedTest
@ValueSource(
strings = {
"",
"0 0 1",
"0 0 1 CAFEBABEZ",
"0 0 1 CAFEBABEZ-",
"0 0 1 A",
"3 1 1 0D6FCE13243AA-"
})
void invalidRdataFromString(String rdata) {
try (Tokenizer t = new Tokenizer(rdata)) {
TLSARecord tlsaRecord = new TLSARecord();
assertThrows(TextParseException.class, () -> tlsaRecord.rdataFromString(t, null));
}
}
@Test
void emptyAssociationDataConstruction() {
assertThrows(
IllegalArgumentException.class,
() -> new TLSARecord(Name.root, DClass.IN, 3600, 0, 0, 1, new byte[0]));
}
@Test
void nullAssociationDataConstruction() {
assertThrows(
IllegalArgumentException.class,
() -> new TLSARecord(Name.root, DClass.IN, 3600, 0, 0, 1, null));
}
}