Commit 81f985f5 authored by Aral Balkan's avatar Aral Balkan

You can now pass a custom directory to store nodecert certificates

parent d67499e1
......@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Nothing yet.
## [3.1.1] - 2019-11-25
### Added
- Function now takes node certificate directory as its only parameter. Defaults to old default directory.
## [3.1.0] - 2019-09-28
### Changed
......
......@@ -48,6 +48,20 @@ Locally-trusted certificates do not work under Firefox. Please use Edge or Chrom
require('@ind.ie/nodecert')()
```
__As of version 3.1.1,__ you can now pass a custom directory for nodecert to use instead of the default (`~/.nodecert`) and the created certificates will be stored there.
For example:
```js
const os = require('os)
const path = require('path')
const nodecert = require('@ind.ie/nodecert')
const customDirectory = path.join(os.homedir(), '.my-app', 'tls', 'local')
nodecert(customDirectory)
```
## Help wanted
* Linux: _certutil_ (nss) auto-installation has not been tested with yum.
......
......@@ -7,11 +7,15 @@ const _platform = os.platform()
const _architecture = os.arch()
const homeDir = os.homedir()
const nodecertDir = path.join(homeDir, '.nodecert')
const syswidecas = require('syswide-cas')
module.exports = function () {
let nodecertDir
module.exports = function (_nodecertDir = path.join(homeDir, '.nodecert')) {
nodecertDir = _nodecertDir
// Create certificates.
if (!allOK()) {
......
{
"name": "@ind.ie/nodecert",
"version": "3.1.0",
"version": "3.1.1",
"description": "Automatically provision and use locally-trusted TLS certificates in Node.js using mkcert.",
"main": "index.js",
"bin": "bin/nodecert.js",
......
......@@ -20,9 +20,9 @@ function rmRFSync (dirPath) {
}
test('certificate creation', t => {
t.plan(5)
t.plan(10)
const nodecertDirectory = path.join(os.homedir(), '.nodecert')
let nodecertDirectory = path.join(os.homedir(), '.nodecert')
if (fs.existsSync(nodecertDirectory)) {
// Clear the .nodecert directory if it already exists.
rmRFSync(nodecertDirectory)
......@@ -37,5 +37,13 @@ test('certificate creation', t => {
t.ok(fs.existsSync(path.join(nodecertDirectory, 'localhost.pem')), 'Local certificate exists')
t.ok(fs.existsSync(path.join(nodecertDirectory, 'localhost-key.pem')), 'Local certificate private key exists')
nodecert(path.join(os.homedir(), '.nodecert-test'))
t.ok(fs.existsSync(path.join(nodecertDirectory)), '(Custom path) Main nodecert directory exists')
t.ok(fs.existsSync(path.join(nodecertDirectory, 'rootCA.pem')), '(Custom path) Local certificate authority exists')
t.ok(fs.existsSync(path.join(nodecertDirectory, 'rootCA-key.pem')), '(Custom path) Local certificate authority private key exists')
t.ok(fs.existsSync(path.join(nodecertDirectory, 'localhost.pem')), '(Custom path) Local certificate exists')
t.ok(fs.existsSync(path.join(nodecertDirectory, 'localhost-key.pem')), '(Custom path) Local certificate private key exists')
t.end()
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment