diff --git a/pkg/plugin/implementation/requestPreProcessor/cmd/plugin.go b/pkg/plugin/implementation/requestPreProcessor/cmd/plugin.go index e8280d9..4a05ecc 100644 --- a/pkg/plugin/implementation/requestPreProcessor/cmd/plugin.go +++ b/pkg/plugin/implementation/requestPreProcessor/cmd/plugin.go @@ -12,8 +12,8 @@ type provider struct{} func (p provider) New(ctx context.Context, c map[string]string) (func(http.Handler) http.Handler, error) { config := &requestpreprocessor.Config{} - if checkKeysStr, ok := c["CheckKeys"]; ok { - config.CheckKeys = strings.Split(checkKeysStr, ",") + if contextKeysStr, ok := c["ContextKeys"]; ok { + config.ContextKeys = strings.Split(contextKeysStr, ",") } return requestpreprocessor.NewUUIDSetter(config) } diff --git a/pkg/plugin/implementation/requestPreProcessor/cmd/plugin_test.go b/pkg/plugin/implementation/requestPreProcessor/cmd/plugin_test.go index 4a8aae7..8b4cfe9 100644 --- a/pkg/plugin/implementation/requestPreProcessor/cmd/plugin_test.go +++ b/pkg/plugin/implementation/requestPreProcessor/cmd/plugin_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" ) +// TODO: Will Split this into success and fail (two test cases) func TestProviderNew(t *testing.T) { testCases := []struct { name string diff --git a/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor.go b/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor.go index ed2abda..13d4da0 100644 --- a/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor.go +++ b/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor.go @@ -13,8 +13,8 @@ import ( ) type Config struct { - CheckKeys []string - Role string + ContextKeys []string + Role string } type becknRequest struct { @@ -50,7 +50,7 @@ func NewUUIDSetter(cfg *Config) (func(http.Handler) http.Handler, error) { subID = req.Context["bpp_id"] } ctx := context.WithValue(r.Context(), subscriberIDKey, subID) - for _, key := range cfg.CheckKeys { + for _, key := range cfg.ContextKeys { value := uuid.NewString() updatedValue := update(req.Context, key, value) ctx = context.WithValue(ctx, contextKeyType(key), updatedValue) @@ -90,15 +90,15 @@ func validateConfig(cfg *Config) error { return errors.New("config cannot be nil") } - // Check if CheckKeys is empty. - if len(cfg.CheckKeys) == 0 { - return errors.New("checkKeys cannot be empty") + // Check if ContextKeys is empty. + if len(cfg.ContextKeys) == 0 { + return errors.New("ContextKeys cannot be empty") } - // Validate that CheckKeys does not contain empty strings. - for _, key := range cfg.CheckKeys { + // Validate that ContextKeys does not contain empty strings. + for _, key := range cfg.ContextKeys { if key == "" { - return errors.New("checkKeys cannot contain empty strings") + return errors.New("ContextKeys cannot contain empty strings") } } return nil diff --git a/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor_test.go b/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor_test.go index 3e64156..307a7e7 100644 --- a/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor_test.go +++ b/pkg/plugin/implementation/requestPreProcessor/reqpreprocessor_test.go @@ -19,8 +19,8 @@ func TestNewUUIDSetterSuccessCases(t *testing.T) { { name: "Valid keys, update missing keys with bap role", config: &Config{ - CheckKeys: []string{"transaction_id", "message_id"}, - Role: "bap", + ContextKeys: []string{"transaction_id", "message_id"}, + Role: "bap", }, requestBody: map[string]any{ "context": map[string]any{ @@ -35,8 +35,8 @@ func TestNewUUIDSetterSuccessCases(t *testing.T) { { name: "Valid keys, do not update existing keys with bpp role", config: &Config{ - CheckKeys: []string{"transaction_id", "message_id"}, - Role: "bpp", + ContextKeys: []string{"transaction_id", "message_id"}, + Role: "bpp", }, requestBody: map[string]any{ "context": map[string]any{ @@ -66,7 +66,7 @@ func TestNewUUIDSetterSuccessCases(t *testing.T) { dummyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() w.WriteHeader(http.StatusOK) - + subID, ok := ctx.Value(subscriberIDKey).(string) if !ok { http.Error(w, "Subscriber ID not found", http.StatusInternalServerError) @@ -121,7 +121,7 @@ func TestNewUUIDSetterErrorCases(t *testing.T) { { name: "Missing context key", config: &Config{ - CheckKeys: []string{"transaction_id"}, + ContextKeys: []string{"transaction_id"}, }, requestBody: map[string]any{ "otherKey": "value", @@ -131,7 +131,7 @@ func TestNewUUIDSetterErrorCases(t *testing.T) { { name: "Invalid context type", config: &Config{ - CheckKeys: []string{"transaction_id"}, + ContextKeys: []string{"transaction_id"}, }, requestBody: map[string]any{ "context": "not-a-map", @@ -175,4 +175,4 @@ func TestNewUUIDSetterErrorCases(t *testing.T) { } }) } -} \ No newline at end of file +}