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 package org.apache.hc.core5.http.ssl;
29
30 import org.apache.hc.core5.http.ParseException;
31 import org.apache.hc.core5.http.ProtocolVersion;
32 import org.apache.hc.core5.util.Tokenizer;
33 import org.hamcrest.CoreMatchers;
34 import org.hamcrest.MatcherAssert;
35 import org.junit.Before;
36 import org.junit.Test;
37
38
39
40
41 public class TestTlsVersionParser {
42
43 private TlsVersionParser impl;
44
45 @Before
46 public void setup() {
47 impl = new TlsVersionParser();
48 }
49
50 @Test
51 public void testParseBasic() throws Exception {
52 MatcherAssert.assertThat(impl.parse("TLSv1"), CoreMatchers.equalTo(TLS.V_1_0.version));
53 MatcherAssert.assertThat(impl.parse("TLSv1.1"), CoreMatchers.equalTo(TLS.V_1_1.version));
54 MatcherAssert.assertThat(impl.parse("TLSv1.2"), CoreMatchers.equalTo(TLS.V_1_2.version));
55 MatcherAssert.assertThat(impl.parse("TLSv1.3"), CoreMatchers.equalTo(TLS.V_1_3.version));
56 MatcherAssert.assertThat(impl.parse("TLSv22.356"), CoreMatchers.equalTo(new ProtocolVersion("TLS", 22, 356)));
57 }
58
59 @Test
60 public void testParseBuffer() throws Exception {
61 final Tokenizer.Cursor cursor = new Tokenizer.Cursor(1, 13);
62 MatcherAssert.assertThat(impl.parse(" TLSv1.2,0000", cursor, Tokenizer.INIT_BITSET(',')),
63 CoreMatchers.equalTo(TLS.V_1_2.version));
64 MatcherAssert.assertThat(cursor.getPos(), CoreMatchers.equalTo(8));
65 }
66
67 @Test(expected = ParseException.class)
68 public void testParseFailure1() throws Exception {
69 impl.parse("Tlsv1");
70 }
71
72 @Test(expected = ParseException.class)
73 public void testParseFailure2() throws Exception {
74 impl.parse("TLSV1");
75 }
76
77 @Test(expected = ParseException.class)
78 public void testParseFailure3() throws Exception {
79 impl.parse("TLSv");
80 }
81
82 @Test(expected = ParseException.class)
83 public void testParseFailure4() throws Exception {
84 impl.parse("TLSv1A");
85 }
86
87 @Test(expected = ParseException.class)
88 public void testParseFailure5() throws Exception {
89 impl.parse("TLSv1.A");
90 }
91
92 }