Skip to content

Commit

Permalink
fix: Error when CreateVMReq does not have Spec (#470)
Browse files Browse the repository at this point in the history
* fix: Error when CreateVMReq does not have Spec

In the rare case that a user either:
- Sends the wrong request type to the server (ie uses BloomRPC to send a
  ListReq to a Create call)
- Does not include a Spec at all on a CreateMicroVMRequest

we check for its presence and error if not found.

We are doing something similar for other server requests, so this
completes it.
  • Loading branch information
Callisto13 authored Jun 27, 2022
1 parent 945ad35 commit d33959f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions infrastructure/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func (s *server) CreateMicroVM(
logger := log.GetLogger(ctx)
logger.Trace("converting request to model")

if req == nil {
logger.Error("invalid create microvm request")
if req == nil || req.Microvm == nil {
logger.Error("invalid create microvm request: MicroVMSpec required")

//nolint:wrapcheck // don't wrap grpc errors when using the status package
return nil, status.Error(codes.InvalidArgument, "invalid request")
return nil, status.Error(codes.InvalidArgument, "invalid create microvm request: MicroVMSpec required")
}

modelSpec, err := convertMicroVMToModel(req.Microvm)
Expand Down
6 changes: 6 additions & 0 deletions infrastructure/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func TestServer_CreateMicroVM(t *testing.T) {
expectError: true,
expect: func(cm *mock.MockMicroVMCommandUseCasesMockRecorder, qm *mock.MockMicroVMQueryUseCasesMockRecorder) {},
},
{
name: "nil spec should fail with error",
createReq: &mvm1.CreateMicroVMRequest{},
expectError: true,
expect: func(cm *mock.MockMicroVMCommandUseCasesMockRecorder, qm *mock.MockMicroVMQueryUseCasesMockRecorder) {},
},
{
name: "missing id should fail with error",
createReq: createTestCreateRequest("", ""),
Expand Down

0 comments on commit d33959f

Please sign in to comment.