Skip to content

Commit 23a3b58

Browse files
committed
ir/netmap: Fix admitting of netmap candidates with duplicate attributes
Defect of 757b90e. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent dd8073b commit 23a3b58

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pkg/innerring/processors/netmap/nodevalidation/structure/calls.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func (v *Validator) Verify(n netmap.NodeInfo) error {
1818
n.IterateAttributes(func(key, _ string) {
1919
if _, alreadyHave := attrM[key]; alreadyHave {
2020
err = fmt.Errorf("repeating node attribute: '%s'", key)
21+
return
2122
}
23+
attrM[key] = struct{}{}
2224
})
2325

2426
return err
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package structure_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/structure"
7+
"github.com/nspcc-dev/neofs-sdk-go/netmap"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestValidator_Verify(t *testing.T) {
12+
v := structure.New()
13+
t.Run("duplicated attributes", func(t *testing.T) {
14+
var n netmap.NodeInfo
15+
n.SetAttributes([][2]string{
16+
{"key1", "val1"},
17+
{"key2", "val2"},
18+
{"key1", "val3"},
19+
{"key2", "val4"},
20+
})
21+
require.EqualError(t, v.Verify(n), "repeating node attribute: 'key2'")
22+
})
23+
}

0 commit comments

Comments
 (0)