snapd icon indicating copy to clipboard operation
snapd copied to clipboard

cmd/snap: fix JSON keys not being validated on snap set -t

Open locnnil opened this issue 1 year ago • 6 comments

When passing JSON in the snap set -t command, the keys were not being validated.

  • Add: Reusable function to validate snap set keys
  • tests: Write tests to demonstrate functionality
  • fixes: https://bugs.launchpad.net/snapd/+bug/2072331

locnnil avatar Jul 08 '24 11:07 locnnil

@zyga - I was wrong in my comment about the boolean stuff, but when I saw these results of the unit tests, I realized that I wasn't just wrong; I was hugely wrong. So as it can be many possible types, I decide to just check if it's the type that I'm interested: map[string]interface{}

@olivercalder - It's interested that you pointed my attention to this value type validation, because I could realize that I wasn't checking for this edge case: When the value type is: []interface{} what means that the user passed an JSON that contains an array in one of its objects, now my previous commit adds the logic to handle this. Thank you very much.

locnnil avatar Jul 09 '24 20:07 locnnil

@olivercalder I suspect that the access denied error comes from the fact that when testing "happy" cases, the mocking structure for the API server reaches its limit.

Because, it happens when I tried to use ParseArgs for testing happy cases, and also happens when some unhappy case also using ParseArgs fail to trigger an error.

locnnil avatar Jul 17 '24 02:07 locnnil

Since this commit, a conflict has been introduced because the logic for this execution was moved to another function. I will rebase my changes on top of the master branch, but for now, please consider this a draft.

locnnil avatar Jul 23 '24 11:07 locnnil

Sorry for the delay, now it's ready again! :)

locnnil avatar Jul 31 '24 22:07 locnnil

Hello! @olivercalder, @andrewphelpsj this is ready for review now!

locnnil avatar Aug 05 '24 11:08 locnnil

@andrewphelpsj, @bboozzoo, @olivercalder, do you have any additional reviews or feedback on this?

locnnil avatar Aug 22 '24 11:08 locnnil