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

Check for additionalProperties to be set to false #87

Merged
merged 3 commits into from
Aug 25, 2022

Conversation

shapirone
Copy link
Collaborator

@shapirone shapirone commented Aug 24, 2022

Summary

The backend defaults additionalProperties on parameters of the object type to true, so this PR inverts the check to see if they are explicitly setting additionalProperties to false.

Testing

  1. Create an object parameter as a function input or output
  2. Verify that at both workflow authoring time and at runtime, you're able to access unexpected properties.
  3. Change the object parameters you created to set additionalProperties: false
  4. Notice that your access of unexpected properties now results in errors.
anObject: {
        type: Schema.types.object,
        properties: {
            test: { type: Schema.types.string },
        },
        additionalProperties: false,
      },

Requirements (place an x in each [ ])

@shapirone shapirone marked this pull request as ready for review August 24, 2022 23:36
@shapirone shapirone requested a review from a team as a code owner August 24, 2022 23:36
@@ -76,6 +76,7 @@ export type BlockActionsBody = {
id: string;
/**
* @description User's handle as seen in the Slack client when e.g. at-notifying the user.
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was an issue here where we weren't closing the comment, which meant that name wasn't part of the BlockActionsBody defined payload. This is unrelated to the core of this PR and can be removed if we want.

@codecov
Copy link

codecov bot commented Aug 24, 2022

Codecov Report

Merging #87 (855ef1a) into main (fc7d614) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main      #87   +/-   ##
=======================================
  Coverage   96.10%   96.10%           
=======================================
  Files          41       41           
  Lines        1565     1565           
  Branches       87       87           
=======================================
  Hits         1504     1504           
  Misses         59       59           
  Partials        2        2           
Impacted Files Coverage Δ
src/parameters/mod.ts 93.42% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

assertExists(result.outputs?.noAddlPropertiesObj);
assertExists(result.outputs?.noAddlPropertiesObj.aString);

// @ts-expect-error anythingElse cant exist
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure there's a better way to do this type of test, but if this directive becomes unused (i.e. no error), it will let us know!

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL

Comment on lines +102 to +106
& {
[k in keyof Param["properties"]]: FunctionInputRuntimeType<
Param["properties"][k]
>;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could probably figure out some way to avoid this duplication, but I didn't want to spend too much time on this. Open to suggestions.

Copy link
Contributor

@selfcontained selfcontained left a comment

Choose a reason for hiding this comment

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

beautiful, works as described.

assertExists(result.outputs?.noAddlPropertiesObj);
assertExists(result.outputs?.noAddlPropertiesObj.aString);

// @ts-expect-error anythingElse cant exist
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL

@shapirone shapirone merged commit 1245b73 into main Aug 25, 2022
@shapirone shapirone deleted the neil-always-addl-props branch August 25, 2022 16:43
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

2 participants