Logo validation automation tool
This commit is contained in:
Родитель
e4c9f29f41
Коммит
e49a82d258
|
@ -0,0 +1,12 @@
|
|||
jobs:
|
||||
- job: "logoValidator"
|
||||
pool:
|
||||
vmImage: "Ubuntu 16.04"
|
||||
steps:
|
||||
- task: Npm@1
|
||||
displayName: "npm install"
|
||||
inputs:
|
||||
verbose: false
|
||||
command: "install"
|
||||
- script: "npm run tsc && node .script/logoValidator.js"
|
||||
displayName: "logo Validator"
|
|
@ -0,0 +1,37 @@
|
|||
import fs from "fs";
|
||||
import { xml2js } from 'xml-js';
|
||||
import { runCheckOverChangedFiles } from "./utils/changedFilesValidator";
|
||||
import { ExitCode } from "./utils/exitCode";
|
||||
import * as logger from "./utils/logger";
|
||||
import { isValidLogoImage } from "./utils/LogoChecker/logoImageChecker";
|
||||
import { isValidLogoImageSVGContent } from "./utils/LogoChecker/logoImageSVGChecker";
|
||||
export async function IsValidLogo(FileName: string): Promise<ExitCode> {
|
||||
|
||||
isValidLogoImage(FileName);
|
||||
const svgContent: string = fs.readFileSync(FileName, { encoding: "utf8", flag: "r" });
|
||||
console.log(svgContent)
|
||||
const object:Response = xml2js(svgContent) as Response;
|
||||
console.log(object)
|
||||
if(svgContent != "undefined")
|
||||
{
|
||||
isValidLogoImageSVGContent(svgContent)
|
||||
}
|
||||
return ExitCode.SUCCESS;
|
||||
}
|
||||
let fileTypeSuffixes = ["*.svg"];
|
||||
let filePathFolderPrefixes = ["logo"];
|
||||
|
||||
let fileKinds = ["Modified"];
|
||||
let CheckOptions = {
|
||||
onCheckFile: (filePath: string) => {
|
||||
return IsValidLogo(filePath);
|
||||
},
|
||||
onExecError: async (e: any, filePath: string) => {
|
||||
console.log(`Logo Validation Failed. File path: ${filePath}. Error message: ${e.message}`);
|
||||
},
|
||||
onFinalFailed: async () => {
|
||||
logger.logError("An error occurred, please open an issue");
|
||||
},
|
||||
};
|
||||
|
||||
runCheckOverChangedFiles(CheckOptions, fileKinds, fileTypeSuffixes, filePathFolderPrefixes);
|
|
@ -0,0 +1,43 @@
|
|||
import chai, { expect } from "chai";
|
||||
import chaiAsPromised from "chai-as-promised";
|
||||
import { IsValidLogo } from "../../logoValidator";
|
||||
import { ExitCode } from "../../utils/exitCode";
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
|
||||
describe("logoValidator", () => {
|
||||
|
||||
|
||||
it("Should not throw an exception", async () => {
|
||||
await checkValid(".script/tests/logoValidatorTest/testFiles/Morphisec_Logo.svg");
|
||||
});
|
||||
|
||||
it("Should throw an exception", async () => {
|
||||
await checkInvalid(".script/tests/logoValidatorTest/testFiles/ForgeRock_Logo_Vert_75x75.png","logoValidationError");
|
||||
});
|
||||
it("Should throw an exception", async () => {
|
||||
await checkInvalid(".script/tests/logoValidatorTest/testFiles/Filewithstyletag.svg","logoValidationError");
|
||||
});
|
||||
it("Should throw an exception", async () => {
|
||||
await checkInvalid(".script/tests/logoValidatorTest/testFiles/FileWithPNGEmbed.svg","logoValidationError");
|
||||
});
|
||||
it("Should throw an exception", async () => {
|
||||
await checkInvalid(".script/tests/logoValidatorTest/testFiles/filewithxmlnsxlink.svg","logoValidationError");
|
||||
});
|
||||
it("Should throw an exception", async () => {
|
||||
await checkInvalid(".script/tests/logoValidatorTest/testFiles/fileWithxmlnsHERF.svg","logoValidationError");
|
||||
});
|
||||
|
||||
it("Should throw an exception", async () => {
|
||||
await checkValid(".script/tests/logoValidatorTest/testFiles/filewithoutpngembed.svg");
|
||||
});
|
||||
|
||||
async function checkValid(filePath: string): Promise<Chai.PromisedAssertion> {
|
||||
let result = await IsValidLogo(filePath);
|
||||
expect(result).to.equal(ExitCode.SUCCESS);
|
||||
}
|
||||
|
||||
async function checkInvalid(filePath: string, expectedError: string): Promise<Chai.PromisedAssertion> {
|
||||
expect(IsValidLogo(filePath)).eventually.rejectedWith(Error).and.have.property("name", expectedError);
|
||||
}
|
||||
});
|
|
@ -0,0 +1,9 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
<rect x="10" y="10" height="130" width="500"/>
|
||||
|
||||
<image x="20" y="20" width="300" height="80"
|
||||
href="http://jenkov.com/images/layout/top-bar-logo.png" />
|
||||
|
||||
<line x1="25" y1="80" x2="350" y2="80"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 253 B |
|
@ -0,0 +1,10 @@
|
|||
<svg id="f8a78c88-c469-46fa-be85-47fa820f7cd7" xmlns="http://www.w3.org/2000/svg" version="1.1" width="72" height="72" viewBox="0 0 72 72">
|
||||
<g transform="matrix(1 0 0 1 36 36)" id="19f4aaee-5eb3-4c1f-9e26-d0cb2044cec3" >
|
||||
<rect style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" x="-36" y="-36" rx="0" ry="0" width="72" height="72" />
|
||||
</g>
|
||||
<g transform="matrix(Infinity NaN NaN Infinity 0 0)" id="b226becf-48f1-4d51-a4cf-3f1602cdec2a" >
|
||||
</g>
|
||||
<g transform="matrix(0.3 0 0 0.3 36 36)" id="5d556b7b-c4c5-4a9b-8698-63fb777ca329" >
|
||||
<path style="stroke: rgb(0,0,0); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-80.88, -84.86)" d="M 57.34 30.24 L 33.650000000000006 38.239999999999995 L 33.650000000000006 115.64999999999999 L 45.49000000000001 139.47 L 128.1 139.47 L 128.1 43.36 L 128.1 43.36 Z M 114.46000000000001 126.24 L 57.59 126.24 L 57.34 58.019999999999996 L 104.34 67.66 L 104.34 116.59 L 59.84 116.59 L 59.84 124 L 112.21000000000001 124 L 112.21000000000001 123.91 L 106.61000000000001 117.84 L 106.61000000000001 65.84 L 43.06000000000002 52.84 L 43.06000000000002 128.42000000000002 L 36.15000000000002 115.24000000000001 L 36.15000000000002 41.12 L 114.15000000000002 57.48 L 114.45000000000002 126.16 L 114.45000000000002 126.16 Z" stroke-linecap="round" />
|
||||
</g>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 1.6 KiB |
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
<svg id="f8a78c88-c469-46fa-be85-47fa820f7cd7" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 150 150">
|
||||
<path d="M57.34,30.24l-23.69,8v77.41l11.84,23.82H128.1V43.36h0Zm57.12,96H57.59l-.25-68.22,47,9.64v48.93H59.84V124h52.37v-.09l-5.6-6.07v-52l-63.55-13v75.58l-6.91-13.18V41.12l78,16.36.3,68.68,0,0Z"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 310 B |
|
@ -0,0 +1,9 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
<rect x="10" y="10" height="130" width="500"/>
|
||||
|
||||
<image x="20" y="20" width="300" height="80"
|
||||
xlink:href="http://jenkov.com/images/layout/top-bar-logo.jpeg" />
|
||||
|
||||
<line x1="25" y1="80" x2="350" y2="80"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 260 B |
|
@ -0,0 +1,9 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
<rect x="10" y="10" height="130" width="500"/>
|
||||
|
||||
<image x="20" y="20" width="300" height="80"
|
||||
href="http://jenkov.com/images/layout/top-bar-logo.jpeg" />
|
||||
|
||||
<line x1="25" y1="80" x2="350" y2="80"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 254 B |
|
@ -0,0 +1,9 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<rect x="10" y="10" height="130" width="500"/>
|
||||
|
||||
<image x="20" y="20" width="300" height="80"
|
||||
href="http://jenkov.com/images/layout/top-bar-logo.jpeg" />
|
||||
|
||||
<line x1="25" y1="80" x2="350" y2="80"/>
|
||||
</svg>
|
После Ширина: | Высота: | Размер: 297 B |
|
@ -0,0 +1,12 @@
|
|||
import { LogoValidationError } from "../validationError";
|
||||
|
||||
function isLogoSVG(LogoImagesFileNames: string) {
|
||||
return LogoImagesFileNames.toLowerCase().endsWith('.svg');
|
||||
}
|
||||
|
||||
export function isValidLogoImage(LogoImagesPath: string) {
|
||||
if (!isLogoSVG(LogoImagesPath)) {
|
||||
throw new LogoValidationError(`Logo must be svg files`);
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
import { LogoValidationError } from "../validationError";
|
||||
|
||||
function isLogoSVGHasStyleTag(LogoImagesContent: string) {
|
||||
return LogoImagesContent.includes("style=");
|
||||
}
|
||||
function isLogoSVGHasxmlnsxlink(LogoImagesContent: string) {
|
||||
return LogoImagesContent.includes("xmlns:xlink");
|
||||
}
|
||||
function isLogoSVGHasdataname(LogoImagesContent: string) {
|
||||
return LogoImagesContent.includes("data-name");
|
||||
}
|
||||
function isLogoSVGHasxlinkhref(LogoImagesContent: string) {
|
||||
return LogoImagesContent.includes("xlink:href");
|
||||
}
|
||||
function isLogoSVGHasTitleTag(LogoImagesContent: string) {
|
||||
return LogoImagesContent.includes("<title>");
|
||||
}
|
||||
function isLogoSVGHasPNGEmbed(LogoImagesContent: string) {
|
||||
if(LogoImagesContent.includes("<image"))
|
||||
{
|
||||
return LogoImagesContent.includes(".png");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isValid(str: string): boolean {
|
||||
const validRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
return validRegex.test(str);
|
||||
}
|
||||
|
||||
function isLogoSVGHasValidId(LogoImagesContent: string)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
export function isValidLogoImageSVGContent(LogoImagesContent: string) {
|
||||
if (isLogoSVGHasStyleTag(LogoImagesContent)) {
|
||||
throw new LogoValidationError(`Ensure raw file of logo does not have any style formats`);
|
||||
}
|
||||
if (isLogoSVGHasxmlnsxlink(LogoImagesContent)) {
|
||||
throw new LogoValidationError(`Ensure raw file of logo does not have any xmlns:xlink`);
|
||||
}
|
||||
if (isLogoSVGHasdataname(LogoImagesContent)) {
|
||||
throw new LogoValidationError(`Ensure raw file of logo does not have any data-name`);
|
||||
}
|
||||
if (isLogoSVGHasxlinkhref(LogoImagesContent)) {
|
||||
throw new LogoValidationError(`Ensure raw file of logo does not have any xlink:href`);
|
||||
}
|
||||
if (isLogoSVGHasTitleTag(LogoImagesContent)) {
|
||||
throw new LogoValidationError(`Ensure raw file of logo does not have title tag`);
|
||||
}
|
||||
if (isLogoSVGHasPNGEmbed(LogoImagesContent)) {
|
||||
throw new LogoValidationError(`Ensure raw file of logo does not have embedded png formats`);
|
||||
}
|
||||
};
|
||||
|
|
@ -8,3 +8,10 @@ export class WorkbookValidationError extends Error implements ValidationError {
|
|||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export class LogoValidationError extends Error implements ValidationError {
|
||||
public name = "LogoValidationError";
|
||||
constructor(message?: string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
name: "Azure Sentinel Validations"
|
||||
|
||||
trigger:
|
||||
- master
|
||||
- master
|
||||
|
||||
jobs:
|
||||
- template: .azure-pipelines/detectionsValidations.yaml
|
||||
- template: .azure-pipelines/detectionTemplateStructureValidation.yaml
|
||||
- template: .azure-pipelines/kqlValidations.yaml
|
||||
- template: .azure-pipelines/workbooksValidations.yaml
|
||||
- template: .azure-pipelines/yamlFileValidator.yaml
|
||||
- template: .azure-pipelines/jsonFileValidator.yaml
|
||||
- template: .azure-pipelines/documentsLinkValidator.yaml
|
||||
- template: .azure-pipelines/detectionsValidations.yaml
|
||||
- template: .azure-pipelines/detectionTemplateStructureValidation.yaml
|
||||
- template: .azure-pipelines/kqlValidations.yaml
|
||||
- template: .azure-pipelines/workbooksValidations.yaml
|
||||
- template: .azure-pipelines/yamlFileValidator.yaml
|
||||
- template: .azure-pipelines/jsonFileValidator.yaml
|
||||
- template: .azure-pipelines/documentsLinkValidator.yaml
|
||||
- template: .azure-pipelines/logoValidator.yaml
|
||||
|
|
Загрузка…
Ссылка в новой задаче