diff --git a/scm-ui/ui-types/src/index.ts b/scm-ui/ui-types/src/index.ts index a0ce96dac9..7a36ecfc3e 100644 --- a/scm-ui/ui-types/src/index.ts +++ b/scm-ui/ui-types/src/index.ts @@ -36,7 +36,7 @@ export { Branch, BranchRequest } from "./Branches"; export { Person } from "./Person"; -export { Changeset, Contributor, ParentChangeset } from "./Changesets"; +export { Changeset, Contributor, ParentChangeset, Signature } from "./Changesets"; export { AnnotatedSource, AnnotatedLine } from "./Annotate"; diff --git a/scm-ui/ui-webapp/public/locales/de/repos.json b/scm-ui/ui-webapp/public/locales/de/repos.json index 71eb6a9f98..6d34e782c6 100644 --- a/scm-ui/ui-webapp/public/locales/de/repos.json +++ b/scm-ui/ui-webapp/public/locales/de/repos.json @@ -92,6 +92,7 @@ "signatureStatus": "Status", "keyId": "Schlüssel-ID", "keyContacts": "Kontakte", + "noOwner": "Unbekannt", "signatureVerified": "Verifiziert", "signatureNotVerified": "Nicht verifiziert", "signatureInvalid": "Ungültig", diff --git a/scm-ui/ui-webapp/public/locales/en/repos.json b/scm-ui/ui-webapp/public/locales/en/repos.json index a53146bc78..63c14a73db 100644 --- a/scm-ui/ui-webapp/public/locales/en/repos.json +++ b/scm-ui/ui-webapp/public/locales/en/repos.json @@ -90,6 +90,7 @@ "signedBy": "Signed by", "keyId": "Key ID", "keyContacts": "Contacts", + "noOwner": "Unknown", "signatureStatus": "Status", "signatureVerified": "verified", "signatureNotVerified": "not verified", diff --git a/scm-ui/ui-webapp/src/repos/components/changesets/SignatureIcon.tsx b/scm-ui/ui-webapp/src/repos/components/changesets/SignatureIcon.tsx index bd3b4863d8..1167b50b66 100644 --- a/scm-ui/ui-webapp/src/repos/components/changesets/SignatureIcon.tsx +++ b/scm-ui/ui-webapp/src/repos/components/changesets/SignatureIcon.tsx @@ -24,10 +24,10 @@ import React, { FC } from "react"; import { Icon, Tooltip } from "@scm-manager/ui-components"; import { useTranslation } from "react-i18next"; -//import { Signature } from "@scm-manager/ui-types"; +import { Signature } from "@scm-manager/ui-types"; type Props = { - signatures: any[]; + signatures: Signature[]; className: any; }; @@ -36,6 +36,10 @@ const SignatureIcon: FC = ({ signatures, className }) => { const signature = signatures?.length > 0 ? signatures[0] : undefined; + if (!signature) { + return null; + } + const createTooltipMessage = () => { let status; if (signature.status === "VERIFIED") { @@ -50,7 +54,7 @@ const SignatureIcon: FC = ({ signatures, className }) => { return `${t("changeset.signatureStatus")}: ${status}`; } - let message = `${t("changeset.signedBy")}: ${signature.owner}\n${t("changeset.keyId")}: ${signature.keyId}\n${t( + let message = `${t("changeset.signedBy")}: ${signature.owner ? signature.owner : t("changeset.noOwner")}\n${t("changeset.keyId")}: ${signature.keyId}\n${t( "changeset.signatureStatus" )}: ${status}`; @@ -71,9 +75,6 @@ const SignatureIcon: FC = ({ signatures, className }) => { return undefined; }; - if (!signature) { - return null; - } return ( diff --git a/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.test.ts b/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.test.ts index e2377d10b4..ddc1ba076b 100644 --- a/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.test.ts +++ b/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.test.ts @@ -23,29 +23,14 @@ */ import { formatPublicKey } from "./formatPublicKey"; -describe("format authorized key tests", () => { +describe("format public key tests", () => { it("should format the given key", () => { - const key = "ssh-rsa ACB0DEFGHIJKLMOPQRSTUVWXYZ tricia@hitchhiker.com"; - expect(formatPublicKey(key)).toEqual("ssh-rsa ... tricia@hitchhiker.com"); + const key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nA1B2C3D4E5F6HDJSURNSKFHSNEKFHK443MKD\n-----END PGP PUBLIC KEY BLOCK-----"; + expect(formatPublicKey(key)).toEqual("A1B2C3D4E5F6HDJ"); }); - it("should use the first chars of the key without prefix", () => { - const key = "ACB0DEFGHIJKLMOPQRSTUVWXYZ tricia@hitchhiker.com"; - expect(formatPublicKey(key)).toEqual("ACB0DEF... tricia@hitchhiker.com"); - }); - - it("should use the last chars of the key without suffix", () => { - const key = "ssh-rsa ACB0DEFGHIJKLMOPQRSTUVWXYZ"; - expect(formatPublicKey(key)).toEqual("ssh-rsa ...TUVWXYZ"); - }); - - it("should use a few chars from the beginning and a few from the end, if the key has no prefix and suffix", () => { - const key = "ACB0DEFGHIJKLMOPQRSTUVWXYZ0123456789"; - expect(formatPublicKey(key)).toEqual("ACB0DEF...3456789"); - }); - - it("should return the whole string for a short key", () => { - const key = "ABCDE"; - expect(formatPublicKey(key)).toEqual("ABCDE"); + it("should format bad formatted key", () => { + const key = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n\nA1B2C3D4E5F6HDJSURNSKFHSNEKFHK443MKD\n\n\n-----END PGP PUBLIC KEY BLOCK-----"; + expect(formatPublicKey(key)).toEqual("-----BEGIN PGP "); }); }); diff --git a/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.ts b/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.ts index af17e1b362..322ebb88e8 100644 --- a/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.ts +++ b/scm-ui/ui-webapp/src/users/components/publicKeys/formatPublicKey.ts @@ -24,5 +24,8 @@ export const formatPublicKey = (key: string) => { const parts = key.split(/\n/); - return parts[2].substring(0, 15); + if (parts[2].length >= 15) { + return parts[2].substring(0, 15); + } + return parts[0].substring(0, 15); };