Skip to content

Commit

Permalink
Merge pull request #1883 from blockchain-certificates/feat/show-expir…
Browse files Browse the repository at this point in the history
…ation-date

feat(Expiration): show expiration date in error message
  • Loading branch information
lemoustachiste authored Oct 17, 2024
2 parents c91cc2e + 53f2810 commit 03a1846
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
36 changes: 30 additions & 6 deletions src/data/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"couldNotConfirmTx": "Could not confirm the transaction",
"ensureHashesEqual": "Computed hash does not match remote hash",
"ensureMerkleRootEqual": "Merkle root does not match remote hash.",
"ensureNotExpired": "This certificate has expired.",
"ensureNotExpired": "This certificate has expired on ",
"ensureValidReceipt": "The receipt is malformed. There was a problem navigating the merkle tree in the receipt.",
"failedJsonLdNormalization": "Failed JSON-LD normalization",
"foundUnmappedFields": "Found unmapped fields during JSON-LD normalization",
Expand All @@ -111,6 +111,10 @@
"checkImagesIntegrity": "Image integrity verification proved that the content was modified after issuance.",
"ensureValidityPeriodStarted": "This certificate is not yet valid.",
"validateDateFormat":"The date format specified does not conform with the spec requirements (RFC3339). Property:"
},
"date": {
"months": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"],
"pattern": "MM DD, YYYY"
}
},
"fr": {
Expand Down Expand Up @@ -168,7 +172,7 @@
},
"revocation": {
"preReason": "Raison :",
"reason": "Ce certificat a été ${CREDENTIAL_STATUS} par l'émetteur.",
"reason": "Ce certificat a été ${CREDENTIAL_STATUS} par l'émetteur le ",
"revocationListAuthenticityFailure": "L'authenticité de la liste de revocation n'a pas pu être validée.",
"noRevocationStatusList2021Found": "Aucune liste de revocation n'a pu être trouvée à l'URL spécifiée par 'statusListCredential':",
"revoked": "révoqué",
Expand Down Expand Up @@ -225,6 +229,10 @@
"checkImagesIntegrity": "La vérification des images a prouvé que le contenu a été modifié après l'émission.",
"ensureValidityPeriodStarted": "Ce certificat n'est pas encore valide.",
"validateDateFormat": "Le format de date spécifié n'est pas conforme aux exigences de la spécification (RFC3339). Propriété :"
},
"date": {
"months": ["Jan", "Fév", "Mar", "Avr", "Mai", "Juin", "Juil", "Aout", "Sept", "Oct", "Nov", "Déc"],
"pattern": "DD MM YYYY"
}
},
"es": {
Expand Down Expand Up @@ -313,7 +321,7 @@
"couldNotConfirmTx": "No se ha podido confirmar la transacción",
"ensureHashesEqual": "La cadena binaria calculada no corresponde con la cadena binaria remota",
"ensureMerkleRootEqual": "La raíz Merkle no corresponde con la cadena binaria remota",
"ensureNotExpired": "Este certificado ha expirado",
"ensureNotExpired": "Este certificado ha expirado el ",
"ensureValidReceipt": "El recibo está malformado. Hubo un problema navegando el árbol Merkle en el recibo",
"failedJsonLdNormalization": "La normalización del JSON-LD ha fallado",
"foundUnmappedFields": "Se han encontrado campos no mapeados durante la normalización de JSON-LD",
Expand All @@ -339,6 +347,10 @@
"checkImagesIntegrity": "La verificación de la integridad de los imagens provó alteración del contenido después de la emisión.",
"ensureValidityPeriodStarted": "Este certificado aún no está valido.",
"validateDateFormat": "El formato de fecha especificado no cumple con los requisitos de la especificación (RFC3339). Propiedad:"
},
"date": {
"months": ["enero", "feb", "marzo", "abr", "mayo", "jun", "jul", "agosto", "set", "oct", "nov", "dic"],
"pattern": "MM DD, YYYY"
}
},
"mt": {
Expand Down Expand Up @@ -427,7 +439,7 @@
"couldNotConfirmTx": "Ma setgħetx tiġi kkonfermata t-tranżazzjoni",
"ensureHashesEqual": "Il-hash ikkalkulat ma jikkorrispondix mar-remote hash",
"ensureMerkleRootEqual": "Merkle root ma taqbilx mar-remote hash",
"ensureNotExpired": "Dan iċ-ċertifikat skada",
"ensureNotExpired": "Dan iċ-ċertifikat skada fid-data - ",
"ensureValidReceipt": "L-irċevuta hija malformata. Kien hemm problema fin-navigazzjoni tal-merkle tree fl-irċevuta",
"failedJsonLdNormalization": "In-normalizzazzjoni ta' JSON-LD ma rnexxietx",
"foundUnmappedFields": "Instabu unmapped fields matul in-normalizzazzjoni JSON-LD",
Expand All @@ -453,6 +465,10 @@
"checkImagesIntegrity": "Image integrity verification proved that the content was modified after issuance.",
"ensureValidityPeriodStarted": "This certificate is not yet valid.",
"validateDateFormat": "The date format specified does not conform with the spec requirements (RFC3339). Property:"
},
"date": {
"months": ["Jannar", "Frar", "Marzu", "April", "Mejju", "Ġunju", "Lulju", "Awwissu", "Settembru", "Ottubru", "Novembru", "Diċembru"],
"pattern": "DD MM YYYY"
}
},
"it-IT": {
Expand Down Expand Up @@ -541,7 +557,7 @@
"couldNotConfirmTx": "Impossibile confermare la transazione",
"ensureHashesEqual": "L'hash calcolato non corrisponde all'hash remoto",
"ensureMerkleRootEqual": "La radice di Merkle non corrisponde all'hash remoto.",
"ensureNotExpired": "Questo certificato è scaduto.",
"ensureNotExpired": "Questo certificato è scaduto il ",
"ensureValidReceipt": "La ricevuta è malformata. C'è stato un problema nella navigazione dell'albero di Merkle nella ricevuta.",
"failedJsonLdNormalization": "Normalizzazione JSON-LD fallita",
"foundUnmappedFields": "Campi non mappati trovati durante la normalizzazione JSON-LD",
Expand All @@ -567,6 +583,10 @@
"checkImagesIntegrity": "Image integrity verification proved that the content was modified after issuance.",
"ensureValidityPeriodStarted": "This certificate is not yet valid.",
"validateDateFormat": "The date format specified does not conform with the spec requirements (RFC3339). Property:"
},
"date": {
"months": ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"],
"pattern": "DD MM YYYY"
}
},
"ja": {
Expand Down Expand Up @@ -655,7 +675,7 @@
"couldNotConfirmTx": "取引を確認できませんでした",
"ensureHashesEqual": "算出されたハッシュがリモートハッシュと一致しませんでした",
"ensureMerkleRootEqual": "Merkle rootがリモートハッシュと一致しませんでした",
"ensureNotExpired": "この証明書の有効期限が切れています",
"ensureNotExpired": "この証明書の有効期限が切れています ",
"ensureValidReceipt": "レシートに異常があります。レシート内のMerkle treeを辿る際に問題が発生しました。",
"failedJsonLdNormalization": "JSON-LDの正規化に失敗しました",
"foundUnmappedFields": "JSON-LDの正規化時にマップされていないフィールドを検出しました",
Expand All @@ -681,6 +701,10 @@
"checkImagesIntegrity": "データが発行後に変更されたことが画像保全性の検証によって証明されました。",
"ensureValidityPeriodStarted": "This certificate is not yet valid.",
"validateDateFormat": "The date format specified does not conform with the spec requirements (RFC3339). Property:"
},
"date": {
"months": ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
"pattern": "YYYY年-MM-DD日"
}
}
}
29 changes: 29 additions & 0 deletions src/domain/i18n/useCases/getDateFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import getText from './getText';

function replaceMonth (pattern: string, monthIndex: number): string {
const months = getText('date', 'months');
return pattern.replace('MM', months[monthIndex]);
}

function replaceDay (pattern: string, day: string): string {
return pattern.replace('DD', day);
}

function replaceYear (pattern: string, year: string): string {
return pattern.replace('YYYY', year);
}

export default function getDateFormat (date: string): string {
const pattern = getText('date', 'pattern');
if (date.slice(-1) === 'Z') {
date = date.slice(0, date.length - 1);
} else if (date.includes('+')) {
date = date.split('+')[0];
}
const objDate = new Date(date);

let formattedDate = replaceMonth(pattern, objDate.getMonth());
formattedDate = replaceDay(formattedDate, objDate.getDate().toString(10));
formattedDate = replaceYear(formattedDate, objDate.getFullYear().toString(10));
return formattedDate;
}
4 changes: 3 additions & 1 deletion src/domain/i18n/useCases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import ensureIsSupported from './ensureIsSupported';
import getComposedText from './getComposedText';
import getText from './getText';
import getSupportedLanguages from './getSupportedLanguages';
import getDateFormat from './getDateFormat';

export {
detectLocale,
ensureIsSupported,
getComposedText,
getText,
getSupportedLanguages
getSupportedLanguages,
getDateFormat
};
3 changes: 2 additions & 1 deletion src/inspectors/ensureNotExpired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { dateToUnixTimestamp } from '../helpers/date';
import VerifierError from '../models/verifierError';
import { SUB_STEPS } from '../domain/verifier/entities/verificationSteps';
import { getText } from '../domain/i18n/useCases';
import domain from '../domain';

export default function ensureNotExpired (expires = null): void {
if (!expires) {
Expand All @@ -12,7 +13,7 @@ export default function ensureNotExpired (expires = null): void {
if (today.getTime() >= expiryDate) {
throw new VerifierError(
SUB_STEPS.checkExpiresDate,
getText('errors', 'ensureNotExpired')
`${getText('errors', 'ensureNotExpired')}${domain.i18n.getDateFormat(expires)}`
);
}
}
2 changes: 1 addition & 1 deletion test/application/inspectors/ensureNotExpired.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ensureNotExpired } from '../../../src/inspectors';

describe('Inspectors test suite', function () {
describe('ensureNotExpired method', function () {
const errorMessage = 'This certificate has expired.';
const errorMessage = 'This certificate has expired on Jan 1, 2017';

describe('given it is called with no parameter', function () {
it('should not throw an error', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/verifier/mocknet-vc-v2-validUntil-invalid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ describe('given the certificate is an expired validUntil', function () {
});

it('should set the expected error message', function () {
expect(result.message).toBe('This certificate has expired.');
expect(result.message).toBe('This certificate has expired on Jan 5, 2024');
});
});

0 comments on commit 03a1846

Please sign in to comment.