From 3f448d2d1f8924184ecf4cd77c8cec4c1962325b Mon Sep 17 00:00:00 2001 From: martgil Date: Thu, 20 Mar 2025 15:51:14 +0800 Subject: [PATCH 1/4] refactor: use .toISOString() in compatibility.ts --- extension/js/common/core/crypto/key.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extension/js/common/core/crypto/key.ts b/extension/js/common/core/crypto/key.ts index 3fd41622eba..07d5478b788 100644 --- a/extension/js/common/core/crypto/key.ts +++ b/extension/js/common/core/crypto/key.ts @@ -275,7 +275,8 @@ export class KeyUtil { const opgpresult = await OpenPGPKey.diagnose(key, passphrase); result = new Map([...result, ...opgpresult]); } - result.set(`expiration`, KeyUtil.formatResult(key.expiration)); + const expirationIso = key.expiration ? new Date(key.expiration).toISOString() : undefined; + result.set(`expiration`, KeyUtil.formatResult(expirationIso)); result.set(`internal dateBeforeExpiration`, await KeyUtil.formatResultAsync(async () => KeyUtil.dateBeforeExpirationIfAlreadyExpired(key))); result.set(`internal usableForEncryption`, KeyUtil.formatResult(key.usableForEncryption)); result.set(`internal usableForSigning`, KeyUtil.formatResult(key.usableForSigning)); @@ -292,8 +293,9 @@ export class KeyUtil { } } - public static formatResult(value: unknown): string { - return `[-] ${String(value)}`; + public static formatResult(value: unknown | undefined): string { + const formattedOutput = value !== undefined ? (value as string) : '-'; + return `[-] ${formattedOutput}`; } public static async asPublicKey(key: Key): Promise { From 3bc3c4aa43d9d44d6fd8096db193ab1c32636d34 Mon Sep 17 00:00:00 2001 From: martgil Date: Thu, 20 Mar 2025 16:40:54 +0800 Subject: [PATCH 2/4] test: fix failing test --- test/source/tests/unit-node.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/source/tests/unit-node.ts b/test/source/tests/unit-node.ts index fe7ef024735..9591343587b 100644 --- a/test/source/tests/unit-node.ts +++ b/test/source/tests/unit-node.ts @@ -1638,8 +1638,8 @@ ZAvn6PBX7vsaReOVa2zsnuY5g70xCxvzHIwR94POu5cENwRtCkrppFnISALpQ1kA expect(result.get('SK 0 > SIG 0 > Sig creation time')).to.equal('[-] 1606140328 or 2020-11-23T14:05:28.000Z'); expect(result.get('SK 0 > SIG 0 > Sig expiration time')).to.equal('[-] -'); expect(result.get('SK 0 > SIG 0 > Verify')).to.equal('[-] valid'); - expect(result.get('expiration')).to.equal('[-] undefined'); - expect(result.get('internal dateBeforeExpiration')).to.equal('[-] undefined'); + expect(result.get('expiration')).to.equal('[-] -'); + expect(result.get('internal dateBeforeExpiration')).to.equal('[-] -'); expect(result.get('internal usableForEncryptionButExpired')).to.equal('[-] false'); expect(result.get('internal usableForSigningButExpired')).to.equal('[-] false'); t.pass(); @@ -1676,8 +1676,8 @@ ZAvn6PBX7vsaReOVa2zsnuY5g70xCxvzHIwR94POu5cENwRtCkrppFnISALpQ1kA expect(result.get('SK 0 > SIG 0 > Sig creation time')).to.equal('[-] 1606140328 or 2020-11-23T14:05:28.000Z'); expect(result.get('SK 0 > SIG 0 > Sig expiration time')).to.equal('[-] -'); expect(result.get('SK 0 > SIG 0 > Verify')).to.equal('[-] valid'); - expect(result.get('expiration')).to.equal('[-] undefined'); - expect(result.get('internal dateBeforeExpiration')).to.equal('[-] undefined'); + expect(result.get('expiration')).to.equal('[-] -'); + expect(result.get('internal dateBeforeExpiration')).to.equal('[-] -'); expect(result.get('internal usableForEncryptionButExpired')).to.equal('[-] false'); expect(result.get('internal usableForSigningButExpired')).to.equal('[-] false'); t.pass(); @@ -1983,8 +1983,8 @@ jA== expect(result.get('SK 0 > SIG 0 > Sig creation time')).to.equal('[-] 1606140328 or 2020-11-23T14:05:28.000Z'); expect(result.get('SK 0 > SIG 0 > Sig expiration time')).to.equal('[-] -'); expect(result.get('SK 0 > SIG 0 > Verify')).to.equal('[-] valid'); - expect(result.get('expiration')).to.equal('[-] undefined'); - expect(result.get('internal dateBeforeExpiration')).to.equal('[-] undefined'); + expect(result.get('expiration')).to.equal('[-] -'); + expect(result.get('internal dateBeforeExpiration')).to.equal('[-] -'); expect(result.get('internal usableForEncryptionButExpired')).to.equal('[-] false'); expect(result.get('internal usableForSigningButExpired')).to.equal('[-] false'); t.pass(); @@ -2021,8 +2021,8 @@ jA== expect(result.get('SK 0 > SIG 0 > Sig creation time')).to.equal('[-] 1611500699 or 2021-01-24T15:04:59.000Z'); expect(result.get('SK 0 > SIG 0 > Sig expiration time')).to.equal('[-] -'); expect(result.get('SK 0 > SIG 0 > Verify')).to.equal('[-] valid'); - expect(result.get('expiration')).to.equal('[-] undefined'); - expect(result.get('internal dateBeforeExpiration')).to.equal('[-] undefined'); + expect(result.get('expiration')).to.equal('[-] -'); + expect(result.get('internal dateBeforeExpiration')).to.equal('[-] -'); expect(result.get('internal usableForEncryptionButExpired')).to.equal('[-] false'); expect(result.get('internal usableForSigningButExpired')).to.equal('[-] false'); t.pass(); From 41129905144f9db99c6286c83ae9efdc050b648f Mon Sep 17 00:00:00 2001 From: martgil <46025304+martgil@users.noreply.github.com> Date: Wed, 2 Apr 2025 15:30:28 +0800 Subject: [PATCH 3/4] test: fix failing test --- test/source/tests/unit-node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/source/tests/unit-node.ts b/test/source/tests/unit-node.ts index 8e6776067cb..fe5f31c729d 100644 --- a/test/source/tests/unit-node.ts +++ b/test/source/tests/unit-node.ts @@ -2022,7 +2022,7 @@ jA== expect(result.get('SK 0 > SIG 0 > Sig creation time')).to.equal('[-] 1611140947 or 2021-01-20T11:09:07.000Z'); expect(result.get('SK 0 > SIG 0 > Sig expiration time')).to.equal('[-] -'); expect(result.get('SK 0 > SIG 0 > Verify')).to.equal('[-] valid'); - expect(result.get('expiration')).to.equal('[-] undefined'); + expect(result.get('expiration')).to.equal('[-] -'); expect(result.get('internal dateBeforeExpiration')).to.equal('[-] undefined'); expect(result.get('internal usableForEncryptionButExpired')).to.equal('[-] false'); expect(result.get('internal usableForSigningButExpired')).to.equal('[-] false'); From 44f7011a98b4eae44dc0e51d04d829342b27e9d3 Mon Sep 17 00:00:00 2001 From: martgil <46025304+martgil@users.noreply.github.com> Date: Wed, 2 Apr 2025 16:08:33 +0800 Subject: [PATCH 4/4] test: fix failing test --- test/source/tests/unit-node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/source/tests/unit-node.ts b/test/source/tests/unit-node.ts index fe5f31c729d..1d4577444fb 100644 --- a/test/source/tests/unit-node.ts +++ b/test/source/tests/unit-node.ts @@ -2023,7 +2023,7 @@ jA== expect(result.get('SK 0 > SIG 0 > Sig expiration time')).to.equal('[-] -'); expect(result.get('SK 0 > SIG 0 > Verify')).to.equal('[-] valid'); expect(result.get('expiration')).to.equal('[-] -'); - expect(result.get('internal dateBeforeExpiration')).to.equal('[-] undefined'); + expect(result.get('internal dateBeforeExpiration')).to.equal('[-] -'); expect(result.get('internal usableForEncryptionButExpired')).to.equal('[-] false'); expect(result.get('internal usableForSigningButExpired')).to.equal('[-] false'); t.pass();