Skip to content

Commit

Permalink
remove _ownerKeyVersion when removing identity fields
Browse files Browse the repository at this point in the history
we found this when looking into tutadb#1862.
it is not critical as the _ownerKeyVersion is never used, but we should clean it properly
  • Loading branch information
vaf-hub committed Oct 7, 2024
1 parent 55bd5c1 commit ee87216
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/tutanota-utils/test/UtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import o from "@tutao/otest"
import { clone, deepEqual, getChangedProps } from "../lib/Utils.js"
import { arrayEquals } from "../lib/index.js"

o.spec("utils", function () {
o("deep clone an instance", function () {
Expand All @@ -9,7 +10,9 @@ o.spec("utils", function () {
address.address = "donald@duck.de"
address.customTypeName = ""
let c1: any = {}
c1._ownerEncSessionKey = new Uint8Array([3, 2])
const ownerEncSessionKey = new Uint8Array([3, 2])
c1._ownerKeyVersion = "2"
c1._ownerEncSessionKey = ownerEncSessionKey
c1._id = ["dummyListId", "dummyId"]
c1.firstName = "Donald"
c1.lastName = "Duck"
Expand All @@ -22,6 +25,8 @@ o.spec("utils", function () {
o(Object.is(c1._ownerEncSessionKey, c2._ownerEncSessionKey)).equals(false)("Uint8Arrays must be cloned")
o(c1._ownerEncSessionKey instanceof Uint8Array).equals(true)
o(c2._ownerEncSessionKey instanceof Uint8Array).equals(true)
o(c2._ownerKeyVersion).equals(c1._ownerKeyVersion)
o(arrayEquals(ownerEncSessionKey, c2._ownerEncSessionKey)).equals(true)
o(Object.is(c1.mailAddresses[0], c2.mailAddresses[0])).equals(false)("objects must be cloned")
})
o("getChangedProps", function () {
Expand Down
2 changes: 1 addition & 1 deletion src/common/api/common/utils/EntityUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export function getStrippedClone<E extends SomeEntity>(entity: StrippedEntity<E>
* remove fields that do not contain user defined data but are related to finding/accessing the entity on the server
*/
function removeIdentityFields<E extends Partial<SomeEntity>>(entity: E) {
const keysToDelete = ["_id", "_ownerGroup", "_ownerEncSessionKey", "_permissions"]
const keysToDelete = ["_id", "_ownerGroup", "_ownerEncSessionKey", "_ownerKeyVersion", "_permissions"]

function _removeIdentityFields(erased: Record<string, any>) {
for (const key of Object.keys(erased)) {
Expand Down

0 comments on commit ee87216

Please sign in to comment.