fix(core): update

This commit is contained in:
Philipp Kunz 2019-01-13 02:10:00 +01:00
parent c3fd8750b2
commit f9db3d28fe
6 changed files with 30 additions and 6 deletions

8
package-lock.json generated
View File

@ -271,12 +271,12 @@
} }
}, },
"@pushrocks/smartstring": { "@pushrocks/smartstring": {
"version": "3.0.5", "version": "3.0.8",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.5.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartstring/-/smartstring-3.0.8.tgz",
"integrity": "sha512-Bws2s6+Pc0HIXA35QH6cl6LJywhZ1U5icjyYMx+1kH8nURG+njzkacfarr9NWqyVYYOVu7SgXLzp9sR0eH7k9g==", "integrity": "sha512-twmCGF47+TJoiCpj6t5MxwcKDDJEATuKqJXxftcHOlXWW743LJ/1bCpMueDdtumo5EheUfSxb43aRse3DU3wig==",
"requires": { "requires": {
"crypto-random-string": "^1.0.0", "crypto-random-string": "^1.0.0",
"js-base64": "^2.4.9", "js-base64": "^2.5.0",
"normalize-newline": "^3.0.0", "normalize-newline": "^3.0.0",
"randomatic": "^3.1.1", "randomatic": "^3.1.1",
"strip-indent": "^2.0.0" "strip-indent": "^2.0.0"

View File

@ -32,6 +32,7 @@
"@pushrocks/smartexpress": "^3.0.0", "@pushrocks/smartexpress": "^3.0.0",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^2.0.5",
"@pushrocks/smartrequest": "^1.1.14", "@pushrocks/smartrequest": "^1.1.14",
"@pushrocks/smartstring": "^3.0.8",
"@pushrocks/smarttime": "^3.0.5", "@pushrocks/smarttime": "^3.0.5",
"@pushrocks/smartunique": "^3.0.1", "@pushrocks/smartunique": "^3.0.1",
"acme-client": "^2.2.2" "acme-client": "^2.2.2"

View File

@ -30,6 +30,13 @@ tap.test('should create a valid instance of SmartAcme', async () => {
// await smartAcmeInstance.getCertificateForDomain('bleu.de'); // await smartAcmeInstance.getCertificateForDomain('bleu.de');
}); });
tap.test('certmatcher should correctly match domains', async () => {
const certMatcherMod = await import('../ts/smartacme.classes.certmatcher');
const certMatcher = new certMatcherMod.CertMatcher();
const matchedCert = certMatcher.getCertificateDomainNameByDomainName('level3.level2.level1');
expect(matchedCert).to.equal('level2.level1');
});
tap.test('should stop correctly', async () => { tap.test('should stop correctly', async () => {
await smartAcmeInstance.stop(); await smartAcmeInstance.stop();
}); });

View File

@ -0,0 +1,10 @@
import * as plugins from './smartacme.plugins';
export class CertMatcher {
public getCertificateDomainNameByDomainName(domainNameArg: string): string {
const originalDomain = new plugins.smartstring.Domain(domainNameArg);
if (!originalDomain.level4) {
return `${originalDomain.level2}.${originalDomain.level1}`;
}
}
}

View File

@ -1,6 +1,7 @@
import * as plugins from './smartacme.plugins'; import * as plugins from './smartacme.plugins';
import { Cert } from './smartacme.classes.cert'; import { Cert } from './smartacme.classes.cert';
import { CertManager } from './smartacme.classes.certmanager'; import { CertManager } from './smartacme.classes.certmanager';
import { CertMatcher } from './smartacme.classes.certmatcher';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
import { request } from 'http'; import { request } from 'http';
@ -44,6 +45,7 @@ export class SmartAcme {
// certmanager // certmanager
private certmanager: CertManager; private certmanager: CertManager;
private certmatcher: CertMatcher;
private certremoteHandler: plugins.smartexpress.Handler; private certremoteHandler: plugins.smartexpress.Handler;
constructor(optionsArg: ISmartAcmeOptions) { constructor(optionsArg: ISmartAcmeOptions) {
@ -68,6 +70,9 @@ export class SmartAcme {
}); });
await this.certmanager.init(); await this.certmanager.init();
// CertMatcher
this.certmatcher = new CertMatcher();
// CertRemoteHandler // CertRemoteHandler
this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => { this.certremoteHandler = new plugins.smartexpress.Handler('POST', async (req, res) => {
const requestBody: interfaces.ICertRemoteRequest = req.body; const requestBody: interfaces.ICertRemoteRequest = req.body;
@ -118,7 +123,7 @@ export class SmartAcme {
} }
public async getCertificateForDomain(domainArg: string): Promise<Cert> { public async getCertificateForDomain(domainArg: string): Promise<Cert> {
const domain = domainArg; const domain = this.certmatcher.getCertificateDomainNameByDomainName(domainArg);
const retrievedCertificate = await this.certmanager.retrieveCertificate(domain); const retrievedCertificate = await this.certmanager.retrieveCertificate(domain);

View File

@ -7,9 +7,10 @@ import * as smartexpress from '@pushrocks/smartexpress';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
import * as smartunique from '@pushrocks/smartunique'; import * as smartunique from '@pushrocks/smartunique';
import * as smartstring from '@pushrocks/smartstring';
import * as smarttime from '@pushrocks/smarttime'; import * as smarttime from '@pushrocks/smarttime';
export { lik, smartdata, smartdelay, smartdns, smartexpress, smartpromise, smartrequest, smartunique, smarttime }; export { lik, smartdata, smartdelay, smartdns, smartexpress, smartpromise, smartrequest, smartunique, smartstring, smarttime };
// thirs party scope // thirs party scope
import * as acme from 'acme-client'; import * as acme from 'acme-client';