Skip to content

Commit

Permalink
Add SSL test
Browse files Browse the repository at this point in the history
  • Loading branch information
juffalow committed Oct 28, 2021
1 parent 42a42e3 commit be444cb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"htmlparser2": "^7.1.2",
"lint": "^0.7.0",
"node-fetch": "^2.6.0",
"ssl-checker": "^2.0.7",
"uglify-js": "^3.6.1",
"xml2js": "^0.4.22"
},
Expand Down
37 changes: 37 additions & 0 deletions src/security/SSL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sslChecker from 'ssl-checker';
import Test, { TestParameters, Result } from '../Test';
import logger from '../logger';

class SSL extends Test {
public name = 'SSL';

public async test({ url }: TestParameters): Promise<Result> {
logger.info('Starting SSL test...');
const hostname = (new URL(url)).hostname;
const sslDetails = await sslChecker(hostname);

if (!sslDetails.valid) {
return {
status: 'ERROR',
title: this.name,
description: 'SSL certificate is not valid!',
};
}

if (sslDetails.daysRemaining <= 7) {
return {
status: 'WARNING',
title: this.name,
description: 'SSL certificate is valid for 7 or less days!',
};
}

return {
status: 'SUCCESS',
title: this.name,
description: `SSL certificate is valid until ${sslDetails.validTo}.`,
};
}
}

export default SSL;
2 changes: 2 additions & 0 deletions src/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cookies from './Cookies';
import ReferrerPolicy from './ReferrerPolicy';
import RobotsTXT from './RobotsTXT';
import PermissionsPolicy from './PermissionsPolicy';
import SSL from './SSL';

export default class Security extends Test {
public name = 'Security';
Expand All @@ -30,6 +31,7 @@ export default class Security extends Test {
new HTTPVersion(),
new ContentEncoding(),
new RobotsTXT(),
new SSL(),
];
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3338,6 +3338,11 @@ sshpk@^1.7.0:
safer-buffer "^2.0.2"
tweetnacl "~0.14.0"

ssl-checker@^2.0.7:
version "2.0.7"
resolved "https://registry.yarnpkg.com/ssl-checker/-/ssl-checker-2.0.7.tgz#031feef44a0b53bd22a29bdad0687f69fb262e9a"
integrity sha512-/fc379/SD4Ov5zWM2heUAZIHTijW45tD33BPCXU+FLhP4TGD8LHm5HbMYqvy/Hwzxv3RmXXqxC8ahlv0rKv0MA==

stack-utils@^2.0.3:
version "2.0.5"
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.5.tgz#d25265fca995154659dbbfba3b49254778d2fdd5"
Expand Down

0 comments on commit be444cb

Please sign in to comment.