3f7fe647ddc8a56f33fdfeb4d7f1087cb5dd92d0
[icn/sdwan.git] /
1 /*\r
2 * Copyright 2018 TechMahindra\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 *     http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15  */\r
16 \r
17 package auth\r
18 \r
19 import (\r
20         "crypto/tls"\r
21         "testing"\r
22 )\r
23 \r
24 //Unit test to varify GetTLSconfig func and varify the tls config min version to be 771\r
25 //Assuming cert file name as auth_test.cert\r
26 func TestGetTLSConfig(t *testing.T) {\r
27         _, err := GetTLSConfig("filedoesnotexist.cert", "filedoesnotexist.cert", "filedoesnotexist.cert")\r
28         if err == nil {\r
29                 t.Errorf("Test failed, expected error but got none")\r
30         }\r
31         tlsConfig, err := GetTLSConfig("../../../tests/certs/auth_test_certificate.pem",\r
32                 "../../../tests/certs/auth_test_certificate.pem",\r
33                 "../../../tests/certs/auth_test_key.pem")\r
34         if err != nil {\r
35                 t.Fatal("Test Failed as GetTLSConfig returned error: " + err.Error())\r
36         }\r
37         expected := tls.VersionTLS12\r
38         actual := tlsConfig.MinVersion\r
39         if tlsConfig != nil {\r
40                 if int(actual) != expected {\r
41                         t.Errorf("Test Failed due to version mismatch")\r
42                 }\r
43                 if tlsConfig == nil {\r
44                         t.Errorf("Test Failed due to GetTLSConfig returned nil")\r
45                 }\r
46         }\r
47 }\r