Skip to content

Commit

Permalink
MF-1237 - Return to transport only things service errors (#1236)
Browse files Browse the repository at this point in the history
* Replace error messages for things and channels with error messages for entities

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Add db and cache errors

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Migrate swagger to openapi

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Remove db and cache specific err msgs and generalize errs

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Redefine status codes

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Define endpoint error codes in service and swagger

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Fix tests

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Refactor sdk errors

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Fix grpc tests

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Reformat and add err check

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
  • Loading branch information
darkodraskovic authored Sep 23, 2020
1 parent f10e49e commit 043d1e0
Show file tree
Hide file tree
Showing 21 changed files with 1,474 additions and 1,348 deletions.
26 changes: 13 additions & 13 deletions pkg/sdk/go/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func TestCreateChannel(t *testing.T) {
desc: "create new channel with empty token",
channel: channel,
token: "",
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
empty: true,
},
{
desc: "create new channel with invalid token",
channel: channel,
token: wrongValue,
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
empty: true,
},
{
Expand Down Expand Up @@ -126,14 +126,14 @@ func TestCreateChannels(t *testing.T) {
desc: "create new channels with empty token",
channels: channels,
token: "",
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
res: []sdk.Channel{},
},
{
desc: "create new channels with invalid token",
channels: channels,
token: wrongValue,
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
res: []sdk.Channel{},
},
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestChannel(t *testing.T) {
desc: "get channel with invalid token",
chanID: id,
token: "",
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: sdk.Channel{},
},
}
Expand Down Expand Up @@ -244,15 +244,15 @@ func TestChannels(t *testing.T) {
token: wrongValue,
offset: 0,
limit: 5,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
desc: "get a list of channels with empty token",
token: "",
offset: 0,
limit: 5,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestChannelsByThing(t *testing.T) {
offset: 0,
limit: 5,
connected: true,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
Expand All @@ -376,7 +376,7 @@ func TestChannelsByThing(t *testing.T) {
offset: 0,
limit: 5,
connected: true,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
Expand Down Expand Up @@ -483,13 +483,13 @@ func TestUpdateChannel(t *testing.T) {
desc: "update channel with invalid token",
channel: sdk.Channel{ID: id, Name: "test2"},
token: wrongValue,
err: createError(sdk.ErrFailedUpdate, http.StatusForbidden),
err: createError(sdk.ErrFailedUpdate, http.StatusUnauthorized),
},
{
desc: "update channel with empty token",
channel: sdk.Channel{ID: id, Name: "test2"},
token: "",
err: createError(sdk.ErrFailedUpdate, http.StatusForbidden),
err: createError(sdk.ErrFailedUpdate, http.StatusUnauthorized),
},
}

Expand Down Expand Up @@ -526,7 +526,7 @@ func TestDeleteChannel(t *testing.T) {
desc: "delete channel with invalid token",
chanID: id,
token: wrongValue,
err: createError(sdk.ErrFailedRemoval, http.StatusForbidden),
err: createError(sdk.ErrFailedRemoval, http.StatusUnauthorized),
},
{
desc: "delete non-existing channel",
Expand All @@ -544,7 +544,7 @@ func TestDeleteChannel(t *testing.T) {
desc: "delete channel with empty token",
chanID: id,
token: "",
err: createError(sdk.ErrFailedRemoval, http.StatusForbidden),
err: createError(sdk.ErrFailedRemoval, http.StatusUnauthorized),
},
{
desc: "delete existing channel",
Expand Down
38 changes: 19 additions & 19 deletions pkg/sdk/go/things_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func TestCreateThing(t *testing.T) {
desc: "create new thing with empty token",
thing: thing,
token: "",
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
location: "",
},
{
desc: "create new thing with invalid token",
thing: thing,
token: wrongValue,
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
location: "",
},
}
Expand Down Expand Up @@ -163,14 +163,14 @@ func TestCreateThings(t *testing.T) {
desc: "create new thing with empty token",
things: things,
token: "",
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
res: []sdk.Thing{},
},
{
desc: "create new thing with invalid token",
things: things,
token: wrongValue,
err: createError(sdk.ErrFailedCreation, http.StatusForbidden),
err: createError(sdk.ErrFailedCreation, http.StatusUnauthorized),
res: []sdk.Thing{},
},
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestThing(t *testing.T) {
desc: "get thing with invalid token",
thID: id,
token: wrongValue,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: sdk.Thing{},
},
}
Expand Down Expand Up @@ -286,15 +286,15 @@ func TestThings(t *testing.T) {
token: wrongValue,
offset: 0,
limit: 5,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
desc: "get a list of things with empty token",
token: "",
offset: 0,
limit: 5,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestThingsByChannel(t *testing.T) {
offset: 0,
limit: 5,
connected: true,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
Expand All @@ -422,7 +422,7 @@ func TestThingsByChannel(t *testing.T) {
offset: 0,
limit: 5,
connected: true,
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
err: createError(sdk.ErrFailedFetch, http.StatusUnauthorized),
response: nil,
},
{
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestUpdateThing(t *testing.T) {
Metadata: metadata2,
},
token: wrongValue,
err: createError(sdk.ErrFailedUpdate, http.StatusForbidden),
err: createError(sdk.ErrFailedUpdate, http.StatusUnauthorized),
},
{
desc: "update channel with empty token",
Expand All @@ -555,7 +555,7 @@ func TestUpdateThing(t *testing.T) {
Metadata: metadata2,
},
token: "",
err: createError(sdk.ErrFailedUpdate, http.StatusForbidden),
err: createError(sdk.ErrFailedUpdate, http.StatusUnauthorized),
},
}

Expand Down Expand Up @@ -592,7 +592,7 @@ func TestDeleteThing(t *testing.T) {
desc: "delete thing with invalid token",
thingID: id,
token: wrongValue,
err: createError(sdk.ErrFailedRemoval, http.StatusForbidden),
err: createError(sdk.ErrFailedRemoval, http.StatusUnauthorized),
},
{
desc: "delete non-existing thing",
Expand All @@ -610,7 +610,7 @@ func TestDeleteThing(t *testing.T) {
desc: "delete thing with empty token",
thingID: id,
token: "",
err: createError(sdk.ErrFailedRemoval, http.StatusForbidden),
err: createError(sdk.ErrFailedRemoval, http.StatusUnauthorized),
},
{
desc: "delete existing thing",
Expand Down Expand Up @@ -708,14 +708,14 @@ func TestConnectThing(t *testing.T) {
thingID: thingID,
chanID: chanID1,
token: wrongValue,
err: createError(sdk.ErrFailedConnect, http.StatusForbidden),
err: createError(sdk.ErrFailedConnect, http.StatusUnauthorized),
},
{
desc: "connect existing thing to existing channel with empty token",
thingID: thingID,
chanID: chanID1,
token: "",
err: createError(sdk.ErrFailedConnect, http.StatusForbidden),
err: createError(sdk.ErrFailedConnect, http.StatusUnauthorized),
},
{
desc: "connect thing from owner to channel of other user",
Expand Down Expand Up @@ -812,14 +812,14 @@ func TestConnect(t *testing.T) {
thingID: thingID,
chanID: chanID1,
token: wrongValue,
err: createError(sdk.ErrFailedConnect, http.StatusForbidden),
err: createError(sdk.ErrFailedConnect, http.StatusUnauthorized),
},
{
desc: "connect existing things to existing channels with empty token",
thingID: thingID,
chanID: chanID1,
token: emptyValue,
err: createError(sdk.ErrFailedConnect, http.StatusForbidden),
err: createError(sdk.ErrFailedConnect, http.StatusUnauthorized),
},
{
desc: "connect things from owner to channels of other user",
Expand Down Expand Up @@ -923,14 +923,14 @@ func TestDisconnectThing(t *testing.T) {
thingID: thingID,
chanID: chanID1,
token: wrongValue,
err: createError(sdk.ErrFailedDisconnect, http.StatusForbidden),
err: createError(sdk.ErrFailedDisconnect, http.StatusUnauthorized),
},
{
desc: "disconnect existing thing from existing channel with empty token",
thingID: thingID,
chanID: chanID1,
token: "",
err: createError(sdk.ErrFailedDisconnect, http.StatusForbidden),
err: createError(sdk.ErrFailedDisconnect, http.StatusUnauthorized),
},
{
desc: "disconnect owner's thing from someone elses channel",
Expand Down
Loading

0 comments on commit 043d1e0

Please sign in to comment.