diff --git a/things/api/things/http/endpoint_test.go b/things/api/things/http/endpoint_test.go index a1f8ad5b..637b3ddf 100644 --- a/things/api/things/http/endpoint_test.go +++ b/things/api/things/http/endpoint_test.go @@ -1957,7 +1957,7 @@ func TestCreateConnections(t *testing.T) { status: http.StatusNotFound, }, { - desc: "invalid content type", + desc: "connect with invalid content type", channelIDs: bchs, thingIDs: ths, auth: token, @@ -1965,12 +1965,36 @@ func TestCreateConnections(t *testing.T) { status: http.StatusUnsupportedMediaType, }, { - desc: "invalid JSON", + desc: "connect with invalid JSON", auth: token, contentType: contentType, status: http.StatusBadRequest, body: "{", }, + { + desc: "connect valid thing ids with empty channel ids", + channelIDs: []string{}, + thingIDs: ths, + auth: token, + contentType: contentType, + status: http.StatusBadRequest, + }, + { + desc: "connect valid channel ids with empty thing ids", + channelIDs: achs, + thingIDs: []string{}, + auth: token, + contentType: contentType, + status: http.StatusBadRequest, + }, + { + desc: "connect empty channel ids and empty thing ids", + channelIDs: []string{}, + thingIDs: []string{}, + auth: token, + contentType: contentType, + status: http.StatusBadRequest, + }, } for _, tc := range cases { diff --git a/things/api/things/http/requests.go b/things/api/things/http/requests.go index 39e0c8f2..34763215 100644 --- a/things/api/things/http/requests.go +++ b/things/api/things/http/requests.go @@ -252,6 +252,10 @@ func (req createConnectionsReq) validate() error { return things.ErrUnauthorizedAccess } + if len(req.ChannelIDs) == 0 || len(req.ThingIDs) == 0 { + return things.ErrMalformedEntity + } + for _, chID := range req.ChannelIDs { if chID == "" { return things.ErrMalformedEntity