From d4f425f86ab690935788db6f4268c297624abc76 Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Fri, 7 Jun 2024 16:22:46 +0300 Subject: [PATCH] [#1167] adm/morph: Fix set-config parameter validation Signed-off-by: Alexander Chuprov --- .../internal/modules/morph/config/config.go | 27 +++++++++++---- .../modules/morph/config/config_test.go | 34 +++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 cmd/frostfs-adm/internal/modules/morph/config/config_test.go diff --git a/cmd/frostfs-adm/internal/modules/morph/config/config.go b/cmd/frostfs-adm/internal/modules/morph/config/config.go index f35e7aa0..bfcd4ac0 100644 --- a/cmd/frostfs-adm/internal/modules/morph/config/config.go +++ b/cmd/frostfs-adm/internal/modules/morph/config/config.go @@ -147,13 +147,28 @@ func validateConfig(args map[string]any, forceFlag bool) error { } for k, v := range args { - value, ok := v.(int64) - if !ok || value < 0 { - return fmt.Errorf("%s must be >= 0, got %v", k, v) - } + switch k { + case netmap.ContainerFeeConfig, netmap.ContainerAliasFeeConfig, + netmap.EpochDurationConfig, netmap.IrCandidateFeeConfig, + netmap.MaxObjectSizeConfig, netmap.WithdrawFeeConfig, + netmap.MaxECDataCountConfig, netmap.MaxECParityCountConfig: + value, ok := v.(int64) + if !ok { + return fmt.Errorf("%s has an invalid type. Expected type: int", k) + } - if k == netmap.MaxECDataCountConfig || k == netmap.MaxECParityCountConfig { - sumEC += value + if value < 0 { + return fmt.Errorf("%s must be >= 0, got %v", k, v) + } + + if k == netmap.MaxECDataCountConfig || k == netmap.MaxECParityCountConfig { + sumEC += value + } + case netmap.HomomorphicHashingDisabledKey, netmap.MaintenanceModeAllowedConfig: + _, ok := v.(bool) + if !ok { + return fmt.Errorf("%s has an invalid type. Expected type: bool", k) + } } } diff --git a/cmd/frostfs-adm/internal/modules/morph/config/config_test.go b/cmd/frostfs-adm/internal/modules/morph/config/config_test.go new file mode 100644 index 00000000..c6d5b282 --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/config/config_test.go @@ -0,0 +1,34 @@ +package config + +import ( + "testing" + + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap" + "github.com/stretchr/testify/require" +) + +func Test_ValidateConfig(t *testing.T) { + testArgs := make(map[string]any) + + testArgs[netmap.MaxECDataCountConfig] = int64(11) + require.Error(t, validateConfig(testArgs, false)) + + testArgs[netmap.MaxECParityCountConfig] = int64(256) + require.Error(t, validateConfig(testArgs, false)) + require.NoError(t, validateConfig(testArgs, true)) + + testArgs[netmap.MaxECParityCountConfig] = int64(-1) + require.Error(t, validateConfig(testArgs, false)) + + testArgs[netmap.MaxECParityCountConfig] = int64(55) + require.NoError(t, validateConfig(testArgs, false)) + + testArgs[netmap.HomomorphicHashingDisabledKey] = "1" + require.Error(t, validateConfig(testArgs, false)) + + testArgs[netmap.HomomorphicHashingDisabledKey] = true + require.NoError(t, validateConfig(testArgs, false)) + + testArgs["not-well-known-configuration-key"] = "key" + require.NoError(t, validateConfig(testArgs, false)) +}