Skip to content
Snippets Groups Projects
Commit 429acbff authored by Igor Markin's avatar Igor Markin
Browse files

Merge branch...

Merge branch 'lib-seal-2-upgrade-dependents-with-vereign-lib-seal-and-get-rid-of-legacy-code' into 'master'

[Lib Seal introduction] Get rid of SealService

See merge request !78
parents 7bfe671f 9022416e
No related branches found
No related tags found
1 merge request!78[Lib Seal introduction] Get rid of SealService
Pipeline #43482 passed
Showing
with 6 additions and 20244 deletions
...@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. ...@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [2.0.0] - 2021-06-15
### Removed
- `SealService`
## [1.0.2] - 2021-06-07 ## [1.0.2] - 2021-06-07
### Added ### Added
......
import { describe, it, expect } from "@jest/globals";
import { JSDOM } from "jsdom";
import SealService from "../../src/services/SealService";
import * as path from "path";
import * as fs from "fs";
import SealReadingError from "../../src/services/SealService/SealReadingError";
const readFiles = (path: string): Array<string> => {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + "/" + file).isFile();
});
};
const parseHTML = (htmlString: string): HTMLDocument => {
// TODO: test with JSDOM
const {
window: { document },
} = new JSDOM(htmlString);
return document;
};
describe("SealService tests", () => {
it("tests #getSealTemplate()", () => {
const sealUrl = "https://seal.vereign.com#seal-head-1";
const sealId = "sealId";
const sealTemplate = SealService.getSealTemplate(sealId, sealUrl);
const document = parseHTML(sealTemplate);
expect(document.body.innerHTML).toEqual(
'<a id="seal-container-v1-sealId" href="https://seal.vereign.com#seal-head-1" target="_blank" rel="noopener noreferrer"><img id="seal-image-sealId" alt="Vereign Seal" src="<src-placeholder>"></a>'
);
});
it("tests #createSealUrl()", () => {
const sealHeadBytes =
"3DCiDc+0q/4cTggpgT7mw6x161f5073PhITsfDwqoLHwNWAhIg98ZVg/TYXMlGiHtAHBHeS5hv0cZIAG9Mi/H6ZE6eHak=&t=1614589293115";
const baseUrl = "https://seal.vereign.com";
const sealUrl = SealService.createSealUrl(baseUrl, sealHeadBytes);
expect(SealService.getSealHead(sealUrl)).toEqual(sealHeadBytes);
});
describe("#extractSeal()", () => {
describe("Test sealed emails", () => {
const emailsDir = path.resolve(__dirname, "eml/sealed");
// TODO: regenerate sealed test cases
const files = readFiles(emailsDir);
it.concurrent.each(files)("Case %s", async (dirName) => {
const mime = fs.readFileSync(`${emailsDir}/${dirName}`).toString();
const {
sealUrl,
sealId,
publicKey,
} = await SealService.extractSealFromMime(mime, parseHTML);
expect(sealUrl).toBeTruthy();
expect(sealId).toBeTruthy();
expect(publicKey).toBeTruthy();
});
});
describe("Test unsealed emails", () => {
const emailsDir = path.resolve(__dirname, "eml/unsealed");
const files = readFiles(emailsDir);
it.concurrent.each(files)("Case %s", async (dirName) => {
const mime = fs.readFileSync(`${emailsDir}/${dirName}`).toString();
try {
await SealService.extractSealFromMime(mime, parseHTML);
} catch (e) {
expect(e instanceof SealReadingError).toBeTruthy();
expect(e.type).toEqual(SealReadingError.MESSAGE_NOT_SEALED);
}
});
});
});
});
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment