You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.2 KiB
92 lines
3.2 KiB
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Digital Voice Modem - Test Suite
|
|
* GPLv2 Open Source. Use is subject to license terms.
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
*
|
|
* Copyright (C) 2026 Bryan Biedenkapp, N2PLL
|
|
*
|
|
*/
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "fne/FNETestHooks.h"
|
|
#include "fne/HostFNE.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Class Declaration
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Test harness for FNE network tests.
|
|
*/
|
|
class FNEHarness {
|
|
public:
|
|
/**
|
|
* @brief Initializes a new instance of the FNEHarness class.
|
|
*/
|
|
FNEHarness() :
|
|
configFile("fne-test.yml"),
|
|
host(configFile),
|
|
traffic(&host, "127.0.0.1", 62031U, 999999U, "test-password", "test-fne",
|
|
false, false, false, false, true, true, true, true, true,
|
|
0U, false, true, true, 5U, 10U, 2U),
|
|
metadata(&host, &traffic, "127.0.0.1", 62032U, 2U)
|
|
{
|
|
/* stub */
|
|
}
|
|
/**
|
|
* @brief Finalizes a instance of the FNEHarness class.
|
|
*/
|
|
~FNEHarness()
|
|
{
|
|
FNETestHooks::clearPeers(traffic);
|
|
}
|
|
|
|
std::string configFile;
|
|
HostFNE host;
|
|
network::TrafficNetwork traffic;
|
|
network::MetadataNetwork metadata;
|
|
};
|
|
|
|
TEST_CASE("FNE test hooks expose peer connection state", "[fne][hooks]")
|
|
{
|
|
FNEHarness harness;
|
|
FNETestHooks::addPeer(harness.traffic, 1001U, network::NET_STAT_WAITING_AUTHORISATION);
|
|
|
|
REQUIRE(FNETestHooks::hasPeer(harness.traffic, 1001U));
|
|
REQUIRE(FNETestHooks::peerCount(harness.traffic) == 1U);
|
|
REQUIRE(FNETestHooks::peerState(harness.traffic, 1001U) == network::NET_STAT_WAITING_AUTHORISATION);
|
|
}
|
|
|
|
TEST_CASE("FNE traffic dispatcher rejects truncated pre-authentication packets", "[fne][hooks][security]")
|
|
{
|
|
FNEHarness harness;
|
|
FNETestHooks::addPeer(harness.traffic, 1001U, network::NET_STAT_WAITING_AUTHORISATION);
|
|
|
|
REQUIRE_NOTHROW(FNETestHooks::dispatchTraffic(harness.traffic, network::NET_FUNC::RPTK,
|
|
network::NET_SUBFUNC::NOP, 1001U, std::vector<uint8_t>(8U)));
|
|
REQUIRE(FNETestHooks::peerState(harness.traffic, 1001U) == network::NET_STAT_WAITING_AUTHORISATION);
|
|
|
|
REQUIRE_NOTHROW(FNETestHooks::dispatchTraffic(harness.traffic, network::NET_FUNC::RPTC,
|
|
network::NET_SUBFUNC::NOP, 1001U, std::vector<uint8_t>(8U)));
|
|
REQUIRE(FNETestHooks::peerState(harness.traffic, 1001U) == network::NET_STAT_WAITING_AUTHORISATION);
|
|
}
|
|
|
|
TEST_CASE("FNE metadata dispatcher rejects truncated log transfers", "[fne][hooks][security]")
|
|
{
|
|
FNEHarness harness;
|
|
FNETestHooks::addPeer(harness.traffic, 1001U, network::NET_STAT_RUNNING, true);
|
|
|
|
REQUIRE_NOTHROW(FNETestHooks::dispatchMetadata(harness.traffic, harness.metadata,
|
|
network::NET_FUNC::TRANSFER, network::NET_SUBFUNC::TRANSFER_SUBFUNC_ACTIVITY,
|
|
1001U, std::vector<uint8_t>(11U)));
|
|
REQUIRE_NOTHROW(FNETestHooks::dispatchMetadata(harness.traffic, harness.metadata,
|
|
network::NET_FUNC::TRANSFER, network::NET_SUBFUNC::TRANSFER_SUBFUNC_DIAG,
|
|
1001U, std::vector<uint8_t>(10U)));
|
|
REQUIRE(FNETestHooks::peerState(harness.traffic, 1001U) == network::NET_STAT_RUNNING);
|
|
}
|