Unittests extend coverage 18/27918/2
authorVitalii Irkha <v.irkha@samsung.com>
Thu, 7 Feb 2019 15:16:17 +0000 (17:16 +0200)
committerAleksey Volkov <a.volkov@samsung.com>
Fri, 8 Feb 2019 09:25:53 +0000 (09:25 +0000)
Added certhelper coverage

Change-Id: I6b1a0882b0ba239f22b0eeded57d8c554944c3f0
Signed-off-by: Vitalii Irkha <v.irkha@samsung.com>
resource/csdk/security/include/internal/certhelpers.h
resource/csdk/security/unittest/SConscript
resource/csdk/security/unittest/certhelpers.cpp [new file with mode: 0644]

index f2a4cea..1bc7487 100644 (file)
 #ifndef IOTVT_SRM_CERTHELPERS_H_
 #define IOTVT_SRM_CERTHELPERS_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if defined(__WITH_TLS__) || defined(__WITH_DTLS__)
 
 #include <mbedtls/pk.h>
@@ -125,4 +129,8 @@ OCStackResult OCInternalVerifyRoleCertificate(const OicSecKey_t *certificateChai
                                               const ByteArrayLL_t *trustedCaCerts,
                                               OicSecRole_t **roles, size_t *rolesLength,
                                               struct tm *notValidAfter);
+
+#ifdef __cplusplus
+}
+#endif
 #endif
index fd91f6b..5809f13 100644 (file)
@@ -105,7 +105,8 @@ unittests_src += [
     'pbkdf2tests.cpp',
     'srmtestcommon.cpp',
     'crlresourcetest.cpp',
-    'ocsecurity.cpp'
+    'ocsecurity.cpp',
+    'certhelpers.cpp'
 ]
 
 if target_os not in ['msys_nt', 'windows']:
diff --git a/resource/csdk/security/unittest/certhelpers.cpp b/resource/csdk/security/unittest/certhelpers.cpp
new file mode 100644 (file)
index 0000000..a1303fa
--- /dev/null
@@ -0,0 +1,37 @@
+/* *****************************************************************
+ *
+ * Copyright 2019 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * 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.
+ *
+ * *****************************************************************/
+#include <gtest/gtest.h>
+#include "octypes.h"
+#include "csrresource.h"
+#include "certhelpers.h"
+
+using namespace std;
+
+#define TAG  "CERT-HLP-UT"
+
+TEST(OCInternalGenerateKeyPairTest, InvalidPK)
+{
+    EXPECT_EQ(-1, OCInternalGenerateKeyPair(NULL));
+}
+
+TEST(OCInternalIsValidCertChainTest, InvalidCertificateBuffer)
+{
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCInternalIsValidCertChain(NULL, 0));
+}