mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-26 23:24:03 +02:00
NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes
This patch updates the PxeBcDhcp6GoogleTest due to the changes in the underlying code. The changes are as follows: - Random now comes from the RngLib Protocol - The TCP ISN is now generated by the hash function Cc: Saloni Kasbekar <saloni.kasbekar@intel.com> Cc: Zachary Clark-williams <zachary.clark-williams@intel.com> Signed-off-by: Doug Flick [MSFT] <doug.edk2@gmail.com> Reviewed-by: Saloni Kasbekar <saloni.kasbekar@intel.com>
This commit is contained in:
parent
dff3d3811f
commit
207b6d68a0
@ -30,6 +30,7 @@
|
|||||||
NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf {
|
NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf {
|
||||||
<LibraryClasses>
|
<LibraryClasses>
|
||||||
UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
|
UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
|
||||||
|
UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
|
||||||
}
|
}
|
||||||
|
|
||||||
# Despite these library classes being listed in [LibraryClasses] below, they are not needed for the host-based unit tests.
|
# Despite these library classes being listed in [LibraryClasses] below, they are not needed for the host-based unit tests.
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <Library/GoogleTestLib.h>
|
#include <Library/GoogleTestLib.h>
|
||||||
#include <GoogleTest/Library/MockUefiLib.h>
|
#include <GoogleTest/Library/MockUefiLib.h>
|
||||||
#include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h>
|
#include <GoogleTest/Library/MockUefiRuntimeServicesTableLib.h>
|
||||||
|
#include <GoogleTest/Library/MockUefiBootServicesTableLib.h>
|
||||||
|
#include <GoogleTest/Protocol/MockRng.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <Uefi.h>
|
#include <Uefi.h>
|
||||||
@ -165,7 +167,7 @@ protected:
|
|||||||
// Note:
|
// Note:
|
||||||
// Testing PxeBcHandleDhcp6Offer() is difficult because it depends on a
|
// Testing PxeBcHandleDhcp6Offer() is difficult because it depends on a
|
||||||
// properly setup Private structure. Attempting to properly test this function
|
// properly setup Private structure. Attempting to properly test this function
|
||||||
// without a signficant refactor is a fools errand. Instead, we will test
|
// without a significant refactor is a fools errand. Instead, we will test
|
||||||
// that we can prevent an overflow in the function.
|
// that we can prevent an overflow in the function.
|
||||||
TEST_F (PxeBcHandleDhcp6OfferTest, BasicUsageTest) {
|
TEST_F (PxeBcHandleDhcp6OfferTest, BasicUsageTest) {
|
||||||
PXEBC_DHCP6_PACKET_CACHE *Cache6 = NULL;
|
PXEBC_DHCP6_PACKET_CACHE *Cache6 = NULL;
|
||||||
@ -238,6 +240,7 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, BasicUsageTest) {
|
|||||||
FreePool (Option);
|
FreePool (Option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Description
|
// Test Description
|
||||||
// Test that we can prevent an overflow in the function
|
// Test that we can prevent an overflow in the function
|
||||||
TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptOverflowTest) {
|
TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptOverflowTest) {
|
||||||
@ -470,10 +473,15 @@ TEST_F (PxeBcRequestBootServiceTest, AttemptRequestOverFlowExpectFailure) {
|
|||||||
class PxeBcDhcp6DiscoverTest : public ::testing::Test {
|
class PxeBcDhcp6DiscoverTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
PXEBC_PRIVATE_DATA Private = { 0 };
|
PXEBC_PRIVATE_DATA Private = { 0 };
|
||||||
|
// create a mock md5 hash
|
||||||
|
UINT8 Md5Hash[16] = { 0 };
|
||||||
|
|
||||||
EFI_UDP6_PROTOCOL Udp6Read;
|
EFI_UDP6_PROTOCOL Udp6Read;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MockUefiRuntimeServicesTableLib RtServicesMock;
|
MockUefiRuntimeServicesTableLib RtServicesMock;
|
||||||
|
MockUefiBootServicesTableLib BsMock;
|
||||||
|
MockRng RngMock;
|
||||||
|
|
||||||
// Add any setup code if needed
|
// Add any setup code if needed
|
||||||
virtual void
|
virtual void
|
||||||
@ -527,8 +535,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicOverflowTest) {
|
|||||||
|
|
||||||
Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 *)Private.Dhcp6Request);
|
Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 *)Private.Dhcp6Request);
|
||||||
|
|
||||||
EXPECT_CALL (RtServicesMock, gRT_GetTime)
|
EXPECT_CALL (BsMock, gBS_LocateProtocol)
|
||||||
.WillOnce (::testing::Return (0));
|
.WillOnce (
|
||||||
|
::testing::DoAll (
|
||||||
|
::testing::SetArgPointee<2> (::testing::ByRef (gRngProtocol)),
|
||||||
|
::testing::Return (EFI_SUCCESS)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
EXPECT_CALL (RngMock, GetRng)
|
||||||
|
.WillOnce (
|
||||||
|
::testing::DoAll (
|
||||||
|
::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash[0])),
|
||||||
|
::testing::Return (EFI_SUCCESS)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
ASSERT_EQ (
|
ASSERT_EQ (
|
||||||
PxeBcDhcp6Discover (
|
PxeBcDhcp6Discover (
|
||||||
@ -558,8 +579,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicUsageTest) {
|
|||||||
|
|
||||||
Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 *)Private.Dhcp6Request);
|
Private.Dhcp6Request->Length = (UINT16)(Cursor - (UINT8 *)Private.Dhcp6Request);
|
||||||
|
|
||||||
EXPECT_CALL (RtServicesMock, gRT_GetTime)
|
EXPECT_CALL (BsMock, gBS_LocateProtocol)
|
||||||
.WillOnce (::testing::Return (0));
|
.WillOnce (
|
||||||
|
::testing::DoAll (
|
||||||
|
::testing::SetArgPointee<2> (::testing::ByRef (gRngProtocol)),
|
||||||
|
::testing::Return (EFI_SUCCESS)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
EXPECT_CALL (RngMock, GetRng)
|
||||||
|
.WillOnce (
|
||||||
|
::testing::DoAll (
|
||||||
|
::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash[0])),
|
||||||
|
::testing::Return (EFI_SUCCESS)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
ASSERT_EQ (
|
ASSERT_EQ (
|
||||||
PxeBcDhcp6Discover (
|
PxeBcDhcp6Discover (
|
||||||
@ -572,3 +606,61 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicUsageTest) {
|
|||||||
EFI_SUCCESS
|
EFI_SUCCESS
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F (PxeBcDhcp6DiscoverTest, MultipleRequestsAttemptOverflow) {
|
||||||
|
EFI_IPv6_ADDRESS DestIp = { 0 };
|
||||||
|
EFI_DHCP6_PACKET_OPTION RequestOpt = { 0 }; // the data section doesn't really matter
|
||||||
|
|
||||||
|
RequestOpt.OpCode = HTONS (0x1337);
|
||||||
|
RequestOpt.OpLen = HTONS (REQUEST_OPTION_LENGTH); // this length would overflow without a check
|
||||||
|
UINT8 RequestOptBuffer[REQUEST_OPTION_LENGTH] = { 0 };
|
||||||
|
|
||||||
|
// make sure we have enough space for 10 of these options
|
||||||
|
ASSERT_TRUE (REQUEST_OPTION_LENGTH * 10 <= PACKET_SIZE);
|
||||||
|
|
||||||
|
UINT8 Index = 0;
|
||||||
|
EFI_DHCP6_PACKET *Packet = (EFI_DHCP6_PACKET *)&Private.Dhcp6Request[Index];
|
||||||
|
UINT8 *Cursor = (UINT8 *)(Packet->Dhcp6.Option);
|
||||||
|
|
||||||
|
// let's add 10 of these options - this should overflow
|
||||||
|
for (UINT8 i = 0; i < 10; i++) {
|
||||||
|
CopyMem (Cursor, &RequestOpt, sizeof (RequestOpt));
|
||||||
|
Cursor += sizeof (RequestOpt) - 1;
|
||||||
|
CopyMem (Cursor, RequestOptBuffer, REQUEST_OPTION_LENGTH);
|
||||||
|
Cursor += REQUEST_OPTION_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the packet length
|
||||||
|
Packet->Length = (UINT16)(Cursor - (UINT8 *)Packet);
|
||||||
|
Packet->Size = PACKET_SIZE;
|
||||||
|
|
||||||
|
// Make sure we're larger than the buffer we're trying to write into
|
||||||
|
ASSERT_TRUE (Packet->Length > sizeof (EFI_PXE_BASE_CODE_DHCPV6_PACKET));
|
||||||
|
|
||||||
|
EXPECT_CALL (BsMock, gBS_LocateProtocol)
|
||||||
|
.WillOnce (
|
||||||
|
::testing::DoAll (
|
||||||
|
::testing::SetArgPointee<2> (::testing::ByRef (gRngProtocol)),
|
||||||
|
::testing::Return (EFI_SUCCESS)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
EXPECT_CALL (RngMock, GetRng)
|
||||||
|
.WillOnce (
|
||||||
|
::testing::DoAll (
|
||||||
|
::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash[0])),
|
||||||
|
::testing::Return (EFI_SUCCESS)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
ASSERT_EQ (
|
||||||
|
PxeBcDhcp6Discover (
|
||||||
|
&(PxeBcDhcp6DiscoverTest::Private),
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
FALSE,
|
||||||
|
(EFI_IP_ADDRESS *)&DestIp
|
||||||
|
),
|
||||||
|
EFI_OUT_OF_RESOURCES
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -14,7 +14,7 @@ VERSION_STRING = 1.0
|
|||||||
#
|
#
|
||||||
# The following information is for reference only and not required by the build tools.
|
# The following information is for reference only and not required by the build tools.
|
||||||
#
|
#
|
||||||
# VALID_ARCHITECTURES = IA32 X64
|
# VALID_ARCHITECTURES = IA32 X64 AARCH64
|
||||||
#
|
#
|
||||||
|
|
||||||
[Sources]
|
[Sources]
|
||||||
@ -23,6 +23,7 @@ VERSION_STRING = 1.0
|
|||||||
PxeBcDhcp6GoogleTest.h
|
PxeBcDhcp6GoogleTest.h
|
||||||
../PxeBcDhcp6.c
|
../PxeBcDhcp6.c
|
||||||
../PxeBcSupport.c
|
../PxeBcSupport.c
|
||||||
|
../../../MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
Loading…
x
Reference in New Issue
Block a user