Skip to content

Commit

Permalink
Fix subsequent calls to sslChecker, fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere authored and dyaa committed Nov 4, 2020
1 parent 26f2f32 commit c730d7a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ const getSslDetails = async (hostname: string) =>

## Options

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

| Option | Default | Description |
| ------------------ | ------- | -------------------------------------------------- |
| method | HEAD | Can be GET too |
| port | 443 | Your SSL/TLS entry point |
| agent | default | Default HTTPS agent with { maxCachedSessions: 0 } |
| rejectUnauthorized | false | Skips authorization by default |

```ts
sslChecker("dyaa.me", { method: "GET", port: 443 }).then(console.info);
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ describe("sslChecker", () => {
);
});

it("Should work on subsequent calls for the same domain", async () => {
await sslChecker(validSslHost);
await new Promise((r) => setTimeout(r, 1000));
const sslDetails = await sslChecker(validSslHost);

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

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

Expand Down
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@ const getDaysRemaining = (validFrom: Date, validTo: Date): number => {
return daysRemaining;
};

const DEFAULT_OPTIONS: Partial<https.RequestOptions> = {
agent: new https.Agent({
maxCachedSessions: 0
}),
method: "HEAD",
port: 443,
rejectUnauthorized: false,
};

const sslChecker = (
host: string,
options: Partial<https.RequestOptions> = {
agent: false,
method: "HEAD",
port: 443,
rejectUnauthorized: false,
}
options: Partial<https.RequestOptions> = {}
): Promise<IResolvedValues> =>
new Promise((resolve, reject) => {
options = Object.assign({}, DEFAULT_OPTIONS, options);

if (!checkPort(options.port)) {
reject(Error("Invalid port"));
return;
}

try {
Expand Down

0 comments on commit c730d7a

Please sign in to comment.