Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: quotes are escaped #432

Closed
wants to merge 1 commit into from
Closed

Conversation

sezanzeb
Copy link

@sezanzeb sezanzeb commented Apr 8, 2022

Proposed Changes

Just adds a single test. I was investigating how to use flux but couldn't see if this escapes and prevents injection attacks.

Checklist

  • CHANGELOG.md updated < I guess adding a test isn't really something worth mentioning there
  • Rebased/mergeable < I guess so?
  • A test has been added if appropriate
  • yarn test completes successfully
  • Commit messages are in semantic format
  • Sign CLA (if not already signed) < Dude, just take it or leave it. I'm not interested in spending an hour trying to decipher this legal lingo for this. I don't care about having any rights about those 8 lines of code or whatever. I give this to you.

@sezanzeb sezanzeb changed the title added test to check if quotes are escaped @sezanzeb test: quotes are escaped Apr 8, 2022
@sezanzeb sezanzeb changed the title @sezanzeb test: quotes are escaped test: quotes are escaped Apr 8, 2022
@sranka sranka self-requested a review April 8, 2022 18:27
Copy link
Contributor

@sranka sranka left a comment

Choose a reason for hiding this comment

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

Thank @sezanzeb you for a PR, but I think that your changes do not bring any additional value to this library. The flux tagged template is designed exactly for the purpose that you double-checked, it is properly documented this way in https://influxdata.github.io/influxdb-client-js/influxdb-client.flux.html . All the possible value types and escape sequences are already tested thoroughly in flux.test.ts. A possible (but not a necessary improvement) would be to add

        if (pair.value !== undefined) {
          expect(flux`${pair.value}`.toString()).equals(pair.flux)
        } else {
          expect(() => flux`${pair.value}`.toString()).to.throw(
            "Unsupported parameter literal 'undefined' at index: 0, type: undefined"
          )
        }

right after

https://github.com/influxdata/influxdb-client-js/blob/master/packages/core/test/unit/query/flux.test.ts#L119

it will then extra test all parameter types and escape sequences within the flux tagged template.

@sezanzeb
Copy link
Author

sezanzeb commented Apr 8, 2022

The only test that uses doubles quotes in flux is:

  it('processes a simple nested flux template', () => {
    const flux1 = flux`from(bucket:"my-bucket")`
    expect(flux`${flux1} |> range(start: ${0})")`.toString()).equals(
      'from(bucket:"my-bucket") |> range(start: 0)")'
    )
  })

but it is different. The new test that I added tries to insert a string containing a double-quote into another set of double-quotes in the target. There is no test that expects an escaped double-quote: \"

or what am I missing here?

There just isn't a test that makes sure that a user-defined string (like foo"bar) is not breaking the command

@sranka
Copy link
Contributor

sranka commented Apr 9, 2022

Thank you for your feedback.

@sranka sranka closed this Apr 9, 2022
@bednar bednar added this to the 1.25.0 milestone Apr 14, 2022
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.

None yet

3 participants