From f01263859b594ccf4fca188977f7b80d63c3786b Mon Sep 17 00:00:00 2001 From: jkoberg Date: Sat, 12 Mar 2022 14:19:41 +0100 Subject: [PATCH] share accepted/declined events Signed-off-by: jkoberg --- audit/pkg/service/service_test.go | 35 ++++++++++++++++++++++++++----- audit/pkg/types/constants.go | 18 ++++++++++++++++ audit/pkg/types/conversion.go | 24 ++++++++++++++++++++- audit/pkg/types/types.go | 4 ---- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/audit/pkg/service/service_test.go b/audit/pkg/service/service_test.go index 4ec5a439d9..bb60d064a1 100644 --- a/audit/pkg/service/service_test.go +++ b/audit/pkg/service/service_test.go @@ -214,13 +214,38 @@ var testCases = []struct { require.NoError(t, json.Unmarshal(b, &ev)) // AuditEvent fields - checkBaseAuditEvent(t, ev.AuditEvent, "", "", "public link id:'token-123' was removed", "file_unshared") + checkBaseAuditEvent(t, ev.AuditEvent, "beshared-userid", "2001-09-09T03:46:40+02:00", "user 'beshared-userid' accepted share 'shareid' from user 'sharing-userid'", "share_accepted") // AuditEventSharing fields - checkSharingAuditEvent(t, ev.AuditEventSharing, "", "", "token-123") + checkSharingAuditEvent(t, ev.AuditEventSharing, "itemid-1", "sharing-userid", "shareid") // AuditEventShareUpdated fields - require.Equal(t, "", ev.ItemType) // not implemented atm - require.Equal(t, "link", ev.ShareType) - require.Equal(t, "", ev.ShareWith) // not filled on links + require.Equal(t, "", ev.ItemType) + require.Equal(t, "user", ev.ShareType) + require.Equal(t, "beshared-userid", ev.ShareWith) + }, + }, { + Alias: "Share declined", + SystemEvent: events.ReceivedShareUpdated{ + ShareID: shareID("shareid"), + ItemID: resourceID("storageid-1", "itemid-1"), + Permissions: sharePermissions("get_quota"), + GranteeUserID: userID("beshared-userid"), + GranteeGroupID: nil, + Sharer: userID("sharing-userid"), + MTime: timestamp(10e8), + State: "SHARE_STATE_DECLINED", + }, + CheckAuditEvent: func(t *testing.T, b []byte) { + ev := types.AuditEventReceivedShareUpdated{} + require.NoError(t, json.Unmarshal(b, &ev)) + + // AuditEvent fields + checkBaseAuditEvent(t, ev.AuditEvent, "beshared-userid", "2001-09-09T03:46:40+02:00", "user 'beshared-userid' declined share 'shareid' from user 'sharing-userid'", "share_declined") + // AuditEventSharing fields + checkSharingAuditEvent(t, ev.AuditEventSharing, "itemid-1", "sharing-userid", "shareid") + // AuditEventShareUpdated fields + require.Equal(t, "", ev.ItemType) + require.Equal(t, "user", ev.ShareType) + require.Equal(t, "beshared-userid", ev.ShareWith) }, }, } diff --git a/audit/pkg/types/constants.go b/audit/pkg/types/constants.go index 00084862e8..a8372249e6 100644 --- a/audit/pkg/types/constants.go +++ b/audit/pkg/types/constants.go @@ -10,6 +10,9 @@ const ( ActionSharePasswordUpdated = "share_password_updated" ActionShareExpirationUpdated = "share_expiration_updated" ActionShareRemoved = "file_unshared" + ActionShareAccepted = "share_accepted" + ActionShareDeclined = "share_declined" + ActionLinkAccessed = "public_link_accessed" ) // MessageShareCreated returns the human readable string that describes the action @@ -41,3 +44,18 @@ func MessageShareRemoved(sharer, shareid, itemid string) string { func MessageLinkRemoved(shareid string) string { return fmt.Sprintf("public link id:'%s' was removed", shareid) } + +// MessageShareAccepted returns the human readable string that describes the action +func MessageShareAccepted(userid, shareid, sharerid string) string { + return fmt.Sprintf("user '%s' accepted share '%s' from user '%s'", userid, shareid, sharerid) +} + +// MessageShareDeclined returns the human readable string that describes the action +func MessageShareDeclined(userid, shareid, sharerid string) string { + return fmt.Sprintf("user '%s' declined share '%s' from user '%s'", userid, shareid, sharerid) +} + +// MessageLinkAccessed returns the human readable string that describes the action +func MessageLinkAccessed(linkid string, success bool) string { + return fmt.Sprintf("link '%s' was accessed. Success: %b", linkid, success) +} diff --git a/audit/pkg/types/conversion.go b/audit/pkg/types/conversion.go index 79d1b3fbf2..a0c55384ed 100644 --- a/audit/pkg/types/conversion.go +++ b/audit/pkg/types/conversion.go @@ -168,7 +168,29 @@ func LinkRemoved(ev events.LinkRemoved) AuditEventShareRemoved { // ReceivedShareUpdated converts a ReceivedShareUpdated event to an AuditEventReceivedShareUpdated func ReceivedShareUpdated(ev events.ReceivedShareUpdated) AuditEventReceivedShareUpdated { - return AuditEventReceivedShareUpdated{} + uid := ev.Sharer.GetOpaqueId() + sid := ev.ShareID.GetOpaqueId() + with, typ := extractGrantee(ev.GranteeUserID, ev.GranteeGroupID) + itemID := ev.ItemID.GetOpaqueId() + + msg, utype := "", "" + switch ev.State { + case "SHARE_STATE_ACCEPTED": + msg = MessageShareAccepted(with, sid, uid) + utype = ActionShareAccepted + case "SHARE_STATE_DECLINED": + msg = MessageShareDeclined(with, sid, uid) + utype = ActionShareDeclined + } + base := BasicAuditEvent(with, formatTime(ev.MTime), msg, utype) + return AuditEventReceivedShareUpdated{ + AuditEventSharing: SharingAuditEvent(sid, itemID, uid, base), + ShareType: typ, + ShareWith: with, + + // NOTE: those values are not in the event and can therefore not be filled at the moment + ItemType: "", + } } // LinkAccessed converts a LinkAccessed event to an AuditEventLinkAccessed diff --git a/audit/pkg/types/types.go b/audit/pkg/types/types.go index abe4ac671d..17e2d0a3e1 100644 --- a/audit/pkg/types/types.go +++ b/audit/pkg/types/types.go @@ -67,10 +67,6 @@ type AuditEventReceivedShareUpdated struct { ItemType string // file or folder ShareType string // group user or link ShareWith string // The UID or GID of the share recipient. - Path string // The path of the shared item. - Owner string // The UID of the owner of the shared item. - FileID string // The file identifier for the item shared. - ShareID string // The sharing identifier. (not available for public_link_accessed) } // AuditEventLinkAccessed is the event logged when a link is accessed