From 442cae6cb9fca075b92a9aac44aed1b29d238d9d Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Wed, 26 Aug 2020 11:21:53 +0545 Subject: [PATCH] get bundle with insuficiant permissions tests --- pkg/proto/v0/settings.pb.micro_test.go | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/proto/v0/settings.pb.micro_test.go b/pkg/proto/v0/settings.pb.micro_test.go index 4c3b73f8a0..15828fa4fb 100644 --- a/pkg/proto/v0/settings.pb.micro_test.go +++ b/pkg/proto/v0/settings.pb.micro_test.go @@ -350,6 +350,45 @@ func TestSaveBundleWithoutSettings(t *testing.T) { assert.Equal(t, merrors.New("ocis-settings", "extension: cannot be blank; name: cannot be blank; settings: cannot be blank.", 400), err) } +func TestGetBundleOfABundleSavedWithoutPermissions(t *testing.T) { + teardown := setup() + defer teardown() + + saveRequest := proto.SaveBundleRequest{ + Bundle: &bundleStub, + } + saveResponse, err := bundleService.SaveBundle(context.Background(), &saveRequest) + assert.NoError(t, err) + assert.Equal(t, bundleStub.Id, saveResponse.Bundle.Id) + + getRequest := proto.GetBundleRequest{BundleId: bundleStub.Id} + ctx := metadata.Set(context.Background(), middleware.AccountID, testAccountID) + getResponse, err := bundleService.GetBundle(ctx, &getRequest) + assert.Empty(t, getResponse) + + assert.Equal(t, merrors.New("ocis-settings", "could not read bundle: b1b8c9d0-fb3c-4e12-b868-5a8508218d2e", 404), err) +} + +func TestGetBundleOfABundleSavedWithFullPermissionsButForAnOtherUser(t *testing.T) { + teardown := setup() + defer teardown() + + saveRequest := proto.SaveBundleRequest{ + Bundle: &bundleStub, + } + saveResponse, err := bundleService.SaveBundle(context.Background(), &saveRequest) + assert.NoError(t, err) + assert.Equal(t, bundleStub.Id, saveResponse.Bundle.Id) + + setFullReadWriteOnBundle(t, "33ba12b3-0340-44ec-afdf-253fb90ea47d", bundleStub.Id) + getRequest := proto.GetBundleRequest{BundleId: bundleStub.Id} + ctx := metadata.Set(context.Background(), middleware.AccountID, testAccountID) + getResponse, err := bundleService.GetBundle(ctx, &getRequest) + assert.Empty(t, getResponse) + + assert.Equal(t, merrors.New("ocis-settings", "could not read bundle: b1b8c9d0-fb3c-4e12-b868-5a8508218d2e", 404), err) +} + /** testing that setting getting and listing a settings bundle works correctly with a set of setting definitions */