Fix ode-engine-unit-tests 88/160488/4
authorPawel Kowalski <p.kowalski2@partner.samsung.com>
Thu, 16 Nov 2017 09:07:44 +0000 (10:07 +0100)
committerPawel Kowalski <p.kowalski2@partner.samsung.com>
Wed, 22 Nov 2017 07:42:42 +0000 (08:42 +0100)
Change-Id: If14ed39db1806d821303dc792a206db91107f93f

server/engine/encryption/dmcrypt-engine.cpp
tests/dmcrypt-engine.cpp
tests/ext4-engine.cpp

index 5cd3163..e6f8872 100644 (file)
@@ -197,6 +197,8 @@ void destroyCryptoBlkDev(const std::string &cryptoBlkDev)
 
 ode::DMCryptEngine::data sanitizeKey(const ode::DMCryptEngine::data &key)
 {
+       if (key.size() < DM_KEY_MIN_LEN_BYTE)
+               throw runtime::Exception("Size of key smaller than minimum 32B");
        ode::DMCryptEngine::data sanitized(key);
        sanitized.resize(DM_KEY_MIN_LEN_BYTE);
        return sanitized;
index 084a3bf..d355291 100644 (file)
@@ -44,10 +44,13 @@ TESTCASE(DMCryptConvertKeyToHexAsciiSingle16byte)
 {
        try {
                const ode::DMCryptEngine::data master_key = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
+               const std::string master_key_ascii = ode::convertToHex(master_key);
+               // the string master_key_ascii is equal to "000102030405060708090a0b0c0d0e0f" after conversion
+
                ode::DMCryptEngine::data answer = {0x30, 0x30, 0x30, 0x31, 0x30, 0x32, 0x30, 0x33, 0x30, 0x34, 0x30, 0x35, 0x30, 0x36, 0x30, 0x37,
-                                                                                  0x30, 0x38, 0x30, 0x39, 0x30, 0x41, 0x30, 0x42, 0x30, 0x43, 0x30, 0x44, 0x30, 0x45, 0x30, 0x46
+                                                                                  0x30, 0x38, 0x30, 0x39, 0x30, 0x61, 0x30, 0x62, 0x30, 0x63, 0x30, 0x64, 0x30, 0x65, 0x30, 0x66
                                                                                  };
-               const std::string master_key_ascii = ode::convertToHex(master_key);
+               // the answer is a set of hex codes of ASCII symbols in master_key_ascii string, e.g. hex(a) = 0x61
 
                // check
                for (unsigned int i = 0; i < master_key.size() * 2; i++) {
@@ -65,10 +68,13 @@ TESTCASE(DMCryptConvertKeyToHexAsciiDouble16byte)
 {
        try {
                const ode::DMCryptEngine::data master_key = {0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87, 0x78, 0x69, 0x5A, 0x4B, 0x3C, 0x2D, 0x1E, 0x0F};
-               ode::DMCryptEngine::data answer = {0x46, 0x30, 0x45, 0x31, 0x44, 0x32, 0x43, 0x33, 0x42, 0x34, 0x41, 0x35, 0x39, 0x36, 0x38, 0x37,
-                                                                                  0x37, 0x38, 0x36, 0x39, 0x35, 0x41, 0x34, 0x42, 0x33, 0x43, 0x32, 0x44, 0x31, 0x45, 0x30, 0x46
-                                                                                 };
                const std::string master_key_ascii = ode::convertToHex(master_key);
+               // the string master_key_ascii is equal to "f0e1d2c3b4a5968778695a4b3c2d1e0f" after conversion
+
+               ode::DMCryptEngine::data answer = {0x66, 0x30, 0x65, 0x31, 0x64, 0x32, 0x63, 0x33, 0x62, 0x34, 0x61, 0x35, 0x39, 0x36, 0x38, 0x37,
+                                                                                  0x37, 0x38, 0x36, 0x39, 0x35, 0x61, 0x34, 0x62, 0x33, 0x63, 0x32, 0x64, 0x31, 0x65, 0x30, 0x66
+                                                                                 };
+               // the answer is a set of hex codes of ASCII symbols in master_key_ascii string, e.g. hex(a) = 0x61
 
                // check
                for (unsigned int i = 0; i < master_key.size() * 2; i++)
@@ -86,11 +92,10 @@ TESTCASE(DMCryptSanitizeKey)
                // -- expected: cause exception
                {
                        const std::string keystring = "SMALLER_THAN_32BYTES______";
-                       const ode::DMCryptEngine::data keySmall32bit(keystring.begin(), keystring.end());
+                       const ode::DMCryptEngine::data shortKey(keystring.begin(), keystring.end());
                        try {
-                               ode::sanitizeKey(keySmall32bit);
-                               //
-                               TEST_FAIL("small key should be cause exception");
+                               ode::sanitizeKey(shortKey);
+                               TEST_FAIL("small key should cause an exception");
                        } catch (runtime::Exception &e) {
                                // expected result: it's good
                        }
index d0efba5..97b3350 100755 (executable)
@@ -27,7 +27,7 @@ TESTCASE(Ext4GetPathTest)
        try {
                ode::ProgressBar progress([](int v) {});
                ode::Ext4Engine engine("/dev/mmcblkp0", "/opt/usr", progress);
-               if (engine.getDestination() != "/dev/mmcblkp0") {
+               if (engine.getSource() != "/dev/mmcblkp0") {
                        throw runtime::Exception("Source doen't match");
                }
                if (engine.getDestination() != "/opt/usr") {