2018-12-28 15:04:05 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2019-01-13 14:00:50 +00:00
|
|
|
#include <crypto/crypto.hpp>
|
2019-01-26 15:40:58 +00:00
|
|
|
#include <crypto/crypto_libsodium.hpp>
|
2019-05-28 19:45:09 +00:00
|
|
|
#include <llarp_test.hpp>
|
2018-12-28 15:04:05 +00:00
|
|
|
#include <router_contact.hpp>
|
2020-05-15 12:38:04 +00:00
|
|
|
#include <net/net_int.hpp>
|
2018-12-28 15:04:05 +00:00
|
|
|
|
2019-05-28 19:45:09 +00:00
|
|
|
using namespace ::llarp;
|
|
|
|
using namespace ::testing;
|
|
|
|
|
2019-01-02 22:21:29 +00:00
|
|
|
static const byte_t DEF_VALUE[] = "unittest";
|
|
|
|
|
2019-05-28 19:45:09 +00:00
|
|
|
struct RCTest : public test::LlarpTest<>
|
2018-12-28 15:04:05 +00:00
|
|
|
{
|
2020-05-15 12:38:04 +00:00
|
|
|
using RC_t = RouterContact;
|
2019-05-28 19:45:09 +00:00
|
|
|
using SecKey_t = SecretKey;
|
2018-12-28 15:04:05 +00:00
|
|
|
|
2019-05-28 19:45:09 +00:00
|
|
|
RCTest() : oldval(NetID::DefaultValue())
|
2018-12-28 15:04:05 +00:00
|
|
|
{
|
2019-05-28 19:45:09 +00:00
|
|
|
NetID::DefaultValue() = NetID(DEF_VALUE);
|
2018-12-28 15:04:05 +00:00
|
|
|
}
|
|
|
|
|
2019-01-02 22:21:29 +00:00
|
|
|
~RCTest()
|
2018-12-28 15:04:05 +00:00
|
|
|
{
|
2019-05-28 19:45:09 +00:00
|
|
|
NetID::DefaultValue() = oldval;
|
2018-12-28 15:04:05 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 19:45:09 +00:00
|
|
|
const NetID oldval;
|
2018-12-28 15:04:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(RCTest, TestSignVerify)
|
|
|
|
{
|
2019-05-28 19:45:09 +00:00
|
|
|
NetID netid(DEF_VALUE);
|
2019-01-17 15:11:17 +00:00
|
|
|
RC_t rc;
|
2018-12-28 15:04:05 +00:00
|
|
|
SecKey_t encr;
|
|
|
|
SecKey_t sign;
|
2019-04-08 17:40:51 +00:00
|
|
|
|
2019-01-02 22:21:29 +00:00
|
|
|
rc.enckey = encr.toPublic();
|
2019-01-17 15:11:17 +00:00
|
|
|
rc.pubkey = sign.toPublic();
|
|
|
|
ASSERT_TRUE(rc.netID == netid);
|
2019-05-28 19:45:09 +00:00
|
|
|
ASSERT_TRUE(rc.netID == NetID::DefaultValue());
|
|
|
|
|
|
|
|
EXPECT_CALL(m_crypto, sign(_, sign, _)).WillOnce(Return(true));
|
|
|
|
EXPECT_CALL(m_crypto, verify(_, _, _)).WillOnce(Return(true));
|
|
|
|
|
2019-05-28 19:45:08 +00:00
|
|
|
ASSERT_TRUE(rc.Sign(sign));
|
2019-05-28 19:45:09 +00:00
|
|
|
ASSERT_TRUE(rc.Verify(time_now_ms()));
|
2018-12-28 15:04:05 +00:00
|
|
|
}
|