Skip to content

Commit

Permalink
impr: Rewrite in typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
dyaa committed Oct 4, 2019
1 parent 442c779 commit c7009e1
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 169 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

13 changes: 0 additions & 13 deletions .editorconfig

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc.json

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: test-sslChecker

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- name: Use yarn
uses: nuxt/actions-yarn@master
- name: yarn install, test and build
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: |
yarn install
yarn test:coverage
yarn build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ coverage
node_modules
npm-debug.log
yarn.lock
lib
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Dyaa Eldin Moustafa
Copyright (c) 8008 :trollface: Dyaa Eldin Moustafa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# Node SSL Checker

[![wercker status](https://app.wercker.com/status/d9c8e99c45ac59552e86375ac942697b/s/master "wercker status")](https://app.wercker.com/project/byKey/d9c8e99c45ac59552e86375ac942697b) [![npm version](https://badge.fury.io/js/ssl-checker.svg)](https://badge.fury.io/js/ssl-checker) [![npm](https://img.shields.io/npm/dt/ssl-checker.svg)](https://github.com/dyaa/node-ssl-checker)
[![Build Status](https://github.com/dyaa/ssl-checker/workflows/test-sslChecker/badge.svg)](https://github.com/dyaa/ssl-checker/actions)
[![npm version](https://badge.fury.io/js/ssl-checker.svg)](https://badge.fury.io/js/ssl-checker) [![npm](https://img.shields.io/npm/dt/ssl-checker.svg)](https://github.com/dyaa/node-ssl-checker)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4544a598aa6b4bc99883ef655e1dd90f)](https://www.codacy.com/manual/dyaa/node-ssl-checker?utm_source=github.com&utm_medium=referral&utm_content=dyaa/node-ssl-checker&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/4544a598aa6b4bc99883ef655e1dd90f)](https://www.codacy.com/manual/dyaa/node-ssl-checker?utm_source=github.com&utm_medium=referral&utm_content=dyaa/node-ssl-checker&utm_campaign=Badge_Coverage)

## Installation

Simply add `ssl-checker` as a dependency:

```bash
$ npm install ssl-checker --save # npm i -s ssl-checker

# Or if you are using yarn (https://yarnpkg.com/lang/en/)
# Or if you prefer using yarn (https://yarnpkg.com/lang/en/)
$ yarn add ssl-checker
```

## Usage

```javascript
import sslChecker from 'ssl-checker';

sslChecker("github.com").then(console.log).catch(console.error);
sslChecker("github").then(console.log).catch((err) => {
if (err.code === 'ENOTFOUND') {
console.log("Please get back only or fix hostname");
} else {
console.error(err);
}
});
```ts
import sslChecker from "ssl-checker";

const getSslDetails = async (hostname: string) =>
await sslChecker(hostname`ex. badssl.com`);
```

## Options
| Option | Default | |
| ------ | -------- | ----------------------- |
| Host | Required | your host *ex. github.com* |
| Method | HEAD | can be GET too |
| Port | 443 | Your ssl port number |

```javascript
var sslChecker = require("ssl-checker")
sslChecker('dyaa.me', 'GET', 443).then(result => console.info(result));

| Option | Default | |
| ------ | ------- | -------------------------------------------------- |
| method | HEAD | can be GET too |
| port | 443 | Your ssl entrypoint |
| agent | HEAD | I dont know why but if you'd like provide agent id |
| |

```ts
sslChecker("dyaa.me", { method: "GET", port: 443 }).then(console.info);
```

## Response Example

```json
{
"valid": true,
"days_remaining" : 90,
"valid_from" : "issue date",
"valid_to" : "expiry date"
"days_remaining": 90,
"valid": true,
"valid_from": "issue date",
"valid_to": "expiry date"
}
```

#### License

Copylefted (c) 2018 [Dyaa Eldin Moustafa][1] Licensed under the [MIT license][2].

Copylefted (c) 8008 :trollface: [Dyaa Eldin Moustafa][1] Licensed under the [MIT license][2].

[1]: https://dyaa.me/
[2]: https://github.com/dyaa/node-ssl-checker/blob/master/LICENSE
[1]: https://dyaa.me/
[2]: https://github.com/dyaa/node-ssl-checker/blob/master/LICENSE
54 changes: 0 additions & 54 deletions index.js

This file was deleted.

28 changes: 28 additions & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"setupFilesAfterEnv": [
"jest-extended"
],
"transform": {
"^.+\\.ts?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/))\\.(ts)$",
"moduleFileExtensions": [
"ts",
"js",
"json",
"node"
],
"coverageReporters": [
"json",
"lcov",
"text",
"text-summary"
],
"coverageDirectory": "./coverage/",
"collectCoverage": true,
"globals": {
"ts-jest": {
"diagnostics": false
}
}
}
49 changes: 35 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
{
"name": "ssl-checker",
"version": "1.2.1",
"version": "2.0.0",
"description": "ssl-checker",
"main": "index.js",
"main": "./lib/cmjs/index.js",
"module": "./lib/cmjs/index.js",
"es2015": "./lib/es2015/index.js",
"unpkg": "./lib/umd/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --require babel-register",
"posttest": "npm run lint"
"test": "jest --config jestconfig.json",
"test:coverage": "jest --coverage --config=jestconfig.json && cat ./coverage/lcov.info | codacy-coverage -v",
"build": "yarn build:es2015 && yarn build:umd && yarn build:cmjs",
"build:es2015": "tsc --module es2015 --outDir lib/es2015",
"build:umd": "tsc --module umd --outDir lib/umd",
"build:cmjs": "tsc --module commonjs --outDir lib/cmjs",
"lint": "tslint -p tsconfig.json",
"format": "prettier --write '**/*.{ts,md}'",
"precommit": "pretty-quick --staged",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dyaa/node-ssl-checker.git"
"url": "git+https://github.com/dyaa/ssl-checker.git"
},
"keywords": [
"ssl",
Expand All @@ -19,15 +34,21 @@
"author": "Dyaa Eldin <mail@dyaa.me> (https://dyaa.me)",
"license": "MIT",
"bugs": {
"url": "https://github.com/dyaa/node-ssl-checker/issues"
"url": "https://github.com/dyaa/ssl-checker/issues"
},
"homepage": "https://github.com/dyaa/node-ssl-checker#readme",
"homepage": "https://github.com/dyaa/ssl-checker#readme",
"devDependencies": {
"babel-core": "^6.24.1",
"babel-eslint": "^10.0.2",
"babel-preset-es2015": "^6.24.1",
"chai": "^4.1.0",
"eslint": "^6.0.1",
"mocha": "^6.1.4"
"@types/jest": "^24.0.18",
"@types/node": "^12.7.11",
"codacy-coverage": "^3.4.0",
"codecov": "^3.5.0",
"jest": "^24.9.0",
"jest-extended": "^0.11.2",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.1",
"ts-jest": "^24.0.2",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.6.3"
}
}
56 changes: 56 additions & 0 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sslChecker from "../";

const validSslHost = "badssl.com";
const expiredSSlHost = "expired.badssl.com";
const wrongHostDomain = "wrong.host.badssl.com";

describe("sslChecker", () => {
it("Should return valid values when valid host is passed", async () => {
const sslDetails = await sslChecker(validSslHost);

expect(sslDetails).toEqual(
expect.objectContaining({
daysRemaining: expect.any(Number),
valid: true,
validFrom: expect.any(String),
validTo: expect.any(String)
})
);
});

it("Should return valid = false when provided an expired domain", async () => {
const sslDetails = await sslChecker(expiredSSlHost);

expect(sslDetails).toEqual(
expect.objectContaining({
valid: false
})
);
});

it("Should return an error when passing a wrong host domain", async () => {
try {
await sslChecker(wrongHostDomain);
} catch (e) {
expect(e).toContain(
"getaddrinfo ENOTFOUND expiredSSlHost expiredSSlHost:"
);
}
});

it("Should return 'Invalid host' when no host provided", async () => {
try {
await sslChecker();
} catch (e) {
expect(e).toEqual(new Error("Invalid host"));
}
});

it("Should return 'Invalid port' when no port provided", async () => {
try {
await sslChecker(validSslHost, { port: "port" });
} catch (e) {
expect(e).toEqual(new Error("Invalid port"));
}
});
});
Loading

0 comments on commit c7009e1

Please sign in to comment.