diff --git a/system-tests/tests/regression/cre/http/config/config.go b/system-tests/tests/regression/cre/http/config/config.go index e66edb6f5e7..adfed780151 100644 --- a/system-tests/tests/regression/cre/http/config/config.go +++ b/system-tests/tests/regression/cre/http/config/config.go @@ -5,3 +5,9 @@ type Config struct { URL string `json:"url"` TestCase string `json:"testCase"` // Identifies which test case to run } + +const ( + TestCaseInvalidKeyType = "invalid-key-type" + TestCaseInvalidPublicKey = "invalid-public-key" + TestCaseNonExistingPublicKey = "non-existing-public-key" +) diff --git a/system-tests/tests/regression/cre/http/main.go b/system-tests/tests/regression/cre/http/main.go index 8c53473b19c..9d757206322 100644 --- a/system-tests/tests/regression/cre/http/main.go +++ b/system-tests/tests/regression/cre/http/main.go @@ -30,7 +30,7 @@ func RunHTTPRegressionWorkflow(wfCfg config.Config, _ *slog.Logger, _ cre.Secret var triggerConfig *http.Config switch wfCfg.TestCase { - case "invalid-key-type": + case config.TestCaseInvalidKeyType: // Use an invalid key type (non-existent enum value) triggerConfig = &http.Config{ AuthorizedKeys: []*http.AuthorizedKey{ @@ -40,23 +40,23 @@ func RunHTTPRegressionWorkflow(wfCfg config.Config, _ *slog.Logger, _ cre.Secret }, }, } - case "invalid-public-key": + case config.TestCaseInvalidPublicKey: // Use an invalid public key format triggerConfig = &http.Config{ AuthorizedKeys: []*http.AuthorizedKey{ { Type: http.KeyType_KEY_TYPE_ECDSA_EVM, - PublicKey: "invalid-public-key-format", + PublicKey: wfCfg.AuthorizedKey, }, }, } - case "non-existing-public-key": + case config.TestCaseNonExistingPublicKey: // Use a non-existing but properly formatted public key triggerConfig = &http.Config{ AuthorizedKeys: []*http.AuthorizedKey{ { Type: http.KeyType_KEY_TYPE_ECDSA_EVM, - PublicKey: "0x0000000000000000000000000000000000000000", + PublicKey: wfCfg.AuthorizedKey, }, }, } diff --git a/system-tests/tests/regression/cre/v2_http_trigger_regression_test.go b/system-tests/tests/regression/cre/v2_http_trigger_regression_test.go index 5611e5c28b5..acdbdb05aff 100644 --- a/system-tests/tests/regression/cre/v2_http_trigger_regression_test.go +++ b/system-tests/tests/regression/cre/v2_http_trigger_regression_test.go @@ -38,23 +38,27 @@ import ( type httpNegativeTest struct { name string testCase string + keyToUse string expectedError string } var httpNegativeTests = []httpNegativeTest{ { name: "invalid AuthorizedKey.Type", - testCase: "invalid-key-type", + testCase: http_config.TestCaseInvalidKeyType, + keyToUse: mustDKGKey(), expectedError: "unsupported key type", }, { name: "invalid AuthorizedKey.PublicKey format", - testCase: "invalid-public-key", + testCase: http_config.TestCaseInvalidPublicKey, + keyToUse: "invalid-public-key-format", expectedError: "invalid public key", }, { name: "non-existing AuthorizedKey.PublicKey", - testCase: "non-existing-public-key", + testCase: http_config.TestCaseNonExistingPublicKey, + keyToUse: "0x0000000000000000000000000000000000000000", expectedError: "Auth failure", }, } @@ -113,21 +117,8 @@ func HTTPTriggerFailsTest(t *testing.T, testEnv *ttypes.TestEnvironment, httpNeg t_helpers.IgnoreUserLogs(t.Context(), userLogsCh) testLogger.Info().Msg("Creating HTTP negative test workflow configuration...") - // Determine the authorized key to use based on test case - var authorizedKeyToUse string - switch httpNegativeTest.testCase { - case "invalid-public-key": - authorizedKeyToUse = "0x000000000000000000000000000000000000000" - case "non-existing-public-key": - authorizedKeyToUse = "0x0000000000000000000000000000000000000000" - default: - dkgKey, dErr := dkgrecipientkey.New() - require.NoError(t, dErr, "failed to generate new DKG recipient key") - authorizedKeyToUse = dkgKey.PublicKeyString() - } - workflowConfig := http_config.Config{ - AuthorizedKey: authorizedKeyToUse, + AuthorizedKey: httpNegativeTest.keyToUse, URL: fakeServer.BaseURLHost + "/orders-" + testID, TestCase: httpNegativeTest.testCase, } @@ -137,7 +128,7 @@ func HTTPTriggerFailsTest(t *testing.T, testEnv *ttypes.TestEnvironment, httpNeg // For invalid key type and invalid public key format, we expect the workflow deployment/trigger setup to fail // For non-existing public key, we expect the trigger execution to fail with unauthorized error at gateway level - if httpNegativeTest.testCase == "non-existing-public-key" { + if httpNegativeTest.testCase == http_config.TestCaseNonExistingPublicKey { // Try to execute the trigger with a valid signing key but unauthorized public key testLogger.Info().Msg("Attempting to execute HTTP trigger with unauthorized key...") authFailureDetected := executeHTTPTriggerRequestExpectingFailure(t, testEnv, workflowName, signingKey) @@ -314,3 +305,11 @@ func startTestOrderServer(t *testing.T, port int, testID string) (*fake.Output, framework.L.Info().Msgf("Test order server started on port %d at: %s with endpoint %s", port, fakeOutput.BaseURLHost, endpoint) return fakeOutput, nil } + +func mustDKGKey() string { + dkgKey, dErr := dkgrecipientkey.New() + if dErr != nil { + panic(dErr) + } + return dkgKey.PublicKeyString() +}