View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.http.ssl;
29  
30  import static org.junit.jupiter.api.Assertions.assertNull;
31  import static org.junit.jupiter.api.Assertions.assertTrue;
32  
33  import org.apache.hc.core5.http.ParseException;
34  import org.junit.jupiter.api.Assertions;
35  import org.junit.jupiter.api.Test;
36  
37  class TLSTest {
38  
39  
40      @Test
41      void isSame() throws ParseException {
42          assertTrue(TLS.V_1_0.isSame(TLS.parse("TLSv1")));
43      }
44  
45      @Test
46      void isComparable() throws ParseException {
47          assertTrue(TLS.V_1_0.isComparable(TLS.parse("TLSv1")));
48      }
49  
50      @Test
51      void greaterEquals() throws ParseException {
52          assertTrue(TLS.V_1_3.greaterEquals(TLS.parse("TLSv1")));
53      }
54  
55      @Test
56      void lessEquals() throws ParseException {
57          assertTrue(TLS.V_1_0.lessEquals(TLS.parse("TLSv1.3")));
58      }
59  
60      @Test
61      void parse() throws ParseException {
62          assertTrue(TLS.V_1_0.lessEquals(TLS.parse("TLSv1.3")));
63      }
64  
65      @Test
66      void parseNull() throws ParseException {
67          assertNull(TLS.parse(null));
68      }
69  
70      @Test
71      void excludeWeakNull() {
72          assertNull((TLS.excludeWeak((String[]) null)));
73      }
74  
75      @Test
76      void excludeWeak() {
77          final String[] mixProtocol = {
78                  "SSL 2.0",
79                  "TLS 1.3",
80                  "SSL 3.0",
81                  "TLS 1.2",
82                  "TLS 1.1"
83          };
84          final String[] strongProtocols = TLS.excludeWeak(mixProtocol);
85          for (final String protocol : strongProtocols) {
86              Assertions.assertTrue(TLS.isSecure(protocol));
87          }
88      }
89  }