1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00

MF-982 - Add error when connecting empty channels or things (#985)

* Add error when connecting empty channels or things

Signed-off-by: nwneisen <nwneisen@gmail.com>

* Add more detailed test descriptions

Signed-off-by: nwneisen <nwneisen@gmail.com>

* Add to test descriptions

Signed-off-by: nwneisen <nwneisen@gmail.com>

* fix channel ids

Signed-off-by: nwneisen <nwneisen@gmail.com>
This commit is contained in:
Nick Neisen 2019-12-17 11:53:45 -07:00 committed by Drasko DRASKOVIC
parent 2080ee8afa
commit 887bc2d9c0
2 changed files with 30 additions and 2 deletions

View File

@ -1957,7 +1957,7 @@ func TestCreateConnections(t *testing.T) {
status: http.StatusNotFound, status: http.StatusNotFound,
}, },
{ {
desc: "invalid content type", desc: "connect with invalid content type",
channelIDs: bchs, channelIDs: bchs,
thingIDs: ths, thingIDs: ths,
auth: token, auth: token,
@ -1965,12 +1965,36 @@ func TestCreateConnections(t *testing.T) {
status: http.StatusUnsupportedMediaType, status: http.StatusUnsupportedMediaType,
}, },
{ {
desc: "invalid JSON", desc: "connect with invalid JSON",
auth: token, auth: token,
contentType: contentType, contentType: contentType,
status: http.StatusBadRequest, status: http.StatusBadRequest,
body: "{", 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 { for _, tc := range cases {

View File

@ -252,6 +252,10 @@ func (req createConnectionsReq) validate() error {
return things.ErrUnauthorizedAccess return things.ErrUnauthorizedAccess
} }
if len(req.ChannelIDs) == 0 || len(req.ThingIDs) == 0 {
return things.ErrMalformedEntity
}
for _, chID := range req.ChannelIDs { for _, chID := range req.ChannelIDs {
if chID == "" { if chID == "" {
return things.ErrMalformedEntity return things.ErrMalformedEntity