Add unit tests for increased code coverage 04/318904/1
authorTomasz Swierczek <t.swierczek@samsung.com>
Tue, 17 Sep 2024 10:40:05 +0000 (12:40 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 10 Oct 2024 15:50:26 +0000 (17:50 +0200)
Change-Id: I5ac2ce309cf55e0d98220f3d4525cbb440ea0fc2

unit-tests/test_decider.cpp
unit-tests/test_serialization.cpp

index 6328977e2769d7d417b0eefc8f1ddcf722e51e92..44509e4e27b486437f897fb530442357b0f32fc2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2023 - 2024 Samsung Electronics Co., Ltd 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.
@@ -153,4 +153,53 @@ POSITIVE_TEST_CASE(MappingTest)
        }
 }
 
+NEGATIVE_TEST_CASE(getStoreTest_n)
+{
+       Decider d;
+       CryptoBackend b;
+       GStore* s;
+       // this always has to pass
+       b = CryptoBackend::OpenSSL;
+       s = d.getStore(b);
+       BOOST_REQUIRE(s != NULL);
+       // this always has to pass
+       b = CryptoBackend::None;
+       s = d.getStore(b);
+       BOOST_REQUIRE(s == NULL);
+       b = CryptoBackend::TrustZone;
+       s = d.getStore(b);
+#ifdef TZ_BACKEND_ENABLED
+       // this passes only if TZ is enabled
+       BOOST_REQUIRE(s != NULL);
+#else
+       BOOST_REQUIRE(s == NULL);
+#endif
+       Policy priv, pub;
+       BOOST_REQUIRE_NO_THROW(d.getStore(DataType::KEY_DSA_PUBLIC, priv, pub, false, false));
+}
+
+POSITIVE_TEST_CASE(getStoreRefTest_p)
+{
+       Decider d;
+       Token t;
+       t.backendId = CryptoBackend::OpenSSL;
+       BOOST_REQUIRE_NO_THROW(d.getStore(t));
+#ifdef TZ_BACKEND_ENABLED
+       t.backendId = CryptoBackend::TrustZone;
+       BOOST_REQUIRE_NO_THROW(d.getStore(t));
+#endif
+}
+
+NEGATIVE_TEST_CASE(getStoreRefTest_n)
+{
+       Decider d;
+       Token t;
+       t.backendId = CryptoBackend::None;
+       BOOST_REQUIRE_THROW(d.getStore(t), Exc::Crypto::InternalError);
+#ifndef TZ_BACKEND_ENABLED
+       t.backendId = CryptoBackend::TrustZone;
+       BOOST_REQUIRE_THROW(d.getStore(t), Exc::Crypto::InternalError);
+#endif
+}
+
 BOOST_AUTO_TEST_SUITE_END()
index c825acd27463ddd2dda6cf39de15437fdbece0f1..2d298b16452f5a15d910b944a98e5a3b771946c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2024 Samsung Electronics Co., Ltd 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.
@@ -155,4 +155,46 @@ NEGATIVE_TEST_CASE(Serialization_CryptoAlgorithm_wrong_name)
                                                CryptoAlgorithmSerializable::UnsupportedParam);
 }
 
+POSITIVE_TEST_CASE(Serialization_Policy)
+{
+       Policy input;
+       input.extractable = false;
+       input.backend = PolicyBackend::FORCE_SOFTWARE;
+       input.password = "abc";
+
+       PolicySerializable in(input);
+       PolicySerializable output;
+
+       MessageBuffer buf;
+       buf.Push(SerializeMessage(in));
+       buf.Deserialize(output);
+
+       BOOST_REQUIRE(output.extractable == input.extractable);
+       BOOST_REQUIRE(output.backend == input.backend);
+       BOOST_REQUIRE(output.password == input.password);
+}
+
+POSITIVE_TEST_CASE(Serialization_AliasInfoVector)
+{
+       AliasInfoVector v;
+       v.push_back(AliasInfo("alias 1", 1, BackendId::SW));
+       v.push_back(AliasInfo("alias 2", 2, BackendId::TZ));
+
+       AliasInfoSerializableVector sv(v);
+       AliasInfoVector o;
+       AliasInfoSerializableVector output(o);
+
+       MessageBuffer buf;
+       buf.Push(SerializeMessage(sv));
+       buf.Deserialize(output);
+
+       BOOST_REQUIRE(o.size() == v.size());
+       BOOST_REQUIRE(o[0].alias == v[0].alias);
+       BOOST_REQUIRE(o[0].type == v[0].type);
+       BOOST_REQUIRE(o[0].backend == v[0].backend);
+       BOOST_REQUIRE(o[1].alias == v[1].alias);
+       BOOST_REQUIRE(o[1].type == v[1].type);
+       BOOST_REQUIRE(o[1].backend == v[1].backend);
+}
+
 BOOST_AUTO_TEST_SUITE_END()