Adding unit test case for auth.go 61/31361/5
authorHavaldar Girish <hg0071052@techmahindra.com>
Mon, 12 Feb 2018 04:12:47 +0000 (09:42 +0530)
committerHavaldar Girish <hg0071052@techmahindra.com>
Thu, 15 Feb 2018 05:57:40 +0000 (11:27 +0530)
Adding Unit Test case auth_test.go and auth_test.cert file for testing auth.go

Change-Id: I68611f2b17a9f37618cbc5ef8db11e6fb632b910
Issue-ID: AAF-122
Signed-off-by: Havaldar Girish <hg0071052@techmahindra.com>
sms-service/src/sms/auth/auth_test.go [new file with mode: 0644]
sms-service/src/sms/test/auth_test.cert [new file with mode: 0644]

diff --git a/sms-service/src/sms/auth/auth_test.go b/sms-service/src/sms/auth/auth_test.go
new file mode 100644 (file)
index 0000000..15f0cf3
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+* Copyright 2018 TechMahindra
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package auth
+
+import (
+       "crypto/tls"
+       "testing"
+)
+
+//Unit test to varify GetTLSconfig func and varify the tls config min version to be 771
+//Assuming cert file name as auth_test.cert
+func TestGetTLSConfig(t *testing.T) {
+       _, err := GetTLSConfig("filedoesnotexist.cert")
+       if err == nil {
+               t.Errorf("Test failed, expected error but got none")
+       }
+       tlsConfig, err := GetTLSConfig("../test/auth_test.cert")
+       expected := tls.VersionTLS12
+       actual := tlsConfig.MinVersion
+       if tlsConfig != nil {
+               if int(actual) != expected {
+                       t.Errorf("Test Failed due to version mismatch")
+               }
+       if tlsConfig == nil {
+               t.Errorf("Test Failed due to GetTLSConfig returned nil")
+               }
+       }
+}
diff --git a/sms-service/src/sms/test/auth_test.cert b/sms-service/src/sms/test/auth_test.cert
new file mode 100644 (file)
index 0000000..e36d41b
--- /dev/null
@@ -0,0 +1,59 @@
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number: 2 (0x2)
+    Signature Algorithm: ecdsa-with-SHA1
+        Issuer: C=IN, ST=MH, L=Pune, O=COE, CN=Tech Mahindra Ltd
+        Validity
+            Not Before: Feb  5 10:20:17 2018 GMT
+            Not After : Feb  5 10:20:17 2019 GMT
+        Subject: CN=Tech Mahindra Ltd, ST=MH, C=IN, O=OTC
+        Subject Public Key Info:
+            Public Key Algorithm: id-ecPublicKey
+                Public-Key: (384 bit)
+                pub: 
+                    04:9b:00:db:bf:6d:ca:2f:61:63:5a:ea:7a:ad:63:
+                    03:a4:10:52:fc:8c:90:87:3a:77:88:59:8e:6c:42:
+                    68:ac:f8:04:18:06:14:fb:d6:08:21:28:8e:1a:73:
+                    a3:89:b6:83:17:37:ba:a7:84:9e:aa:5a:81:a2:e5:
+                    22:9b:91:00:2f:7a:c9:fa:59:ca:4d:da:26:20:e3:
+                    a0:cb:72:7b:a6:ad:72:f5:73:50:36:f7:95:12:00:
+                    fb:2c:43:b2:55:48:2f
+                ASN1 OID: secp384r1
+                NIST CURVE: P-384
+        X509v3 extensions:
+            X509v3 Basic Constraints: 
+                CA:FALSE
+            X509v3 Subject Key Identifier: 
+                10:B9:8A:C9:4A:81:58:54:8E:E0:6A:74:21:01:A1:B6:48:4F:2F:CD
+            X509v3 Authority Key Identifier: 
+                keyid:9B:14:EA:95:62:80:4C:CC:71:67:EA:9B:44:97:53:DF:A8:19:E3:13
+
+            X509v3 Key Usage: 
+                Digital Signature, Key Encipherment
+            X509v3 Extended Key Usage: 
+                TLS Web Server Authentication, TLS Web Client Authentication
+            X509v3 Subject Alternative Name: 
+                IP Address:127.0.0.1
+    Signature Algorithm: ecdsa-with-SHA1
+         30:65:02:30:0d:a4:a7:8c:56:5c:27:c9:25:17:11:03:aa:5d:
+         9c:90:27:34:3a:a7:db:4c:ee:7d:6e:b6:22:12:16:15:6b:5e:
+         3d:c1:54:46:8d:c2:26:d1:16:89:5c:9a:4a:a8:da:bd:02:31:
+         00:a0:ee:58:e4:00:7f:11:f7:65:5f:30:1b:d3:56:99:ce:0d:
+         22:b7:f1:6d:41:01:59:89:8d:4a:ff:4c:72:6e:09:21:4e:d1:
+         89:3f:91:63:14:a9:c0:b5:5e:7b:30:bf:7e
+-----BEGIN CERTIFICATE-----
+MIICTTCCAdSgAwIBAgIBAjAJBgcqhkjOPQQBMFMxCzAJBgNVBAYTAklOMQswCQYD
+VQQIDAJNSDENMAsGA1UEBwwEUHVuZTEMMAoGA1UECgwDQ09FMRowGAYDVQQDDBFU
+ZWNoIE1haGluZHJhIEx0ZDAeFw0xODAyMDUxMDIwMTdaFw0xOTAyMDUxMDIwMTda
+MEQxGjAYBgNVBAMMEVRlY2ggTWFoaW5kcmEgTHRkMQswCQYDVQQIDAJNSDELMAkG
+A1UEBhMCSU4xDDAKBgNVBAoMA09UQzB2MBAGByqGSM49AgEGBSuBBAAiA2IABJsA
+279tyi9hY1rqeq1jA6QQUvyMkIc6d4hZjmxCaKz4BBgGFPvWCCEojhpzo4m2gxc3
+uqeEnqpagaLlIpuRAC96yfpZyk3aJiDjoMtye6atcvVzUDb3lRIA+yxDslVIL6OB
+izCBiDAJBgNVHRMEAjAAMB0GA1UdDgQWBBQQuYrJSoFYVI7ganQhAaG2SE8vzTAf
+BgNVHSMEGDAWgBSbFOqVYoBMzHFn6ptEl1PfqBnjEzALBgNVHQ8EBAMCBaAwHQYD
+VR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMA8GA1UdEQQIMAaHBH8AAAEwCQYH
+KoZIzj0EAQNoADBlAjANpKeMVlwnySUXEQOqXZyQJzQ6p9tM7n1utiISFhVrXj3B
+VEaNwibRFolcmkqo2r0CMQCg7ljkAH8R92VfMBvTVpnODSK38W1BAVmJjUr/THJu
+CSFO0Yk/kWMUqcC1Xnswv34=
+-----END CERTIFICATE-----