Add Protocol::StunReplay and Tests

This commit is contained in:
2026-08-05 22:31:54 +03:00
parent dfe1edf706
commit 49ac7b9dfc
3 changed files with 53 additions and 1 deletions
+18 -1
View File
@@ -3,7 +3,24 @@
#include <protocol/protocol.hxx>
#include <sodium.h>
TEST_CASE("SignedMessage", "[protocol]") {
TEST_CASE("Protocol::StunReplay", "[protocol]") {
SECTION("str to ipv4") {
auto replay = Protocol::StunReplay("1.1.255.255", 1337);
REQUIRE(replay.addr == 16908287);
}
SECTION("invalid ipv4 str (range)") {
REQUIRE_THROWS_AS(Protocol::StunReplay("1.1.255.256", 1337),
std::runtime_error);
REQUIRE_THROWS_AS(Protocol::StunReplay("0.1.255.255", 1337),
std::runtime_error);
}
SECTION("invalid ipv4 str (len)") {
REQUIRE_THROWS_AS(Protocol::StunReplay("1.1.1", 1337),
std::runtime_error);
}
}
TEST_CASE("Protocol::SignedMessage", "[protocol]") {
REQUIRE(sodium_init() >= 0);
unsigned char pub_key[crypto_sign_PUBLICKEYBYTES];