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