Improve negative assertions by checking the actual exceptions' content.
This commit is contained in:
@@ -28,6 +28,7 @@ add_executable(ChaosTests ${ChaosTests_SOURCE})
|
|||||||
target_link_libraries(ChaosTests gtest gtest_main)
|
target_link_libraries(ChaosTests gtest gtest_main)
|
||||||
target_include_directories(ChaosTests PRIVATE
|
target_include_directories(ChaosTests PRIVATE
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Chaos>
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Chaos>
|
||||||
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/ChaosTests>
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(ChaosTests PRIVATE -Wunused -Werror=unused)
|
target_compile_options(ChaosTests PRIVATE -Wunused -Werror=unused)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "TestHelpers/AssertThrowEx.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -62,8 +63,17 @@ TEST(Arc4CryptTests, UninitializedArc4CryptTest)
|
|||||||
std::array<uint8_t, 10> in = {};
|
std::array<uint8_t, 10> in = {};
|
||||||
std::array<uint8_t, 10> out = {};
|
std::array<uint8_t, 10> out = {};
|
||||||
|
|
||||||
ASSERT_THROW(arc4.Encrypt(out.begin(), in.begin(), in.size()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(arc4.Encrypt(out.begin(), in.begin(), in.size()),
|
||||||
ASSERT_THROW(arc4.Decrypt(out.begin(), in.begin(), in.size()), Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Crypt: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(arc4.Decrypt(out.begin(), in.begin(), in.size()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Crypt: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "TestHelpers/AssertThrowEx.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@@ -322,9 +323,17 @@ TEST(Arc4GenTests, TooSmallKeyTest)
|
|||||||
const char * key = "smal";
|
const char * key = "smal";
|
||||||
|
|
||||||
Arc4Gen gen;
|
Arc4Gen gen;
|
||||||
ASSERT_THROW(gen.Rekey(key, key + strlen(key)), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(gen.Rekey(key, key + strlen(key)),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: key is too small", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
ASSERT_THROW(Arc4Gen(key, key + strlen(key)), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(Arc4Gen(key, key + strlen(key)),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: key is too small", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,12 +344,35 @@ TEST(Arc4GenTests, UninitializedGenTest)
|
|||||||
{
|
{
|
||||||
Arc4Gen gen;
|
Arc4Gen gen;
|
||||||
|
|
||||||
ASSERT_THROW(gen.Generate(out.begin(), out.size()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(gen.Generate(out.begin(), out.size()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
ASSERT_THROW(gen.Drop(0), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(gen.Drop(0),
|
||||||
ASSERT_THROW(gen.Drop(1), Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
ASSERT_THROW(gen.Drop(20), Chaos::Service::ChaosException);
|
{
|
||||||
ASSERT_THROW(gen.Drop(256), Chaos::Service::ChaosException);
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(gen.Drop(1),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(gen.Drop(20),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(gen.Drop(256),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -348,14 +380,41 @@ TEST(Arc4GenTests, UninitializedGenTest)
|
|||||||
|
|
||||||
Arc4Gen gen;
|
Arc4Gen gen;
|
||||||
|
|
||||||
ASSERT_THROW(gen.Rekey(key, key + strlen(key)), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(gen.Rekey(key, key + strlen(key)),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: key is too small", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
ASSERT_THROW(gen.Generate(out.begin(), out.size()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(gen.Generate(out.begin(), out.size()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
ASSERT_THROW(gen.Drop(0), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(gen.Drop(0),
|
||||||
ASSERT_THROW(gen.Drop(1), Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
ASSERT_THROW(gen.Drop(20), Chaos::Service::ChaosException);
|
{
|
||||||
ASSERT_THROW(gen.Drop(256), Chaos::Service::ChaosException);
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(gen.Drop(1),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(gen.Drop(20),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(gen.Drop(256),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Arc4Gen: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "TestHelpers/AssertThrowEx.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -366,7 +367,13 @@ TEST(DesCryptTests, ShortKeyTest)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::array<uint8_t, DesCrypt::KeySize - 1> key = {};
|
std::array<uint8_t, DesCrypt::KeySize - 1> key = {};
|
||||||
ASSERT_THROW(DesCrypt::Key(key.begin(), key.end()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(DesCrypt::Key(key.begin(), key.end()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("DesCrypt::Key: invalid key length "
|
||||||
|
"(8 bytes required)",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +381,13 @@ TEST(DesCryptTests, LongKeyTest)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::array<uint8_t, DesCrypt::KeySize + 1> key = {};
|
std::array<uint8_t, DesCrypt::KeySize + 1> key = {};
|
||||||
ASSERT_THROW(DesCrypt::Key(key.begin(), key.end()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(DesCrypt::Key(key.begin(), key.end()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("DesCrypt::Key: invalid key length "
|
||||||
|
"(8 bytes required)",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "TestHelpers/AssertThrowEx.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -384,8 +385,12 @@ TEST(EcbModeTests, EncryptInsufficientBufferTest)
|
|||||||
|
|
||||||
EcbMode<Des::DesCrypt, PadderPkcs7>::Encryptor enc(desKey);
|
EcbMode<Des::DesCrypt, PadderPkcs7>::Encryptor enc(desKey);
|
||||||
|
|
||||||
ASSERT_THROW(enc.Update(out.begin(), out.end(), data.begin(), data.end()),
|
ASSERT_THROW_EX(enc.Update(out.begin(), out.end(), data.begin(), data.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Encryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -394,8 +399,12 @@ TEST(EcbModeTests, EncryptInsufficientBufferTest)
|
|||||||
|
|
||||||
EcbMode<Des::DesCrypt, PadderPkcs7>::Encryptor enc(desKey);
|
EcbMode<Des::DesCrypt, PadderPkcs7>::Encryptor enc(desKey);
|
||||||
|
|
||||||
ASSERT_THROW(enc.Update(out.begin(), out.end(), data.begin(), data.end()),
|
ASSERT_THROW_EX(enc.Update(out.begin(), out.end(), data.begin(), data.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Encryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -409,8 +418,12 @@ TEST(EcbModeTests, EncryptInsufficientBufferTest)
|
|||||||
|
|
||||||
enc.Update(out1.begin(), out1.end(), data1.begin(), data1.end());
|
enc.Update(out1.begin(), out1.end(), data1.begin(), data1.end());
|
||||||
|
|
||||||
ASSERT_THROW(enc.Update(out2.begin(), out2.end(), data2.begin(), data2.end()),
|
ASSERT_THROW_EX(enc.Update(out2.begin(), out2.end(), data2.begin(), data2.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Encryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -421,8 +434,12 @@ TEST(EcbModeTests, EncryptInsufficientBufferTest)
|
|||||||
|
|
||||||
uint64_t written = enc.Update(out.begin(), out.end(), data.begin(), data.end());
|
uint64_t written = enc.Update(out.begin(), out.end(), data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_THROW(written += enc.Finish(out.begin() + written, out.end()),
|
ASSERT_THROW_EX(written += enc.Finish(out.begin() + written, out.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Encryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -433,8 +450,12 @@ TEST(EcbModeTests, EncryptInsufficientBufferTest)
|
|||||||
|
|
||||||
uint64_t written = enc.Update(out.begin(), out.end(), data.begin(), data.end());
|
uint64_t written = enc.Update(out.begin(), out.end(), data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_THROW(written += enc.Finish(out.begin() + written, out.end()),
|
ASSERT_THROW_EX(written += enc.Finish(out.begin() + written, out.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Encryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,8 +847,12 @@ TEST(EcbModeTests, DecryptInsufficientBufferTest)
|
|||||||
|
|
||||||
EcbMode<Des::DesCrypt, PadderPkcs7>::Decryptor dec(desKey);
|
EcbMode<Des::DesCrypt, PadderPkcs7>::Decryptor dec(desKey);
|
||||||
|
|
||||||
ASSERT_THROW(dec.Update(out.begin(), out.end(), data.begin(), data.end()),
|
ASSERT_THROW_EX(dec.Update(out.begin(), out.end(), data.begin(), data.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -838,8 +863,12 @@ TEST(EcbModeTests, DecryptInsufficientBufferTest)
|
|||||||
|
|
||||||
EcbMode<Des::DesCrypt, PadderPkcs7>::Decryptor dec(desKey);
|
EcbMode<Des::DesCrypt, PadderPkcs7>::Decryptor dec(desKey);
|
||||||
|
|
||||||
ASSERT_THROW(dec.Update(out.begin(), out.end(), data.begin(), data.end()),
|
ASSERT_THROW_EX(dec.Update(out.begin(), out.end(), data.begin(), data.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -855,8 +884,12 @@ TEST(EcbModeTests, DecryptInsufficientBufferTest)
|
|||||||
|
|
||||||
dec.Update(out1.begin(), out1.end(), data1.begin(), data1.end());
|
dec.Update(out1.begin(), out1.end(), data1.begin(), data1.end());
|
||||||
|
|
||||||
ASSERT_THROW(dec.Update(out2.begin(), out2.end(), data2.begin(), data2.end()),
|
ASSERT_THROW_EX(dec.Update(out2.begin(), out2.end(), data2.begin(), data2.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -868,8 +901,12 @@ TEST(EcbModeTests, DecryptInsufficientBufferTest)
|
|||||||
|
|
||||||
uint64_t written = dec.Update(out.begin(), out.end(), data.begin(), data.end());
|
uint64_t written = dec.Update(out.begin(), out.end(), data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_THROW(written += dec.Finish(out.begin() + written, out.end()),
|
ASSERT_THROW_EX(written += dec.Finish(out.begin() + written, out.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -882,8 +919,12 @@ TEST(EcbModeTests, DecryptInsufficientBufferTest)
|
|||||||
|
|
||||||
uint64_t written = dec.Update(out.begin(), out.end(), data.begin(), data.end());
|
uint64_t written = dec.Update(out.begin(), out.end(), data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_THROW(written += dec.Finish(out.begin() + written, out.end()),
|
ASSERT_THROW_EX(written += dec.Finish(out.begin() + written, out.end()),
|
||||||
Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: insufficient output buffer size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -915,7 +956,13 @@ TEST(EcbModeTests, DecryptNotRoundSizeTest)
|
|||||||
std::vector<uint8_t> data = { 0x64, 0x32, 0x13, 0xe7, 0x31, 0x06, 0xc6 };
|
std::vector<uint8_t> data = { 0x64, 0x32, 0x13, 0xe7, 0x31, 0x06, 0xc6 };
|
||||||
std::vector<uint8_t> key = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2, 0x38 };
|
std::vector<uint8_t> key = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2, 0x38 };
|
||||||
|
|
||||||
ASSERT_THROW(ecbDec(data, key), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(ecbDec(data, key), Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: ciphertext size "
|
||||||
|
"is not a multiple of the algorithm's "
|
||||||
|
"block size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -923,7 +970,13 @@ TEST(EcbModeTests, DecryptNotRoundSizeTest)
|
|||||||
0xdc, 0x0d, 0x9f, 0x87 };
|
0xdc, 0x0d, 0x9f, 0x87 };
|
||||||
std::vector<uint8_t> key = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2, 0x38 };
|
std::vector<uint8_t> key = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2, 0x38 };
|
||||||
|
|
||||||
ASSERT_THROW(ecbDec(data, key), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(ecbDec(data, key), Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: ciphertext size "
|
||||||
|
"is not a multiple of the algorithm's "
|
||||||
|
"block size",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -955,7 +1008,11 @@ TEST(EcbModeTests, DecryptInvalidPaddingTest)
|
|||||||
std::vector<uint8_t> data = { 0x60, 0xa7, 0x4b, 0x8c, 0x68, 0x03, 0x70, 0x0c };
|
std::vector<uint8_t> data = { 0x60, 0xa7, 0x4b, 0x8c, 0x68, 0x03, 0x70, 0x0c };
|
||||||
std::vector<uint8_t> key = { 0xaa, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf1, 0x12 };
|
std::vector<uint8_t> key = { 0xaa, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf1, 0x12 };
|
||||||
|
|
||||||
ASSERT_THROW(ecbDec(data, key), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(ecbDec(data, key), Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: invalid ciphertext",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -963,6 +1020,10 @@ TEST(EcbModeTests, DecryptInvalidPaddingTest)
|
|||||||
0xbe, 0xd2, 0x51, 0x7e, 0x4f, 0x39, 0xfe, 0xa2 };
|
0xbe, 0xd2, 0x51, 0x7e, 0x4f, 0x39, 0xfe, 0xa2 };
|
||||||
std::vector<uint8_t> key = { 0xaa, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf1, 0x12 };
|
std::vector<uint8_t> key = { 0xaa, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf1, 0x12 };
|
||||||
|
|
||||||
ASSERT_THROW(ecbDec(data, key), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(ecbDec(data, key), Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("EcbMode<>::Decryptor: invalid ciphertext",
|
||||||
|
ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "TestHelpers/AssertThrowEx.hpp"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -108,7 +109,16 @@ TEST(HmacTests, UninitializedHmacTest)
|
|||||||
{
|
{
|
||||||
Hmac<Md5Hasher> hmac;
|
Hmac<Md5Hasher> hmac;
|
||||||
|
|
||||||
ASSERT_THROW(hmac.Update(in.begin(), in.end()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(hmac.Update(in.begin(), in.end()),
|
||||||
ASSERT_THROW(hmac.Finish(), Chaos::Service::ChaosException);
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Hmac: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_THROW_EX(hmac.Finish(),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("Hmac: not initialized", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include "TestHelpers/AssertThrowEx.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -57,19 +58,31 @@ TEST(PadPkcs7Tests, PadInvalidRangeTest)
|
|||||||
{
|
{
|
||||||
std::array<uint8_t, 256> out = {};
|
std::array<uint8_t, 256> out = {};
|
||||||
|
|
||||||
ASSERT_THROW(PadderPkcs7::Pad(out.begin(), out.end()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(PadderPkcs7::Pad(out.begin(), out.end()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("PadderPkcs7::Pad(): invalid range", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::array<uint8_t, 500> out = {};
|
std::array<uint8_t, 500> out = {};
|
||||||
|
|
||||||
ASSERT_THROW(PadderPkcs7::Pad(out.begin(), out.end()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(PadderPkcs7::Pad(out.begin(), out.end()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("PadderPkcs7::Pad(): invalid range", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::array<uint8_t, 50> out = {};
|
std::array<uint8_t, 50> out = {};
|
||||||
|
|
||||||
ASSERT_THROW(PadderPkcs7::Pad(out.end(), out.begin()), Chaos::Service::ChaosException);
|
ASSERT_THROW_EX(PadderPkcs7::Pad(out.end(), out.begin()),
|
||||||
|
Chaos::Service::ChaosException,
|
||||||
|
{
|
||||||
|
ASSERT_EQ("PadderPkcs7::Pad(): invalid range", ex.GetMessage());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef CHAOSTESTS_TESTHELPERS_ASSERTTHROWEX_HPP
|
||||||
|
#define CHAOSTESTS_TESTHELPERS_ASSERTTHROWEX_HPP
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#define ASSERT_THROW_EX(statement, expected_exception_type, assertions) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
bool ASSERT_THROW_EX_expectedExceptionThrown = false; \
|
||||||
|
\
|
||||||
|
try \
|
||||||
|
{ \
|
||||||
|
statement; \
|
||||||
|
} \
|
||||||
|
catch (const expected_exception_type & ex) \
|
||||||
|
{ \
|
||||||
|
ASSERT_THROW_EX_expectedExceptionThrown = true; \
|
||||||
|
assertions; \
|
||||||
|
} \
|
||||||
|
catch (...) \
|
||||||
|
{ \
|
||||||
|
FAIL() << "Expected: " << #statement << " throws an exception of type " \
|
||||||
|
<< #expected_exception_type << ".\n Actual: it throws a different type."; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if (!ASSERT_THROW_EX_expectedExceptionThrown) \
|
||||||
|
{ \
|
||||||
|
FAIL() << "Expected: " << #statement << " throws an exception of type " \
|
||||||
|
<< #expected_exception_type << ".\n Actual: it throws nothing."; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (false)
|
||||||
|
|
||||||
|
#endif // CHAOSTESTS_TESTHELPERS_ASSERTTHROWEX_HPP
|
||||||
Reference in New Issue
Block a user