@small-tech/auto-encrypt 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/index.js +37 -34
- package/lib/Account.js +6 -4
- package/lib/AcmeRequest.js +32 -29
- package/lib/Authorisation.js +9 -7
- package/lib/Certificate.js +26 -24
- package/lib/Configuration.js +11 -16
- package/lib/Directory.js +26 -24
- package/lib/HttpServer.js +7 -5
- package/lib/Identity.js +8 -6
- package/lib/LetsEncryptServer.js +4 -2
- package/lib/Nonce.js +6 -4
- package/lib/Order.js +17 -15
- package/lib/acme-requests/AuthorisationRequest.js +5 -3
- package/lib/acme-requests/CertificateRequest.js +5 -3
- package/lib/acme-requests/CheckOrderStatusRequest.js +5 -3
- package/lib/acme-requests/FinaliseOrderRequest.js +5 -3
- package/lib/acme-requests/NewAccountRequest.js +4 -2
- package/lib/acme-requests/NewOrderRequest.js +5 -3
- package/lib/acme-requests/ReadyForChallengeValidationRequest.js +5 -3
- package/lib/acmeCsr.js +3 -3
- package/lib/identities/AccountIdentity.js +5 -3
- package/lib/identities/CertificateIdentity.js +5 -3
- package/lib/staging/fakelerootx1.pem +30 -27
- package/lib/staging/monkeyPatchTls.js +6 -6
- package/lib/test-helpers/index.js +39 -31
- package/lib/util/Pluralise.js +3 -1
- package/lib/util/Throws.js +7 -3
- package/lib/util/async-foreach.js +3 -1
- package/lib/util/log.js +3 -1
- package/lib/util/waitFor.js +3 -1
- package/lib/x.509/rfc5280.js +171 -84
- package/package.json +20 -21
- package/typedefs/lib/AcmeRequest.js +1 -1
- package/CHANGELOG +0 -99
package/lib/HttpServer.js
CHANGED
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
//
|
|
26
26
|
////////////////////////////////////////////////////////////////////////////////
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const http = require('http')
|
|
29
|
+
const encodeUrl = require('encodeurl')
|
|
30
|
+
const enableDestroy = require('server-destroy')
|
|
31
|
+
const log = require('./util/log')
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
class HttpServer {
|
|
34
34
|
//
|
|
35
35
|
// Singleton access (async).
|
|
36
36
|
//
|
|
@@ -169,3 +169,5 @@ export default class HttpServer {
|
|
|
169
169
|
})
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
+
|
|
173
|
+
module.exports = HttpServer
|
package/lib/Identity.js
CHANGED
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
//
|
|
15
15
|
////////////////////////////////////////////////////////////////////////////////
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const util = require('util')
|
|
18
|
+
const fs = require('fs-extra')
|
|
19
|
+
const jose = require('jose')
|
|
20
|
+
const Throws = require('./util/Throws')
|
|
21
|
+
const log = require('./util/log')
|
|
22
22
|
|
|
23
23
|
const throws = new Throws({
|
|
24
24
|
[Symbol.for('UnsupportedIdentityType')]: identityFilePath => `The identity file path passed (${identityFilePath}) is for an unsupported identity type.`
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
class Identity {
|
|
28
28
|
|
|
29
29
|
constructor (configuration = throws.ifMissing(), identityFilePathKey = throws.ifMissing()) {
|
|
30
30
|
const identityFilePath = configuration[identityFilePathKey]
|
|
@@ -109,3 +109,5 @@ export default class Identity {
|
|
|
109
109
|
//
|
|
110
110
|
#identityFilePath = null
|
|
111
111
|
}
|
|
112
|
+
|
|
113
|
+
module.exports = Identity
|
package/lib/LetsEncryptServer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
const util = require('util')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
class LetsEncryptServer {
|
|
4
4
|
/**
|
|
5
5
|
* Enumeration.
|
|
6
6
|
*
|
|
@@ -54,3 +54,5 @@ export default class LetsEncryptServer {
|
|
|
54
54
|
'http://localhost:9829/directory'
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
module.exports = LetsEncryptServer
|
package/lib/Nonce.js
CHANGED
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
//
|
|
21
21
|
////////////////////////////////////////////////////////////////////////////////
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const prepareRequest = require('bent')
|
|
24
|
+
const log = require('./util/log')
|
|
25
|
+
const Throws = require('./util/Throws')
|
|
26
26
|
|
|
27
27
|
const throws = new Throws()
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
class Nonce {
|
|
30
30
|
constructor (directory = throws.ifMissing()) {
|
|
31
31
|
this.#directory = directory
|
|
32
32
|
}
|
|
@@ -73,3 +73,5 @@ export default class Nonce {
|
|
|
73
73
|
#directory = null
|
|
74
74
|
#freshNonce = null
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
module.exports = Nonce
|
package/lib/Order.js
CHANGED
|
@@ -12,23 +12,23 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const fs = require('fs-extra')
|
|
16
|
+
const Authorisation = require('./Authorisation')
|
|
17
|
+
const HttpServer = require('./HttpServer')
|
|
18
|
+
const CertificateIdentity = require('./identities/CertificateIdentity')
|
|
19
|
+
const acmeCsr = require('./acmeCsr')
|
|
20
|
+
const asyncForEach = require('./util/async-foreach')
|
|
21
|
+
const log = require('./util/log')
|
|
22
|
+
const NewOrderRequest = require('./acme-requests/NewOrderRequest')
|
|
23
|
+
const FinaliseOrderRequest = require('./acme-requests/FinaliseOrderRequest')
|
|
24
|
+
const CheckOrderStatusRequest = require('./acme-requests/CheckOrderStatusRequest')
|
|
25
|
+
const CertificateRequest = require('./acme-requests/CertificateRequest')
|
|
26
|
+
const Throws = require('./util/Throws')
|
|
27
|
+
const waitFor = require('./util/waitFor')
|
|
28
28
|
|
|
29
29
|
const throws = new Throws()
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
class Order {
|
|
32
32
|
#data = null
|
|
33
33
|
#headers = null
|
|
34
34
|
#order = null
|
|
@@ -193,7 +193,7 @@ export default class Order {
|
|
|
193
193
|
|
|
194
194
|
// Save the certificate.
|
|
195
195
|
try {
|
|
196
|
-
await
|
|
196
|
+
await fs.writeFile(this.configuration.certificatePath, this.certificate, 'utf-8')
|
|
197
197
|
} catch (error) {
|
|
198
198
|
throw new Error(error)
|
|
199
199
|
}
|
|
@@ -214,3 +214,5 @@ export default class Order {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
+
|
|
218
|
+
module.exports = Order
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
//
|
|
12
12
|
////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
15
|
+
const Throws = require('../util/Throws')
|
|
16
16
|
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
class AuthorisationRequest extends AcmeRequest {
|
|
20
20
|
async execute (authorisationUrl = throws.ifMissing()) {
|
|
21
21
|
// This is a POST-as-GET request so it doesn’t have a payload.
|
|
22
22
|
// See RFC 8555 § 6.3 (GET and POST-as-GET requests).
|
|
@@ -34,3 +34,5 @@ export default class AuthorisationRequest extends AcmeRequest {
|
|
|
34
34
|
return response
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
module.exports = AuthorisationRequest
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
16
|
+
const Throws = require('../util/Throws')
|
|
17
17
|
|
|
18
18
|
const throws = new Throws()
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
class CertificateRequest extends AcmeRequest {
|
|
21
21
|
async execute (certificateUrl = throws.ifMissing()) {
|
|
22
22
|
// This is a POST-as-GET request so it doesn’t have a payload.
|
|
23
23
|
// See RFC 8555 § 6.3 (GET and POST-as-GET requests).
|
|
@@ -37,3 +37,5 @@ export default class CertificateRequest extends AcmeRequest {
|
|
|
37
37
|
return response
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
module.exports = CertificateRequest
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
//
|
|
15
15
|
////////////////////////////////////////////////////////////////////////////////
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
18
|
+
const Throws = require('../util/Throws')
|
|
19
19
|
|
|
20
20
|
const throws = new Throws()
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
class CheckOrderStatusRequest extends AcmeRequest {
|
|
23
23
|
async execute (orderUrl = throws.ifMissing()) {
|
|
24
24
|
|
|
25
25
|
const payload = '' // POST-as-GET
|
|
@@ -35,3 +35,5 @@ export default class CheckOrderStatusRequest extends AcmeRequest {
|
|
|
35
35
|
return response
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
module.exports = CheckOrderStatusRequest
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
//
|
|
12
12
|
////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
15
|
+
const Throws = require('../util/Throws')
|
|
16
16
|
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
class FinaliseOrderRequest extends AcmeRequest {
|
|
20
20
|
async execute (finaliseUrl = throws.ifMissing(), csr = throws.ifMissing()) {
|
|
21
21
|
|
|
22
22
|
const payload = { csr }
|
|
@@ -32,3 +32,5 @@ export default class FinaliseOrderRequest extends AcmeRequest {
|
|
|
32
32
|
return response
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
module.exports = FinaliseOrderRequest
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
class NewAccountRequest extends AcmeRequest {
|
|
18
18
|
async execute () {
|
|
19
19
|
// Set the only required element.
|
|
20
20
|
const payload = { termsOfServiceAgreed: true }
|
|
@@ -30,3 +30,5 @@ export default class NewAccountRequest extends AcmeRequest {
|
|
|
30
30
|
return account
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
module.exports = NewAccountRequest
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
16
|
+
const Throws = require('../util/Throws')
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
class NewOrderRequest extends AcmeRequest {
|
|
20
20
|
async execute (configuration = throws.ifMissing()) {
|
|
21
21
|
const identifiers = configuration.domains.map(domain => { return { type: 'dns', value: domain} })
|
|
22
22
|
const payload = { identifiers }
|
|
@@ -25,3 +25,5 @@ export default class NewOrderRequest extends AcmeRequest {
|
|
|
25
25
|
return response
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
module.exports = NewOrderRequest
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
//
|
|
14
14
|
////////////////////////////////////////////////////////////////////////////////
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const AcmeRequest = require('../AcmeRequest')
|
|
17
|
+
const Throws = require('../util/Throws')
|
|
18
18
|
|
|
19
19
|
const throws = new Throws()
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
class ReadyForChallengeValidationRequest extends AcmeRequest {
|
|
22
22
|
async execute (challengeUrl = throws.ifMissing()) {
|
|
23
23
|
const emptyPayload = {}
|
|
24
24
|
|
|
@@ -33,3 +33,5 @@ export default class ReadyForChallengeValidationRequest extends AcmeRequest {
|
|
|
33
33
|
return response
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
module.exports = ReadyForChallengeValidationRequest
|
package/lib/acmeCsr.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// License: AGPLv3 or later.
|
|
13
13
|
//
|
|
14
14
|
////////////////////////////////////////////////////////////////////////////////
|
|
15
|
-
|
|
15
|
+
const forge = require('node-forge')
|
|
16
16
|
const DNS = 2 // The ANS.1 type for DNS name.
|
|
17
17
|
|
|
18
18
|
// Returns a valid ACME-formatted (RFC 8555) CSR.
|
|
@@ -24,7 +24,7 @@ const DNS = 2 // The ANS.1 type for DNS name.
|
|
|
24
24
|
* @param {JWK.rsaKey} key
|
|
25
25
|
* @returns {String} An ACME-formatted CSR in PEM format.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
module.exports = function (domains, key) { return pemToAcmeCsr(csrAsPem(domains, key)) }
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a CSR given a list of domains and a Jose JWK.rsaKey.
|
|
@@ -62,7 +62,7 @@ function csrAsPem (domains, key) {
|
|
|
62
62
|
}]
|
|
63
63
|
}])
|
|
64
64
|
|
|
65
|
-
csr.sign(keys.private)
|
|
65
|
+
csr.sign(keys.private, forge.md.sha256.create())
|
|
66
66
|
|
|
67
67
|
const pem = forge.pki.certificationRequestToPem(csr)
|
|
68
68
|
return pem
|
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
//
|
|
13
13
|
////////////////////////////////////////////////////////////////////////////////
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const Identity = require('../Identity')
|
|
16
|
+
const Throws = require('../util/Throws')
|
|
17
17
|
const throws = new Throws()
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
class AccountIdentity extends Identity {
|
|
20
20
|
constructor (configuration = throws.ifMissing()) {
|
|
21
21
|
super(configuration, 'accountIdentityPath')
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
module.exports = AccountIdentity
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const Identity = require('../Identity')
|
|
2
|
+
const Throws = require('../util/Throws')
|
|
3
3
|
const throws = new Throws()
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,7 +13,7 @@ const throws = new Throws()
|
|
|
13
13
|
* @copyright Aral Balkan, Small Technology Foundation
|
|
14
14
|
* @license AGPLv3 or later
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
class CertificateIdentity extends Identity {
|
|
17
17
|
/**
|
|
18
18
|
* Creates an instance of CertificateIdentity.
|
|
19
19
|
*
|
|
@@ -24,3 +24,5 @@ export default class CertificateIdentity extends Identity {
|
|
|
24
24
|
super(configuration, 'certificateIdentityPath')
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
module.exports = CertificateIdentity
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-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/j68R/iDlCOM4VVfRa8gX6T2FU7fNdatvGro7uQzIvWof
|
|
30
|
+
gN9WUwCbEMBy/YhBSrXycKA8crgGg3x1mIsopn88JKwmMBa68oS7EHM9w7C4y71M
|
|
31
|
+
7DiA+/9Qdp9RBWJpTS9i/mDnJg1xvo8Xz49mrrgfmcAXTCJqXi24NatI3Oc=
|
|
29
32
|
-----END CERTIFICATE-----
|
|
@@ -7,18 +7,16 @@
|
|
|
7
7
|
* @copyright Copyright © 2020 Aral Balkan, Small Technology Foundation.
|
|
8
8
|
* @license AGPLv3 or later.
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const __dirname = new URL('.', import.meta.url).pathname
|
|
10
|
+
const fs = require('fs')
|
|
11
|
+
const tls = require('tls')
|
|
12
|
+
const path = require('path')
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
15
|
* Monkey patches the TLS module to accept the Let’s Encrypt staging certificate.
|
|
18
16
|
*
|
|
19
17
|
* @alias module:lib/MonkeyPatchTls
|
|
20
18
|
*/
|
|
21
|
-
|
|
19
|
+
function monkeyPatchTLS () {
|
|
22
20
|
const originalCreateSecureContext = tls.createSecureContext
|
|
23
21
|
|
|
24
22
|
let pem = fs
|
|
@@ -37,3 +35,5 @@ export default function monkeyPatchTLS () {
|
|
|
37
35
|
return context
|
|
38
36
|
}
|
|
39
37
|
}
|
|
38
|
+
|
|
39
|
+
module.exports = monkeyPatchTLS
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
//
|
|
5
5
|
//////////////////////////////////////////////////////////////////////
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const fs = require('fs-extra')
|
|
8
|
+
const os = require('os')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
const http = require('http')
|
|
11
|
+
const enableServerDestroy = require('server-destroy')
|
|
12
|
+
const Configuration = require('../Configuration')
|
|
13
|
+
const LetsEncryptServer = require('../LetsEncryptServer')
|
|
14
|
+
const Throws = require('../util/Throws')
|
|
15
|
+
const log = require('../util/log')
|
|
16
16
|
|
|
17
17
|
//
|
|
18
18
|
// Server mocks.
|
|
@@ -22,7 +22,7 @@ const throws = new Throws({
|
|
|
22
22
|
[Symbol.for('MockServerCouldNotBeStartedError')]: details => `Mock server could not be started (${error})`
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
class MockServer {
|
|
26
26
|
static #isBeingInstantiatedViaAsyncFactoryMethod = false
|
|
27
27
|
|
|
28
28
|
static async getInstanceAsync (responseHandler = throws.ifMissing()) {
|
|
@@ -64,7 +64,7 @@ export class MockServer {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
async function httpServerWithResponse (mockResponse) {
|
|
68
68
|
return new Promise((resolve, reject) => {
|
|
69
69
|
const server = http.createServer((request, response) => {
|
|
70
70
|
response.statusCode = mockResponse.statusCode
|
|
@@ -76,26 +76,18 @@ export async function httpServerWithResponse (mockResponse) {
|
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
//
|
|
80
|
-
// Pebble setup and teardown.
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
export class TestContext {
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
79
|
//
|
|
88
80
|
// Timing.
|
|
89
81
|
//
|
|
90
82
|
|
|
91
|
-
|
|
83
|
+
function timeIt(func) {
|
|
92
84
|
const startTime = new Date()
|
|
93
85
|
const returnValue = func()
|
|
94
86
|
const endTime = new Date()
|
|
95
87
|
return { returnValue, duration: endTime - startTime }
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
|
|
90
|
+
async function timeItAsync(func) {
|
|
99
91
|
const startTime = new Date()
|
|
100
92
|
const returnValue = await func()
|
|
101
93
|
const endTime = new Date()
|
|
@@ -106,7 +98,7 @@ export async function timeItAsync(func) {
|
|
|
106
98
|
// Error validation.
|
|
107
99
|
//
|
|
108
100
|
|
|
109
|
-
|
|
101
|
+
function symbolOfErrorThrownBy(func) {
|
|
110
102
|
try {
|
|
111
103
|
func()
|
|
112
104
|
return false
|
|
@@ -116,7 +108,7 @@ export function symbolOfErrorThrownBy(func) {
|
|
|
116
108
|
}
|
|
117
109
|
}
|
|
118
110
|
|
|
119
|
-
|
|
111
|
+
async function symbolOfErrorThrownByAsync(func) {
|
|
120
112
|
try {
|
|
121
113
|
await func()
|
|
122
114
|
return false
|
|
@@ -126,7 +118,7 @@ export async function symbolOfErrorThrownByAsync(func) {
|
|
|
126
118
|
}
|
|
127
119
|
}
|
|
128
120
|
|
|
129
|
-
|
|
121
|
+
function throwsErrorOfType (func, errorSymbol) {
|
|
130
122
|
try {
|
|
131
123
|
func()
|
|
132
124
|
} catch (error) {
|
|
@@ -137,7 +129,7 @@ export function throwsErrorOfType (func, errorSymbol) {
|
|
|
137
129
|
return false
|
|
138
130
|
}
|
|
139
131
|
|
|
140
|
-
|
|
132
|
+
async function throwsErrorOfTypeAsync (asyncFunc, errorSymbol) {
|
|
141
133
|
try {
|
|
142
134
|
await asyncFunc()
|
|
143
135
|
} catch (error) {
|
|
@@ -148,17 +140,18 @@ export async function throwsErrorOfTypeAsync (asyncFunc, errorSymbol) {
|
|
|
148
140
|
return false
|
|
149
141
|
}
|
|
150
142
|
|
|
151
|
-
|
|
143
|
+
|
|
144
|
+
function dehydrate (string) {
|
|
152
145
|
return string.replace(/\s/g, '')
|
|
153
146
|
}
|
|
154
147
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
fs.
|
|
148
|
+
function createTestSettingsPath () {
|
|
149
|
+
testSettingsPath = path.join(os.homedir(), '.small-tech.org', 'auto-encrypt', 'test')
|
|
150
|
+
fs.removeSync(testSettingsPath)
|
|
158
151
|
return testSettingsPath
|
|
159
152
|
}
|
|
160
153
|
|
|
161
|
-
|
|
154
|
+
function initialiseStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
162
155
|
Configuration.reset()
|
|
163
156
|
Configuration.initialise({
|
|
164
157
|
domains: ['dev.ar.al'],
|
|
@@ -167,6 +160,21 @@ export function initialiseStagingConfigurationWithOneDomainAtTestSettingsPath ()
|
|
|
167
160
|
})
|
|
168
161
|
}
|
|
169
162
|
|
|
170
|
-
|
|
163
|
+
function setupStagingConfigurationWithOneDomainAtTestSettingsPath () {
|
|
171
164
|
initialiseStagingConfigurationWithOneDomainAtTestSettingsPath()
|
|
172
165
|
}
|
|
166
|
+
|
|
167
|
+
module.exports = {
|
|
168
|
+
MockServer,
|
|
169
|
+
timeIt,
|
|
170
|
+
timeItAsync,
|
|
171
|
+
symbolOfErrorThrownByAsync,
|
|
172
|
+
symbolOfErrorThrownBy,
|
|
173
|
+
throwsErrorOfType,
|
|
174
|
+
throwsErrorOfTypeAsync,
|
|
175
|
+
dehydrate,
|
|
176
|
+
createTestSettingsPath,
|
|
177
|
+
initialiseStagingConfigurationWithOneDomainAtTestSettingsPath,
|
|
178
|
+
setupStagingConfigurationWithOneDomainAtTestSettingsPath,
|
|
179
|
+
httpServerWithResponse
|
|
180
|
+
}
|
package/lib/util/Pluralise.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
class Pluralise {
|
|
2
2
|
|
|
3
3
|
static requiresEs (word) {
|
|
4
4
|
// Note: this is not meant to be comprehensive. It doesn’t take into consideration
|
|
@@ -17,3 +17,5 @@ export default class Pluralise {
|
|
|
17
17
|
return array.length === 1 ? word : `${word}${this.requiresEs(word) ? 'es' : 's'}`
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
module.exports = Pluralise
|