Skip to content

Commit

Permalink
Add GetParam tests for Configuration (microsoft#2802)
Browse files Browse the repository at this point in the history
* fix to appropriate parameter

* Fix comment on PR

* Fix comment

* move all transport parameters to quicdef.h

* Fix CI issue

* Add more SetParam tests for Configuration

* Fix CI issue

* Fix comment

* Fix comment on PR

* Fix comment

* move all transport parameters to quicdef.h

* Fix CI issue

* test

* add Set/GetParam tests for Configuration

* Resolve conflicts

* Fix comment
  • Loading branch information
ami-GS authored Jun 15, 2022
1 parent 1a21743 commit 43fd796
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 64 deletions.
4 changes: 2 additions & 2 deletions src/test/MsQuicTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void QuicTestValidateStream(bool Connect);
void QuicTestGlobalSetParam();
void QuicTestCommonSetParam();
void QuicTestRegistrationSetParam();
void QuicTestConfigurationSetParam();
void QuicTestConfigurationParam();
void QuicTestListenerParam();
void QuicTestConnectionSetParam();
void QuicTestTlsSetParam();
Expand Down Expand Up @@ -1040,7 +1040,7 @@ typedef struct {
#define IOCTL_QUIC_RUN_VALIDATE_REGISTRATION_SET_PARAM \
QUIC_CTL_CODE(92, METHOD_BUFFERED, FILE_WRITE_DATA)

#define IOCTL_QUIC_RUN_VALIDATE_CONFIGURATION_SET_PARAM \
#define IOCTL_QUIC_RUN_VALIDATE_CONFIGURATION_PARAM \
QUIC_CTL_CODE(93, METHOD_BUFFERED, FILE_WRITE_DATA)

#define IOCTL_QUIC_RUN_VALIDATE_LISTENER_PARAM \
Expand Down
8 changes: 4 additions & 4 deletions src/test/bin/quic_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ TEST(ParameterValidation, ValidateRegistrationSetParam) {
}
}

TEST(ParameterValidation, ValidateConfigurationSetParam) {
TestLogger Logger("QuicTestValidateConfigurationSetParam");
TEST(ParameterValidation, ValidateConfigurationParam) {
TestLogger Logger("QuicTestValidateConfigurationParam");
if (TestingKernelMode) {
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_VALIDATE_CONFIGURATION_SET_PARAM));
ASSERT_TRUE(DriverClient.Run(IOCTL_QUIC_RUN_VALIDATE_CONFIGURATION_PARAM));
} else {
QuicTestConfigurationSetParam();
QuicTestConfigurationParam();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/bin/winkernel/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,8 +1224,8 @@ QuicTestCtlEvtIoDeviceControl(
QuicTestCtlRun(QuicTestRegistrationSetParam());
break;

case IOCTL_QUIC_RUN_VALIDATE_CONFIGURATION_SET_PARAM:
QuicTestCtlRun(QuicTestConfigurationSetParam());
case IOCTL_QUIC_RUN_VALIDATE_CONFIGURATION_PARAM:
QuicTestCtlRun(QuicTestConfigurationParam());
break;

case IOCTL_QUIC_RUN_VALIDATE_LISTENER_PARAM:
Expand Down
189 changes: 133 additions & 56 deletions src/test/lib/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2359,41 +2359,70 @@ void QuicTestRegistrationSetParam()
}
}

void QuicTestConfigurationSetParam()
void QuicTestConfigurationParam()
{
MsQuicRegistration Registration;
TEST_TRUE(Registration.IsValid());
MsQuicAlpn Alpn("MsQuicTest");
//MsQuicConfiguration Configuration(Registration, Alpn);

//
// QUIC_PARAM_CONFIGURATION_SETTINGS
//
{
TestScopeLogger LogScope0("QUIC_PARAM_CONFIGURATION_SETTINGS");
//
// QuicSettingsSettingsToInternal fail
//
{
TestScopeLogger LogScope1("QuicSettingsSettingsToInternal fail");
MsQuicConfiguration Configuration(Registration, Alpn);
QUIC_SETTINGS Settings{0};
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_PARAMETER,
MsQuic->SetParam(
nullptr,
QUIC_PARAM_CONFIGURATION_SETTINGS,
sizeof(QUIC_SETTINGS)-8,
&Settings));
TestScopeLogger LogScope1("SetParam");
//
// QuicSettingsSettingsToInternal fail
//
{
TestScopeLogger LogScope2("QuicSettingsSettingsToInternal fail");
MsQuicConfiguration Configuration(Registration, Alpn);
QUIC_SETTINGS Settings{0};
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_PARAMETER,
MsQuic->SetParam(
nullptr,
QUIC_PARAM_CONFIGURATION_SETTINGS,
sizeof(QUIC_SETTINGS)-8,
&Settings));
}

//
// QuicSettingApply fail
//
{
TestScopeLogger LogScope2("QuicSettingApply fail");
MsQuicConfiguration Configuration(Registration, Alpn);
SettingApplyTests(Configuration.Handle, QUIC_PARAM_CONFIGURATION_SETTINGS);
}
}

//
// QuicSettingApply fail
// GetParam
//
{
TestScopeLogger LogScope1("QuicSettingApply fail");
TestScopeLogger LogScope1("GetParam");
MsQuicConfiguration Configuration(Registration, Alpn);
SettingApplyTests(Configuration.Handle, QUIC_PARAM_CONFIGURATION_SETTINGS);
uint32_t Length = 0;
TEST_QUIC_STATUS(
QUIC_STATUS_BUFFER_TOO_SMALL,
MsQuic->GetParam(
Configuration.Handle,
QUIC_PARAM_CONFIGURATION_SETTINGS,
&Length,
nullptr));
TEST_EQUAL(Length, sizeof(QUIC_SETTINGS));

QUIC_SETTINGS Settings{0};
TEST_QUIC_SUCCEEDED(
MsQuic->GetParam(
Configuration.Handle,
QUIC_PARAM_CONFIGURATION_SETTINGS,
&Length,
&Settings));
// TODO: how to compare with default?
// QuicSettingsSetDefault is not accessible from test
}
}

Expand All @@ -2402,46 +2431,64 @@ void QuicTestConfigurationSetParam()
//
{
TestScopeLogger LogScope0("QUIC_PARAM_CONFIGURATION_TICKET_KEYS");
//
// Set before MsQuic->ConfigurationLoadCredential which is Configuration->SecurityConfig == NULL
//
{
TestScopeLogger LogScope1("Set before MsQuic->ConfigurationLoadCredential which is Configuration->SecurityConfig == NULL");
MsQuicConfiguration Configuration(Registration, Alpn);
QUIC_TICKET_KEY_CONFIG Config{0};
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_STATE,
MsQuic->SetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_TICKET_KEYS,
sizeof(Config),
&Config));
TestScopeLogger LogScope1("SetParam");
//
// Set before MsQuic->ConfigurationLoadCredential which is Configuration->SecurityConfig == NULL
//
{
TestScopeLogger LogScope2("Set before MsQuic->ConfigurationLoadCredential which is Configuration->SecurityConfig == NULL");
MsQuicConfiguration Configuration(Registration, Alpn);
QUIC_TICKET_KEY_CONFIG Config{0};
TEST_QUIC_STATUS(
QUIC_STATUS_INVALID_STATE,
MsQuic->SetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_TICKET_KEYS,
sizeof(Config),
&Config));
}

//
// SetParam for client is not supported
//
{
TestScopeLogger LogScope2("SetParam for client is not supported");
MsQuicConfiguration Configuration(Registration, Alpn);
QUIC_CREDENTIAL_CONFIG CredConfig = {};
CredConfig.Flags = QUIC_CREDENTIAL_FLAG_CLIENT;
Configuration.LoadCredential(&CredConfig);
QUIC_TICKET_KEY_CONFIG Config = {};
TEST_QUIC_STATUS(
QUIC_STATUS_NOT_SUPPORTED,
MsQuic->SetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_TICKET_KEYS,
sizeof(Config),
&Config));
}

//
// Good with self-signed key
//
{
TestScopeLogger LogScope2("Good tests are covered by QuicTestValidateConfiguration");
}
}

//
// SetParam for client is not supported
// GetParam
//
{
TestScopeLogger LogScope1("SetParam for client is not supported");
TestScopeLogger LogScope1("GetParam is not allowed");
MsQuicConfiguration Configuration(Registration, Alpn);
QUIC_CREDENTIAL_CONFIG CredConfig = {};
CredConfig.Flags = QUIC_CREDENTIAL_FLAG_CLIENT;
Configuration.LoadCredential(&CredConfig);
QUIC_TICKET_KEY_CONFIG Config = {};
TEST_QUIC_STATUS(
QUIC_STATUS_NOT_SUPPORTED,
MsQuic->SetParam(
QUIC_STATUS_INVALID_PARAMETER,
MsQuic->GetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_TICKET_KEYS,
sizeof(Config),
&Config));
}

//
// Good with self-signed key
//
{
TestScopeLogger LogScope1("Good tests are covered by QuicTestValidateConfiguration");
nullptr,
nullptr));
}
}

Expand All @@ -2457,15 +2504,45 @@ void QuicTestConfigurationSetParam()
// QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED
//
{
TestScopeLogger LogScope("QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED");

TestScopeLogger LogScope0("QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED");
MsQuicConfiguration Configuration(Registration, Alpn);
BOOLEAN Flag = TRUE;
TEST_QUIC_SUCCEEDED(
MsQuic->SetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED,
sizeof(Flag),
&Flag));
BOOLEAN ExpectedFlag = TRUE;
//
// SetParam
//
{
TEST_QUIC_SUCCEEDED(
MsQuic->SetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED,
sizeof(ExpectedFlag),
&ExpectedFlag));
}

//
// GetParam
//
{
uint32_t Length = 0;
TEST_QUIC_STATUS(
QUIC_STATUS_BUFFER_TOO_SMALL,
MsQuic->GetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED,
&Length,
nullptr));
TEST_EQUAL(Length, sizeof(BOOLEAN));

BOOLEAN Flag = FALSE;
TEST_QUIC_SUCCEEDED(
MsQuic->GetParam(
Configuration,
QUIC_PARAM_CONFIGURATION_VERSION_NEG_ENABLED,
&Length,
&Flag));
TEST_EQUAL(Flag, ExpectedFlag);
}
}
#endif
}
Expand Down

0 comments on commit 43fd796

Please sign in to comment.