Skip to content

inso cli scripting first pass#7790

Merged
jackkav merged 10 commits intoKong:developfrom
jackkav:cli-script-first-pass
Aug 27, 2024
Merged

inso cli scripting first pass#7790
jackkav merged 10 commits intoKong:developfrom
jackkav:cli-script-first-pass

Conversation

@jackkav
Copy link
Contributor

@jackkav jackkav commented Aug 1, 2024

motivation: incrementally extend cli features to match app

aim: add the simplest possible implementation which will allow a header to be added by a pre request script, to be confirmed with a test which will rely upon on the script modifying the request

  • proof of concept, copied from hidden-window.ts and wired up
  • make requireInterceptor work, and use same abstraction as hidden-window
  • test case for add header
  • test case for require
  • test case for send request

reviewer note

consider running bundle tests against build
consider refactoring opportunities
theres a high chance of future inconsistency with hidden window implementation

future work

  • post request
  • abstract into common implementation?
  • remove hidden-window implementation? could be a heavy lift due to async implementation, perhaps not for @ihexxa

closes INS-4144


const evalInterceptor = (script: string) => {
invariant(script && typeof script === 'string', 'eval is called with invalid or empty value');
const result = eval(script);

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: javascript.browser.security.eval-detected.eval-detected

Detected the use of eval(). eval() can be dangerous if used to evaluate dynamic content. If this content can be input from outside the program, this may be a code injection vulnerability. Ensure evaluated content is not definable by external sources.
filfreire
filfreire previously approved these changes Aug 2, 2024
@jackkav jackkav marked this pull request as draft August 5, 2024 10:28
@jackkav jackkav marked this pull request as ready for review August 5, 2024 10:44
filfreire
filfreire previously approved these changes Aug 5, 2024
@jackkav
Copy link
Contributor Author

jackkav commented Aug 26, 2024

The major contention of this pass

  • chance of drift in hidden window context implementation
  • slightly different execution context due to the promise handling

My preference would be to use matching execution contexts so that cli task execution results would always match the UI.
That would mean removing the hidden window executor and using a nodejs executor for both.

Copy link
Contributor

@ihexxa ihexxa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first seems working and just have some minor comments.

}
expect(result.code).toBe(0);
describe('exit codes are consistent', () => {
it.each(shouldReturnSuccessCode)('exit code should be 0: %p', async input => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Table driven test looks pretty neat.

}
});

// This function is duplicated in scriptExecutor.ts to run in nodejs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to consider this after the executing mechanism in the CLI side has been proved working well.

@jackkav jackkav force-pushed the cli-script-first-pass branch from 9e72cf4 to 68a2002 Compare August 27, 2024 09:23
@jackkav jackkav enabled auto-merge (squash) August 27, 2024 09:30
@jackkav jackkav merged commit 02f5bf4 into Kong:develop Aug 27, 2024
@jackkav jackkav deleted the cli-script-first-pass branch August 27, 2024 09:36
@jackkav jackkav mentioned this pull request Jul 29, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants