Skip to content

Commit

Permalink
(fix): Enforce Consensus Capability config field key_id
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkaseman committed Oct 25, 2024
1 parent eaedfe1 commit f04a018
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions pkg/capabilities/consensus/ocr3/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aaaa",
"key_id": "key_id",
})
require.NoError(t, err)

Expand All @@ -337,6 +338,7 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
config, err := values.NewMap(map[string]any{
"aggregation_method": "data_feeds",
"report_id": "aaaa",
"key_id": "key_id",
})
require.NoError(t, err)

Expand All @@ -353,6 +355,7 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aa",
"key_id": "key_id",
})
require.NoError(t, err)

Expand All @@ -361,6 +364,22 @@ func TestOCR3Capability_ValidateConfig(t *testing.T) {
assert.Contains(t, err.Error(), "does not match pattern") // taken from the error json schema error message
require.Nil(t, c)
})

t.Run("InvalidConfig no key_id", func(t *testing.T) {
config, err := values.NewMap(map[string]any{
"aggregation_method": "data_feeds",
"aggregation_config": map[string]any{},
"encoder": "",
"encoder_config": map[string]any{},
"report_id": "aaaa",
})
require.NoError(t, err)

c, err := o.ValidateConfig(config)
require.Error(t, err)
assert.Contains(t, err.Error(), "missing properties: 'key_id'") // taken from the error json schema error message
require.Nil(t, c)
})
}

func TestOCR3Capability_RespondsToLateRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/capabilities/consensus/ocr3/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type config struct {
ReportID string `mapstructure:"report_id" json:"report_id" jsonschema:"required,pattern=^[a-f0-9]{4}$"`
RequestTimeoutMS int64 `mapstructure:"request_timeout_ms" json:"request_timeout_ms"`

KeyID string `mapstructure:"key_id" json:"key_id"`
KeyID string `mapstructure:"key_id" json:"key_id,omitempty" jsonschema:"required"`
}

type inputs struct {
Expand Down

0 comments on commit f04a018

Please sign in to comment.