Skip to content

Commit

Permalink
Advanced collection (#41)
Browse files Browse the repository at this point in the history
* Implemented Collection header update

* Unable to sort folders

* Detect folder sort changes to deploy collection header + check requests and responses object

* Deploy advanced collection

* remove dependency on classic collections for the deploy of the advanced collection

* fix deploy issue where git hub repo was not being found

* fix deploy issue where build was failing

* fix deploy issue env vars incorrect

* created separete deployAdvance git workflow

* created separete deployAdvance git workflow

* replace environment name by environment type

* replace environment name by environment type

* update pre-script to read the RSASign lib from the environment variable

* added lib JsRSASign as resource file

* improved pre-script execution conditions to not execute outside of normal box api requests

* fix lint

* WIP: adding the new util object to the collection deployment

* WIP: implemented deploymen of utilities folder and sub folders

* WIP: added auth api key and oauth 2 to create env and auth helper folders

* WIP: added get workspace method

* WIP: refactor search for folders, requests and responses

* added utilities requests to create and test environments

* fix typo in request param

* fix rsa lib not being added to the collection as a variable

* updated pr-req script to handle \n in the private key

* adjusted test not to include the extra environment variable

* adjusted pre-req script to remove an extra console.log
  • Loading branch information
barduinor authored Sep 27, 2023
1 parent d2174b6 commit 8c76aea
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
9 changes: 1 addition & 8 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,7 @@ class Collection {
value: host,
type: 'string'
}))
// add a variable for each of the JWT JS 3rd party libraries
const libJSRSASign = {
id: Utils.GenID('libJSRSASign'),
key: 'libJSRSASign',
value: null,
type: 'string'
}
variables.push(libJSRSASign)

return variables
}

Expand Down
33 changes: 33 additions & 0 deletions src/CollectionAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require('dotenv').config()

const fs = require('fs')
const Utils = require('./Utils')
const { uniq } = require('lodash')

const Collection = require('./Collection')

Expand Down Expand Up @@ -67,6 +68,25 @@ class CollectionAdvanced extends Collection {

// PRIVATE

/**
* Extracts all server URLs as variables
*/
getVariables () {
const variables = uniq(Object.values(this.openapi.paths).flatMap(endpoints => (
Object.values(endpoints).map(endpoint => this.server(endpoint).host)
))).map(host => ({
id: Utils.GenID(host),
key: host, // .replace(/\./g, '_'),
value: host,
type: 'string'
}))
// add a variable for each of the JWT JS 3rd party libraries
const libJSRSASign = this.variableLibJaRsaSign()

variables.push(libJSRSASign)
return variables
}

injectUtilities (localCollection) {
// insert Utils folder at top level item
// TODO: Add proper description
Expand Down Expand Up @@ -188,6 +208,19 @@ class CollectionAdvanced extends Collection {
return []
}

variableLibJaRsaSign () {
const scriptString = String(fs.readFileSync('./src/events/libJsRSASign.min.js'))
const libJSRSASign = {
id: Utils.GenID('libJSRSASign'),
key: 'libJSRSASign',
value: scriptString,
type: 'string'
}
const hash = this.calculateHash(scriptString)
libJSRSASign.id = Utils.GenID(hash) // RB: to big for uuidv5
return libJSRSASign
}

/**
* Creates a pre-request event for collection
*/
Expand Down
11 changes: 6 additions & 5 deletions src/events/collectionPreReqScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ function get_jwt_assertion () {
navigator = {}
window = {}
/* eslint-disable no-eval */

eval(libJSRSASign)

// UUID
const uuid = require('uuid')

const private_key_encrypted = pm.environment.get('private_key_encrypted')
const private_key_encrypted = pm.environment.get('private_key_encrypted').replace(/\\n/g, '')
const private_key_passphrase = pm.environment.get('private_key_passphrase')

const private_key = KEYUTIL.getKey(private_key_encrypted, private_key_passphrase)
Expand All @@ -178,6 +179,7 @@ function get_jwt_assertion () {
const iat = KJUR.jws.IntDate.get('now')

const header = { alg: 'RS512', typ: 'JWT', kid: kid }
// console.log(`header: ${JSON.stringify(header)}`)

const claims =
{
Expand All @@ -190,11 +192,10 @@ function get_jwt_assertion () {
iat: iat
}

const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key)
// console.log(`claim set: ${JSON.stringify(claims)}`)

// console.log(`header: ${JSON.stringify(header)}`)
// console.log(`claim set: ${JSON.stringify(claims)}`)
// console.log('JWT Assertion: ', jwt)
const jwt = KJUR.jws.JWS.sign(null, header, claims, private_key)
// console.log('JWT Assertion: ', jwt)

return jwt
}
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenAPICollection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('.convert', () => {
const openAPISpec = await openapi.process()
const collection = new Collection(openAPISpec, locale).process()
expect(collection.item).toHaveLength(52)
expect(collection.variable).toHaveLength(3 + 1)
expect(collection.variable).toHaveLength(3)
expect(collection.item[0].item[0].request.url.host).toBe('{{account.box.com}}')
})

Expand Down

0 comments on commit 8c76aea

Please sign in to comment.