diff --git a/changelog.md b/changelog.md index 536289d..55806ba 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2024-09-18 - 5.1.0 - feat(ts_node) +Add support for HTTPS certificate creation + +- Added TapNodeTools class with methods to run commands and create HTTPS certificates +- Exported necessary plugins including crypto and fs for node +- Updated test cases to include tests for HTTPS certificate creation + ## 2024-09-17 - 5.0.25 - fix(core) Fix typos in package.json, update dependencies and update workflow. diff --git a/test/test.node.ts b/test/test.node.ts index 7e98887..f393320 100644 --- a/test/test.node.ts +++ b/test/test.node.ts @@ -7,4 +7,12 @@ tap.test('should execure a command', async () => { expect(result.exitCode).toEqual(0); }); +tap.test('should create a https cert', async () => { + const { key, cert } = await tapNodeTools.createHttpsCert('localhost', 'localhost.key', 'localhost.cert'); + console.log(key); + console.log(cert); + expect(key).toInclude('-----BEGIN PRIVATE KEY-----'); + expect(cert).toInclude('-----BEGIN CERTIFICATE-----'); +}); + tap.start(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 482615d..033b23e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/tapbundle', - version: '5.0.25', + version: '5.1.0', description: 'A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.' } diff --git a/ts_node/classes.tapnodetools.ts b/ts_node/classes.tapnodetools.ts new file mode 100644 index 0000000..c32014d --- /dev/null +++ b/ts_node/classes.tapnodetools.ts @@ -0,0 +1,45 @@ +import * as plugins from './plugins.js'; + +class TapNodeTools { + + private smartshellInstance: plugins.smartshell.Smartshell; + constructor() { + + } + + public async runCommand(commandArg) { + if (!this.smartshellInstance) { + this.smartshellInstance = new plugins.smartshell.Smartshell({ + executor: 'bash', + }); + } + const result = await this.smartshellInstance.exec(commandArg); + return result; + } + + public async createHttpsCert(commonName: string, keyFile: string, certFile: string): Promise<{ key: string, cert: string }> { + const key = plugins.crypto.generateKeyPairSync('rsa', { + modulusLength: 2048, + publicExponent: 65537, + }); + + const cert = '-----BEGIN CERTIFICATE-----\n' + + key.publicKey.export({ + type: 'spki', + format: 'pem' + }) + + '\n-----END CERTIFICATE-----\n'; + + const keyContent = key.privateKey.export({ + type: 'pkcs8', + format: 'pem', + }); + + return { + key: keyContent as string, + cert: cert, + } + } +} + +export const tapNodeTools = new TapNodeTools(); \ No newline at end of file diff --git a/ts_node/index.ts b/ts_node/index.ts index a0af471..f4f13a9 100644 --- a/ts_node/index.ts +++ b/ts_node/index.ts @@ -1,21 +1 @@ -import * as plugins from './plugins.js'; - -class TapNodeTools { - - private smartshellInstance: plugins.smartshell.Smartshell; - constructor() { - - } - - public async runCommand(commandArg) { - if (!this.smartshellInstance) { - this.smartshellInstance = new plugins.smartshell.Smartshell({ - executor: 'bash', - }); - } - const result = await this.smartshellInstance.exec(commandArg); - return result; - } -} - -export const tapNodeTools = new TapNodeTools(); \ No newline at end of file +export * from './classes.tapnodetools.js'; diff --git a/ts_node/plugins.ts b/ts_node/plugins.ts index 2d50065..dcdc188 100644 --- a/ts_node/plugins.ts +++ b/ts_node/plugins.ts @@ -1,3 +1,10 @@ +// node native +import * as crypto from 'crypto'; +import * as fs from 'fs'; + +export { crypto,fs }; + +// @push.rocks scope import * as smartshell from '@push.rocks/smartshell'; export { smartshell };