Skip to content

Commit

Permalink
NOISSUE - Fix Share Thing To Add External To Request (#1886)
Browse files Browse the repository at this point in the history
* Fix Share Thing To Add External To Request

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Comment External on SDK policy

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

---------

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
  • Loading branch information
rodneyosodo and drasko authored Aug 9, 2023
1 parent 896a74a commit 51998d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/sdk/go/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Policy struct {
Subject string `json:"subject"`
Object string `json:"object"`
Actions []string `json:"actions"`
External bool `json:"external,omitempty"` // This is specificially used in things service. If set to true, it means the subject is userID otherwise it is thingID.
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/sdk/go/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func TestDeletePolicy(t *testing.T) {
repoCall1 = pRepo.On("RetrieveAll", mock.Anything, mock.Anything).Return(convertUserPolicyPage(sdk.PolicyPage{Policies: []sdk.Policy{cpr}}), nil)
repoCall2 = pRepo.On("Delete", mock.Anything, mock.Anything).Return(sdk.ErrFailedRemoval)
err = mfsdk.DeleteUserPolicy(pr, invalidToken)
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthentication, http.StatusUnauthorized), fmt.Sprintf("expected %s got %s", pr, err))
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthentication, http.StatusUnauthorized), fmt.Sprintf("expected %v got %v", pr, err))
ok = repoCall.Parent.AssertCalled(t, "Delete", mock.Anything, mock.Anything)
assert.True(t, ok, "Delete was not called on invalid policy")
repoCall2.Unset()
Expand Down Expand Up @@ -741,7 +741,7 @@ func TestUnassign(t *testing.T) {
repoCall1 = pRepo.On("RetrieveAll", mock.Anything, mock.Anything).Return(convertUserPolicyPage(sdk.PolicyPage{Policies: []sdk.Policy{cpr}}), nil)
repoCall2 = pRepo.On("Delete", mock.Anything, mock.Anything).Return(sdk.ErrFailedRemoval)
err = mfsdk.Unassign(pr.Subject, pr.Object, invalidToken)
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthentication, http.StatusUnauthorized), fmt.Sprintf("expected %s got %s", pr, err))
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthentication, http.StatusUnauthorized), fmt.Sprintf("expected %v got %v", pr, err))
ok = repoCall.Parent.AssertCalled(t, "Delete", mock.Anything, mock.Anything)
assert.True(t, ok, "Delete was not called on invalid policy")
repoCall2.Unset()
Expand Down Expand Up @@ -1037,7 +1037,7 @@ func TestDisconnectThing(t *testing.T) {

repoCall = pRepo.On("Delete", mock.Anything, mock.Anything).Return(sdk.ErrFailedRemoval)
err = mfsdk.DisconnectThing(pr.Subject, pr.Object, invalidToken)
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthorization, http.StatusUnauthorized), fmt.Sprintf("expected %s got %s", pr, err))
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthorization, http.StatusUnauthorized), fmt.Sprintf("expected %v got %v", pr, err))
ok = repoCall.Parent.AssertCalled(t, "Delete", mock.Anything, mock.Anything)
assert.True(t, ok, "Delete was not called on invalid policy")
repoCall.Unset()
Expand Down Expand Up @@ -1076,7 +1076,7 @@ func TestDisconnect(t *testing.T) {
repoCall = pRepo.On("Delete", mock.Anything, mock.Anything).Return(sdk.ErrFailedRemoval)
conn = sdk.ConnectionIDs{ChannelIDs: []string{pr.Object}, ThingIDs: []string{pr.Subject}}
err = mfsdk.Disconnect(conn, invalidToken)
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthorization, http.StatusUnauthorized), fmt.Sprintf("expected %s got %s", pr, err))
assert.Equal(t, err, errors.NewSDKErrorWithStatus(errors.ErrAuthorization, http.StatusUnauthorized), fmt.Sprintf("expected %v got %v", pr, err))
ok = repoCall.Parent.AssertCalled(t, "Delete", mock.Anything, mock.Anything)
assert.True(t, ok, "Delete was not called on invalid policy")
repoCall.Unset()
Expand Down
11 changes: 6 additions & 5 deletions pkg/sdk/go/things.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ func (sdk mfSDK) IdentifyThing(key string) (string, errors.SDKError) {
}

func (sdk mfSDK) ShareThing(groupID, userID string, actions []string, token string) errors.SDKError {
policy := ConnectionIDs{
ChannelIDs: []string{groupID},
ThingIDs: []string{userID},
Actions: actions,
policy := Policy{
Subject: userID,
Object: groupID,
Actions: actions,
External: true,
}

return sdk.Connect(policy, token)
return sdk.CreateThingPolicy(policy, token)
}

0 comments on commit 51998d7

Please sign in to comment.