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:
parent
2080ee8afa
commit
887bc2d9c0
@ -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 {
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user