From 3f203582f1f0a6990feff1bf6ca1437cfdc7bb29 Mon Sep 17 00:00:00 2001 From: akanass Date: Mon, 1 Feb 2021 01:26:31 +0100 Subject: [PATCH] fix(script): update scripts for latest packages versions --- nest-cli.json | 1 - test/integration/aes.service.test.ts | 9 +++----- test/integration/hash.service.test.ts | 2 +- test/integration/pem.service.test.ts | 28 +++++++++++------------ test/integration/rsa.service.test.ts | 18 +++++++-------- tools/packaging.ts | 32 +++++++++++++-------------- 6 files changed, 43 insertions(+), 47 deletions(-) diff --git a/nest-cli.json b/nest-cli.json index 0dde5f8..56167b3 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -1,5 +1,4 @@ { - "language": "ts", "collection": "@nestjs/schematics", "sourceRoot": "src" } diff --git a/test/integration/aes.service.test.ts b/test/integration/aes.service.test.ts index d91d201..3c98757 100644 --- a/test/integration/aes.service.test.ts +++ b/test/integration/aes.service.test.ts @@ -31,8 +31,7 @@ describe('- Integration aes.service.test.ts file', () => { */ test('- `AesService.createKey()` function must return an Observable with error if AesService key parameters are wrong', (done) => { aesService.createKey(null, null).subscribe(() => null, err => { - expect(err.message).toBe('The "password" argument must be one of type string, ' + - 'Buffer, TypedArray, or DataView. Received type object'); + expect(err.message).toBe('The "password" argument must be of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView. Received null'); done(); }); }); @@ -122,8 +121,7 @@ describe('- Integration aes.service.test.ts file', () => { encryptWithAesKey(Buffer.from('data')) ) .subscribe(() => null, err => { - expect(err.message).toBe('The first argument must be one of type string, ' + - 'Buffer, ArrayBuffer, Array, or Array-like Object. Received type object'); + expect(err.message).toBe('The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null'); done(); }); }); @@ -138,8 +136,7 @@ describe('- Integration aes.service.test.ts file', () => { decryptWithAesKey(Buffer.from('a3d4bb8fcb8ec0e24a86cef07a28e3af', 'hex')) ) .subscribe(() => null, err => { - expect(err.message).toBe('The first argument must be one of type string, ' + - 'Buffer, ArrayBuffer, Array, or Array-like Object. Received type object'); + expect(err.message).toBe('The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null'); done(); }); }); diff --git a/test/integration/hash.service.test.ts b/test/integration/hash.service.test.ts index 88d746a..e3c9b1c 100644 --- a/test/integration/hash.service.test.ts +++ b/test/integration/hash.service.test.ts @@ -39,7 +39,7 @@ describe('- Integration hash.service.test.ts file', () => { test('- `HashService.generate()` function must return an Observable with error if parameters are wrong', (done) => { hashService.generate(undefined, undefined, undefined, undefined, undefined) .subscribe(() => null, err => { - expect(err.message).toBe('The "digest" argument must be one of type string or null. Received type undefined'); + expect(err.message).toBe('The "digest" argument must be of type string. Received undefined'); done(); } ); diff --git a/test/integration/pem.service.test.ts b/test/integration/pem.service.test.ts index 590aca5..1a73de6 100644 --- a/test/integration/pem.service.test.ts +++ b/test/integration/pem.service.test.ts @@ -1,4 +1,4 @@ -import { flatMap } from 'rxjs/operators'; +import { mergeMap } from 'rxjs/operators'; import { CertificateCreationResult, CertificateSubjectReadResult, @@ -101,7 +101,7 @@ describe('- Integration pem.service.test.ts file', () => { '`{country, state, locality, organization, organizationUnit, commonName, emailAddress}`', (done) => { pemService.createCertificate() .pipe( - flatMap((c: CertificateCreationResult) => pemService.readCertificateInfo(c.certificate)) + mergeMap((c: CertificateCreationResult) => pemService.readCertificateInfo(c.certificate)) ) .subscribe((certificateSubjectReadResult: CertificateSubjectReadResult) => { expect(certificateSubjectReadResult).toHaveProperty('country'); @@ -121,7 +121,7 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.getPublicKey()` Observable must return a `PublicKeyCreationResult` object `{publicKey}`', (done) => { pemService.createPrivateKey() .pipe( - flatMap((c: PrivateKeyCreationResult) => pemService.getPublicKey(c.key)) + mergeMap((c: PrivateKeyCreationResult) => pemService.getPublicKey(c.key)) ) .subscribe((publicKeyCreationResult: PublicKeyCreationResult) => { expect(publicKeyCreationResult).toHaveProperty('publicKey'); @@ -147,7 +147,7 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.getFingerprint()` Observable must return a `FingerprintResult` object `{fingerprint}`', (done) => { pemService.createCertificate() .pipe( - flatMap((c: CertificateCreationResult) => pemService.getFingerprint(c.certificate)) + mergeMap((c: CertificateCreationResult) => pemService.getFingerprint(c.certificate)) ) .subscribe((fingerprintResult: FingerprintResult) => { expect(fingerprintResult).toHaveProperty('fingerprint'); @@ -161,7 +161,7 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.getModulus()` Observable must return a `ModulusResult` object `{modulus}`', (done) => { pemService.createCertificate() .pipe( - flatMap((c: CertificateCreationResult) => pemService.getModulus(c.certificate)) + mergeMap((c: CertificateCreationResult) => pemService.getModulus(c.certificate)) ) .subscribe((modulusResult: ModulusResult) => { expect(modulusResult).toHaveProperty('modulus'); @@ -175,7 +175,7 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.getDhparamInfo()` Observable must return a `DhParamInfoResult` object `{size, prime}`', (done) => { pemService.createDhparam() .pipe( - flatMap((dh: DhParamKeyCreationResult) => pemService.getDhparamInfo(dh.dhparam)) + mergeMap((dh: DhParamKeyCreationResult) => pemService.getDhparamInfo(dh.dhparam)) ) .subscribe((dhParamInfoResult: DhParamInfoResult) => { expect(dhParamInfoResult).toHaveProperty('size'); @@ -190,13 +190,13 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.createPkcs12()` Observable must return a `PKCS12CreationResult` object `{pkcs12}`', (done) => { pemService.createPrivateKey() .pipe( - flatMap((pk: PrivateKeyCreationResult) => + mergeMap((pk: PrivateKeyCreationResult) => pemService.createCertificate({ clientKey: pk.key, selfSigned: true }) ), - flatMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password')) + mergeMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password')) ) .subscribe((pkcs12Result: PKCS12CreationResult) => { expect(pkcs12Result).toHaveProperty('pkcs12'); @@ -220,14 +220,14 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.createPkcs12()` Observable must return true', (done) => { pemService.createPrivateKey() .pipe( - flatMap((pk: PrivateKeyCreationResult) => + mergeMap((pk: PrivateKeyCreationResult) => pemService.createCertificate({ clientKey: pk.key, selfSigned: true }) ), - flatMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password')), - flatMap((pkcs12Result: PKCS12CreationResult) => pemService.checkPkcs12(pkcs12Result.pkcs12, 'password')) + mergeMap((c: CertificateCreationResult) => pemService.createPkcs12(c.clientKey, c.certificate, 'password')), + mergeMap((pkcs12Result: PKCS12CreationResult) => pemService.checkPkcs12(pkcs12Result.pkcs12, 'password')) ) .subscribe((isValid: boolean) => { expect(isValid).toBeTruthy(); @@ -241,12 +241,12 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.verifySigningChain()` Observable must return true', (done) => { pemService.createCertificate({ commonName: 'CA Certificate' }) .pipe( - flatMap((ca: CertificateCreationResult) => + mergeMap((ca: CertificateCreationResult) => pemService.createCertificate({ serviceKey: ca.serviceKey, serviceCertificate: ca.certificate, serial: Date.now() }) .pipe( - flatMap((cert: CertificateCreationResult) => + mergeMap((cert: CertificateCreationResult) => pemService.verifySigningChain(cert.certificate, ca.certificate) ) ) @@ -264,7 +264,7 @@ describe('- Integration pem.service.test.ts file', () => { test('- `PemService.checkCertificate()` Observable must return true', (done) => { pemService.createCertificate() .pipe( - flatMap((c: CertificateCreationResult) => pemService.checkCertificate(c.certificate)) + mergeMap((c: CertificateCreationResult) => pemService.checkCertificate(c.certificate)) ) .subscribe((isValid: boolean) => { expect(isValid).toBeTruthy(); diff --git a/test/integration/rsa.service.test.ts b/test/integration/rsa.service.test.ts index 50b71f2..0426409 100644 --- a/test/integration/rsa.service.test.ts +++ b/test/integration/rsa.service.test.ts @@ -1,6 +1,6 @@ import { Buffer } from 'buffer'; import { Observable, of } from 'rxjs'; -import { flatMap } from 'rxjs/operators'; +import { mergeMap } from 'rxjs/operators'; import { NodeRSA, RsaService } from '../../src'; import { decryptPrivate, @@ -375,11 +375,11 @@ describe('- Unit rsa.service.test.ts file', () => { rsaService.loadKey(testKey) ) .pipe( - flatMap((key: Observable) => + mergeMap((key: Observable) => key .pipe( encryptPrivate('data'), - flatMap((enc: Buffer) => + mergeMap((enc: Buffer) => key .pipe( decryptPublic(enc) @@ -416,11 +416,11 @@ describe('- Unit rsa.service.test.ts file', () => { rsaService.loadKey(testKey) ) .pipe( - flatMap((key: Observable) => + mergeMap((key: Observable) => key .pipe( encryptPublic('data'), - flatMap((enc: Buffer) => + mergeMap((enc: Buffer) => key .pipe( decryptPrivate(enc, 'utf8') @@ -469,11 +469,11 @@ describe('- Unit rsa.service.test.ts file', () => { test('- `RsaService.loadKey().sign()` lettable operator must return an error if no private key provided', (done) => { of(rsaService.loadKey(testKey)) .pipe( - flatMap((key: Observable) => + mergeMap((key: Observable) => key .pipe( exportKey('public'), - flatMap((k: any) => + mergeMap((k: any) => rsaService.loadKey(k) .pipe( sign('data') @@ -494,11 +494,11 @@ describe('- Unit rsa.service.test.ts file', () => { test('- `RsaService.loadKey().verify()` must return a true', (done) => { of(rsaService.loadKey(testKey)) .pipe( - flatMap((key: Observable) => + mergeMap((key: Observable) => key .pipe( sign('data'), - flatMap((signature: Buffer) => + mergeMap((signature: Buffer) => key .pipe( verify('data', signature) diff --git a/tools/packaging.ts b/tools/packaging.ts index 2f893b2..aa7eb65 100644 --- a/tools/packaging.ts +++ b/tools/packaging.ts @@ -1,6 +1,6 @@ // import libraries -import { Observable, forkJoin } from 'rxjs'; -import { flatMap } from 'rxjs/operators'; +import { forkJoin, Observable } from 'rxjs'; +import { mergeMap } from 'rxjs/operators'; import * as fs from 'fs-extra'; /** @@ -34,6 +34,18 @@ class Packaging { this._destPath = `${process.cwd()}${dest}/`; } + /** + * Function that _copy all files in dist directory + */ + process() { + forkJoin( + this._files.map( + (fileObject: FileObject) => this._copy(fileObject.name) + ) + ) + .subscribe(() => null, error => console.error(error)); + } + /** * Function to copy one file * @@ -48,7 +60,7 @@ class Packaging { } // copy other files - return > new Observable((observer) => { + return >new Observable((observer) => { fs.stat(`${this._srcPath}${file}`, (error, stats) => { if (error) { console.error('doesn\'t exist on copy =>', error.message); @@ -107,7 +119,7 @@ class Packaging { // read package.json return readJson(`${this._srcPath}${file}`) .pipe( - flatMap(packageObj => { + mergeMap(packageObj => { // delete obsolete data in package.json delete packageObj.scripts; delete packageObj.devDependencies; @@ -117,18 +129,6 @@ class Packaging { }) ); } - - /** - * Function that _copy all files in dist directory - */ - process() { - forkJoin( - this._files.map( - (fileObject: FileObject) => this._copy(fileObject.name) - ) - ) - .subscribe(() => null, error => console.error(error)); - } } // process packaging