lokinet/test/routing/test_llarp_routing_obtainexitmessage.cpp

47 lines
986 B
C++
Raw Normal View History

2019-06-15 14:55:14 +00:00
#include <exit/exit_messages.hpp>
#include <crypto/crypto.hpp>
#include <crypto/crypto_libsodium.hpp>
2019-05-28 19:45:09 +00:00
#include <llarp_test.hpp>
#include <gtest/gtest.h>
2019-05-28 19:45:09 +00:00
#include <gmock/gmock.h>
2019-05-28 19:45:09 +00:00
using namespace ::testing;
using namespace ::llarp;
2019-05-28 19:45:09 +00:00
using ObtainExitMessage = routing::ObtainExitMessage;
class ObtainExitTest : public test::LlarpTest<>
{
public:
2019-05-28 19:45:09 +00:00
SecretKey alice;
2019-05-28 19:45:09 +00:00
ObtainExitTest()
{
2019-05-28 19:45:09 +00:00
// m_crypto.identity_keygen(alice);
}
};
2019-05-28 19:45:09 +00:00
void
fill(Signature& s)
{
s.Fill(0xFF);
}
TEST_F(ObtainExitTest, TestSignVerify)
{
2019-05-28 19:45:09 +00:00
EXPECT_CALL(m_crypto, sign(_, alice, _))
.WillOnce(DoAll(WithArg< 0 >(Invoke(&fill)), Return(true)));
EXPECT_CALL(m_crypto, verify(_, _, _)).WillOnce(Return(true));
ObtainExitMessage msg;
msg.Z.Zero();
2019-05-28 19:45:09 +00:00
msg.S = randint();
msg.T = randint();
EXPECT_TRUE(msg.Sign(alice));
EXPECT_TRUE(msg.Verify());
2019-05-28 19:45:09 +00:00
EXPECT_TRUE(msg.I == PubKey(seckey_topublic(alice)));
EXPECT_FALSE(msg.version != LLARP_PROTO_VERSION);
EXPECT_FALSE(msg.Z.IsZero());
2019-04-25 23:21:19 +00:00
}