2018-12-12 18:37:03 +00:00
|
|
|
#include <service/address.hpp>
|
|
|
|
|
2021-03-01 21:07:32 +00:00
|
|
|
#include <catch2/catch.hpp>
|
2019-01-26 15:40:58 +00:00
|
|
|
|
2021-03-01 21:07:32 +00:00
|
|
|
TEST_CASE("Address", "[Address]")
|
2018-12-12 18:37:03 +00:00
|
|
|
{
|
2021-03-01 21:07:32 +00:00
|
|
|
const std::string snode = "8zfiwpgonsu5zpddpxwdurxyb19x6r96xy4qbikff99jwsziws9y.snode";
|
|
|
|
const std::string loki = "7okic5x5do3uh3usttnqz9ek3uuoemdrwzto1hciwim9f947or6y.loki";
|
2019-04-26 12:11:34 +00:00
|
|
|
const std::string sub = "lokinet.test";
|
2021-03-01 21:07:32 +00:00
|
|
|
const std::string invalid = "7okic5x5do3uh3usttnqz9ek3uuoemdrwzto1hciwim9f947or6y.net";
|
2019-04-26 12:11:34 +00:00
|
|
|
llarp::service::Address addr;
|
|
|
|
|
2021-03-01 21:07:32 +00:00
|
|
|
SECTION("Parse bad TLD")
|
|
|
|
{
|
|
|
|
REQUIRE_FALSE(addr.FromString(snode, ".net"));
|
|
|
|
REQUIRE_FALSE(addr.FromString(invalid, ".net"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Parse bad TLD appened on end")
|
|
|
|
{
|
|
|
|
const std::string bad = loki + ".net";
|
|
|
|
REQUIRE_FALSE(addr.FromString(bad, ".net"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Parse bad TLD appened on end with subdomain")
|
|
|
|
{
|
|
|
|
const std::string bad = sub + "." + loki + ".net";
|
|
|
|
REQUIRE_FALSE(addr.FromString(bad, ".net"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Parse SNode not Loki")
|
|
|
|
{
|
|
|
|
REQUIRE(addr.FromString(snode, ".snode"));
|
|
|
|
REQUIRE_FALSE(addr.FromString(snode, ".loki"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Parse Loki not SNode")
|
|
|
|
{
|
|
|
|
REQUIRE_FALSE(addr.FromString(loki, ".snode"));
|
|
|
|
REQUIRE(addr.FromString(loki, ".loki"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Parse Loki with subdomain")
|
|
|
|
{
|
|
|
|
const std::string addr_str = sub + "." + loki;
|
|
|
|
REQUIRE(addr.FromString(addr_str, ".loki"));
|
|
|
|
REQUIRE(addr.subdomain == sub);
|
|
|
|
REQUIRE(addr.ToString() == addr_str);
|
|
|
|
};
|
|
|
|
|
|
|
|
SECTION("Parse SNode with subdomain")
|
|
|
|
{
|
|
|
|
const std::string addr_str = sub + "." + snode;
|
|
|
|
REQUIRE(addr.FromString(addr_str, ".snode"));
|
|
|
|
REQUIRE(addr.subdomain == sub);
|
|
|
|
REQUIRE(addr.ToString(".snode") == addr_str);
|
|
|
|
}
|
2019-04-26 12:11:34 +00:00
|
|
|
}
|