This commit is contained in:
Eduard Heimbuch
2020-07-30 09:37:43 +02:00
parent 3da7710543
commit a1153df50a
6 changed files with 20 additions and 29 deletions

View File

@@ -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";

View File

@@ -92,6 +92,7 @@
"signatureStatus": "Status",
"keyId": "Schlüssel-ID",
"keyContacts": "Kontakte",
"noOwner": "Unbekannt",
"signatureVerified": "Verifiziert",
"signatureNotVerified": "Nicht verifiziert",
"signatureInvalid": "Ungültig",

View File

@@ -90,6 +90,7 @@
"signedBy": "Signed by",
"keyId": "Key ID",
"keyContacts": "Contacts",
"noOwner": "Unknown",
"signatureStatus": "Status",
"signatureVerified": "verified",
"signatureNotVerified": "not verified",

View File

@@ -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<Props> = ({ 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<Props> = ({ 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<Props> = ({ signatures, className }) => {
return undefined;
};
if (!signature) {
return null;
}
return (
<Tooltip location="top" message={createTooltipMessage()}>

View File

@@ -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 ");
});
});

View File

@@ -24,5 +24,8 @@
export const formatPublicKey = (key: string) => {
const parts = key.split(/\n/);
if (parts[2].length >= 15) {
return parts[2].substring(0, 15);
}
return parts[0].substring(0, 15);
};