NOISSUE - Fix Share Thing To Add External To Request (#1886)
* 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>
This commit is contained in:
parent
896a74ad49
commit
51998d79af
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue