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

[BUG] fromjson fails with a string sourcefield value #164

Closed
pbq opened this issue Aug 19, 2022 · 2 comments
Closed

[BUG] fromjson fails with a string sourcefield value #164

pbq opened this issue Aug 19, 2022 · 2 comments

Comments

@pbq
Copy link
Collaborator

pbq commented Aug 19, 2022

hello,
with pimo 1.14.0

this venom test is failling

- name: fromjson sourcefield with string value
  steps:
    - script: rm -rf masking.yml
    - script: |-
        cat > masking.yml <<EOF
        version: "1"
        masking:
          - selector:
              jsonpath: "targetfield"
            mask:
              fromjson: "sourcefield"
        EOF
        echo '{"sourcefield": "value"}' | pimo
      assertions:
        - result.code ShouldEqual 0
        - result.systemout ShouldEqual {"sourcefield":"value","targetfield":"value"}
        - result.systemerr ShouldBeEmpty

as far as i understand the fromjson mask, it works if sourcefield's type is bool, float but not if its a string.

@youen
Copy link
Member

youen commented Aug 19, 2022

fromjson mask try to parse field content as a JSON value.

a valid JSON value must be :

  • a number ex : 3.14, -1 , 42
  • a boolean ex : true, false
  • a string ex : "I am a string with double quotes at the beginning and at the end "
  • an array ex : [1,2,3]
  • a dictionary ex : { "key" : "value"}

Your test should be :

- name: fromjson sourcefield with string value
  steps:
    - script: rm -rf masking.yml
    - script: |-
        cat > masking.yml <<EOF
        version: "1"
        masking:
          - selector:
              jsonpath: "targetfield"
            mask:
              fromjson: "sourcefield"
        EOF
        echo '{"sourcefield": "\"value\""}' | pimo
      assertions:
        - result.code ShouldEqual 0
        - result.systemout ShouldEqual {"sourcefield":"\"value\"","targetfield":"value"}
        - result.systemerr ShouldBeEmpty

@pbq
Copy link
Collaborator Author

pbq commented Aug 22, 2022

thank you @youen, i added some escaped double quotes in my dataset and the fromjson mask is working now ;)

@pbq pbq closed this as completed Aug 22, 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

No branches or pull requests

2 participants