Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Fix Share Thing To Add External To Request #1886

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading