mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +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,
|
||||
},
|
||||
{
|
||||
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 {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user