Skip to content

Commit

Permalink
Test middleend Update with non-AIP complaint names.
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun committed Jun 28, 2023
1 parent 9732e5d commit c8db9f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions pkg/middleend/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ func TestMiddleEnd_UpdateEncryptedVolume(t *testing.T) {
false,
false,
},
"malformed name": {
nil,
&pb.EncryptedVolume{Name: "-ABC-DEF"},
nil,
[]string{""},
codes.Unknown,
fmt.Sprintf("segment '%s': not a valid DNS name", "-ABC-DEF"),
false,
false,
},
}

// run tests
Expand Down
10 changes: 5 additions & 5 deletions pkg/middleend/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ func (s *Server) UpdateQosVolume(_ context.Context, in *pb.UpdateQosVolumeReques
log.Printf("error: %v", err)
return nil, err
}
// Validate that a resource name conforms to the restrictions outlined in AIP-122.
// if err := resourcename.Validate(in.QosVolume.Name); err != nil {
// log.Printf("error: %v", err)
// return nil, err
// }

// fetch object from the database
if err := s.verifyQosVolume(in.QosVolume); err != nil {
log.Println("error:", err)
Expand Down Expand Up @@ -253,6 +249,10 @@ func (s *Server) verifyQosVolume(volume *pb.QosVolume) error {
if volume.Name == "" {
return fmt.Errorf("QoS volume name cannot be empty")
}
// Validate that a resource name conforms to the restrictions outlined in AIP-122.
if err := resourcename.Validate(volume.Name); err != nil {
return err
}
if volume.VolumeId == nil || volume.VolumeId.Value == "" {
return fmt.Errorf("volume_id cannot be empty")
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/middleend/qos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,17 @@ func TestMiddleEnd_UpdateQosVolume(t *testing.T) {
existBefore: true,
missing: false,
},
"malformed name": {
mask: nil,
in: &pb.QosVolume{Name: "-ABC-DEF"},
out: nil,
spdk: []string{""},
errCode: codes.InvalidArgument,
errMsg: fmt.Sprintf("segment '%s': not a valid DNS name", "-ABC-DEF"),
start: false,
existBefore: false,
missing: false,
},
}

for name, tt := range tests {
Expand Down

0 comments on commit c8db9f5

Please sign in to comment.