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

support tests using template-linked policies #150

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

mwhicks1
Copy link
Contributor

@mwhicks1 mwhicks1 commented Jun 6, 2024

Description of changes: Allow the test scripts to take a links file for template-linked policies

Signed-off-by: Mike Hicks <mwhicks@amazon.com>
Comment on lines -52 to 67
if [ -z "$schema" ]
if [ -z "$schema" -a -z "$links" ]
then
IFS=$'\n' read -r -d '' -a tmp_array < <(cedar authorize --policies "$folder/$policies" --entities "$folder/$entities" --request-json "$file" -v && printf '\0')
else
elif [ -z "$links" ]
then
IFS=$'\n' read -r -d '' -a tmp_array < <(cedar authorize --policies "$folder/$policies" --schema "$folder/$schema" --schema-format human --entities "$folder/$entities" --request-json "$file" -v && printf '\0')
else
IFS=$'\n' read -r -d '' -a tmp_array < <(cedar authorize --policies "$folder/$policies" -k "$folder/$links" --schema "$folder/$schema" --schema-format human --entities "$folder/$entities" --request-json "$file" -v && printf '\0')
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

are we missing a case where -z "$schema" but not -z "$links"? just doesn't come up in the current tests?

Might be clearer (and less duplication) to define something like $schema_arg to be either --schema "$folder/$schema" --schema-format human or empty, and likewise $links_arg, and then we can have the command just once and reference $schema_arg and $links_arg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are we missing a case

No because that situation cannot happen: Args come in by order with schema first, links second. So if links is there, then schema must be too.

These are bash functions so I don't know how to make the args by name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, seems good.

I don't know how to make the args by name

I was meaning something like

if [ -z "$schema" ] then schema_arg='' else schema_arg='--schema "$folder/$schema" --schema-format human' fi
if [-z "$links" ] then links_arg='' else links_arg='-k "$folder/$links"' fi
IFS=$'\n' read -r -d '' -a tmp_array < <(cedar authorize ... $schema_arg $links_arg ... -v && printf '\0')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I have stacked commits with other PRs, so I'll fix it after all those are in.

@mwhicks1 mwhicks1 merged commit da322f1 into main Jun 6, 2024
7 checks passed
@cdisselkoen cdisselkoen deleted the support-template-links branch June 6, 2024 16:53
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

4 participants