-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
schwaby.io
committed
Apr 23, 2024
1 parent
a5d6ab0
commit 79f1715
Showing
81 changed files
with
6,899 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// getTrustedCaCertFilePath.js - Get absolute file path of trusted CA cert // | ||
// for Newman options.sslExtraCaCerts. // | ||
// // | ||
// Created by: schwaby.io // | ||
//////////////////////////////////////////////////////////////////////////////// | ||
const { readdir } = require('node:fs/promises') | ||
const path = require('node:path') | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
const getTrustedCaCertFilePath = async function getTrustedCaCertFilePath(settings) { | ||
const defaultTrustedCaCertDirectoryPath = 'trustedCaCert' | ||
let directoryPath | ||
|
||
//Check if settings.trustedCaCertDirectoryPath is an absolute path | ||
if (path.isAbsolute(settings.trustedCaCertDirectoryPath)) { | ||
directoryPath = settings.trustedCaCertDirectoryPath | ||
} else { | ||
//Need to join | ||
directoryPath = path.join(settings.xRunProjectPath, settings.xRunProjectDirectoryName, settings.trustedCaCertDirectoryPath) | ||
} | ||
|
||
try { | ||
const filePathArray = [] | ||
|
||
//Read directoryPath for a .pem file | ||
const files = await readdir(directoryPath) | ||
|
||
//Loop over all files | ||
for (const fileName of files) { | ||
|
||
//Only add files that match '.pem' file extension | ||
if (path.extname(fileName) === '.pem') { | ||
filePathArray.push(path.join(directoryPath, fileName)) | ||
} | ||
} | ||
|
||
if (filePathArray.length === 1) { | ||
//There should only be one '.pem' file, return | ||
return filePathArray[0] | ||
} else if (filePathArray.length === 0) { | ||
console.log(`WARNING: No '.pem' file was found within '${directoryPath}'`) | ||
return null | ||
} else { | ||
console.log(`WARNING: Found more than one '.pem' file within '${directoryPath}'. Only using the first found '${filePathArray[0]}'`) | ||
return filePathArray[0] | ||
} | ||
|
||
} catch (error) { | ||
//Do not throw error | ||
|
||
//Only display warnings when NOT using default trustedCaCertDirectoryPath | ||
if (settings.trustedCaCertDirectoryPath !== defaultTrustedCaCertDirectoryPath) { | ||
//Do not throw error, just display warningMessage | ||
const warningMessage = `WARNING: unable to getTrustedCaCertFilePath(): ${error.code} '${directoryPath}' - ${error.message}` | ||
console.log(warningMessage) | ||
} | ||
|
||
return null | ||
} | ||
} | ||
|
||
|
||
module.exports = getTrustedCaCertFilePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const path = require('node:path') | ||
|
||
const getTrustedCaCertFilePath = require('./getTrustedCaCertFilePath') | ||
|
||
test('successfully returns a path to a trustedCaCertFile', async() => { | ||
const settings = {} | ||
settings['xRunProjectPath'] = path.join(__dirname, '/unit-tests/test-data/test-project6') | ||
settings['xRunProjectDirectoryName'] = 'xrun' | ||
settings['trustedCaCertDirectoryPath'] = 'trustedCaCert' | ||
const trustedCaCertFilePath = await getTrustedCaCertFilePath(settings) | ||
|
||
expect(trustedCaCertFilePath).toContain('unit-tests/test-data/test-project6/xrun/trustedCaCert/successfulCaCert.pem') | ||
}) | ||
|
||
|
||
test('No error occurs when trustedCaCertDirectoryPath does NOT exist and trustedCaCertFilePath === null', async() => { | ||
const settings = {} | ||
settings['xRunProjectPath'] = path.join(__dirname, '/unit-tests/test-data/test-project3') | ||
settings['xRunProjectDirectoryName'] = 'xrun' | ||
settings['trustedCaCertDirectoryPath'] = 'trustedCaCert' | ||
const trustedCaCertFilePath = await getTrustedCaCertFilePath(settings) | ||
|
||
expect(trustedCaCertFilePath).toBeNull() | ||
}) | ||
|
||
test('successfully returns a path to a trustedCaCertFile when using a custom trustedCaCertDirectoryPath', async() => { | ||
const settings = {} | ||
settings['xRunProjectPath'] = path.join(__dirname, '/unit-tests/test-data/test-project7') | ||
settings['xRunProjectDirectoryName'] = 'xrun' | ||
settings['trustedCaCertDirectoryPath'] = 'customTrustedCaCertDirectory' | ||
const trustedCaCertFilePath = await getTrustedCaCertFilePath(settings) | ||
|
||
expect(trustedCaCertFilePath).toContain('unit-tests/test-data/test-project7/xrun/customTrustedCaCertDirectory/successfulCaCert.pem') | ||
}) | ||
|
||
|
||
test('successfully returns a path to a trustedCaCertFile when using an absolute path for trustedCaCertDirectoryPath', async() => { | ||
const settings = {} | ||
settings['xRunProjectPath'] = path.join(__dirname, '/unit-tests/test-data/test-project6') | ||
settings['xRunProjectDirectoryName'] = 'xrun' | ||
settings['trustedCaCertDirectoryPath'] = path.join(__dirname, '/unit-tests/test-data/trustedCaCertDirectory') | ||
const trustedCaCertFilePath = await getTrustedCaCertFilePath(settings) | ||
|
||
expect(trustedCaCertFilePath).toContain('/unit-tests/test-data/trustedCaCertDirectory/successfulCaCert.pem') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.