Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedoublev committed Sep 16, 2024
1 parent a5af79a commit 4234c84
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 50 deletions.
18 changes: 10 additions & 8 deletions e2e/attributes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ setup_file() {
# Create the namespace to be used by other tests

export NS_NAME="testing-attr.co"
export NS_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
NS_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
export NS_ID
}

# always create a randomly named attribute
Expand All @@ -23,18 +24,19 @@ setup() {
run sh -c "./otdfctl $HOST $WITH_CREDS policy attributes $*"
}

export ATTR_NAME_RANDOM=$(LC_ALL=C tr -dc 'a-zA-Z' < /dev/urandom | head -c 16)
export ATTR_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes create --namespace "$NS_ID" --name "$ATTR_NAME_RANDOM" --rule ANY_OF -l key=value --json | jq -r '.id')
ATTR_NAME_RANDOM=$(LC_ALL=C tr -dc 'a-zA-Z' < /dev/urandom | head -c 16)
ATTR_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes create --namespace "$NS_ID" --name "$ATTR_NAME_RANDOM" --rule ANY_OF -l key=value --json | jq -r '.id')
export ATTR_NAME_RANDOM ATTR_ID
}

# always unsafely delete the created attribute
teardown() {
./otdfctl $HOST $WITH_CREDS policy attributes unsafe delete --force --id "$ATTR_ID"
./otdfctl "$HOST" "$WITH_CREDS" policy attributes unsafe delete --force --id "$ATTR_ID"
}

teardown_file() {
# remove the namespace
./otdfctl $HOST $WITH_CREDS policy attributes namespaces unsafe delete --id "$NS_ID" --force
./otdfctl "$HOST" "$WITH_CREDS" policy attributes namespaces unsafe delete --id "$NS_ID" --force

# clear out all test env vars
unset HOST WITH_CREDS NS_NAME NS_ID ATTR_NAME_RANDOM
Expand Down Expand Up @@ -92,13 +94,13 @@ teardown_file() {
# replace labels
run_otdfctl_attr update --force-replace-labels -l key=somethingElse --id "$ATTR_ID" --json
assert_success
[ "$(echo $output | jq -r '.metadata.labels.key')" = "somethingElse" ]
[ "$(echo "$output" | jq -r '.metadata.labels.key')" = "somethingElse" ]

# extend labels
run_otdfctl_attr update -l other=testing --id "$ATTR_ID" --json
assert_success
[ "$(echo $output | jq -r '.metadata.labels.other')" = "testing" ]
[ "$(echo $output | jq -r '.metadata.labels.key')" = "somethingElse" ]
[ "$(echo "$output" | jq -r '.metadata.labels.other')" = "testing" ]
[ "$(echo "$output" | jq -r '.metadata.labels.key')" = "somethingElse" ]
}

@test "Update an attribute definition (Safe) - Bad" {
Expand Down
8 changes: 4 additions & 4 deletions e2e/encrypt-decrypt.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ setup_file() {
export OUT_TXT=secret.txt
export OUTFILE_TXT=secret.txt.tdf

NS_ID=$(./otdfctl --host $HOST $WITH_CREDS $DEBUG_LEVEL policy attributes namespaces create -n "testing-enc-dec.io" --json | jq -r '.id')
ATTR_ID=$(./otdfctl --host $HOST $WITH_CREDS $DEBUG_LEVEL policy attributes create --namespace "$NS_ID" -n attr1 -r ALL_OF --json | jq -r '.id')
VAL_ID=$(./otdfctl --host $HOST $WITH_CREDS $DEBUG_LEVEL policy attributes values create --attribute-id "$ATTR_ID" -v value1 --json | jq -r '.id')
NS_ID=$(./otdfctl --host "$HOST" "$WITH_CREDS" $DEBUG_LEVEL policy attributes namespaces create -n "testing-enc-dec.io" --json | jq -r '.id')
ATTR_ID=$(./otdfctl --host "$HOST" "$WITH_CREDS" $DEBUG_LEVEL policy attributes create --namespace "$NS_ID" -n attr1 -r ALL_OF --json | jq -r '.id')
VAL_ID=$(./otdfctl --host "$HOST" "$WITH_CREDS" $DEBUG_LEVEL policy attributes values create --attribute-id "$ATTR_ID" -v value1 --json | jq -r '.id')
# entitles opentdf client id for client credentials CLI user
SCS='[{"condition_groups":[{"conditions":[{"operator":1,"subject_external_values":["opentdf"],"subject_external_selector_value":".clientId"}],"boolean_operator":2}]}]'
SM=$(./otdfctl --host $HOST $WITH_CREDS $DEBUG_LEVEL policy subject-mappings create --action-standard DECRYPT -a "$VAL_ID" --subject-condition-set-new "$SCS")
SM=$(./otdfctl --host "$HOST" "$WITH_CREDS" $DEBUG_LEVEL policy subject-mappings create --action-standard DECRYPT -a "$VAL_ID" --subject-condition-set-new "$SCS")
export FQN="https://testing-enc-dec.io/attr/attr1/value/value1"
export MIXED_CASE_FQN="https://Testing-Enc-Dec.io/attr/Attr1/value/VALUE1"
}
Expand Down
7 changes: 4 additions & 3 deletions e2e/kas-grants.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ setup_file() {
export HOST='--host http://localhost:8080'

export KAS_URI="https://e2etestkas.com"
export KAS_ID=$(./otdfctl $HOST $WITH_CREDS policy kas-registry create --uri "$KAS_URI" --public-key-remote 'https://e2etestkas.com/pub_key' --json | jq -r '.id')
KAS_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy kas-registry create --uri "$KAS_URI" --public-key-remote 'https://e2etestkas.com/pub_key' --json | jq -r '.id')
export KAS_ID_FLAG="--kas-id $KAS_ID"

export NS_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes namespaces create -n "testing-kasg.uk" --json | jq -r '.id')
ATTR=$(./otdfctl $HOST $WITH_CREDS policy attributes create -n "attr1" --json --rule ANY_OF --namespace "$NS_ID" -v "val1")
NS_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes namespaces create -n "testing-kasg.uk" --json | jq -r '.id')
ATTR=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes create -n "attr1" --json --rule ANY_OF --namespace "$NS_ID" -v "val1")
export ATTR_ID=$(echo $ATTR | jq -r '.id')
export VAL_ID=$(echo $ATTR | jq -r '.values[0].id')
export NS_ID KAS_ID
}

setup() {
Expand Down
2 changes: 1 addition & 1 deletion e2e/kas-registry.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ setup() {

# invoke binary with credentials
run_otdfctl_kasr () {
run sh -c "./otdfctl policy kas-registry $HOST $WITH_CREDS $*"
run sh -c "./otdfctl policy kas-registry "$HOST" "$WITH_CREDS" $*"
}
}

Expand Down
31 changes: 16 additions & 15 deletions e2e/namespaces.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ setup_file() {

export NS_NAME="creating-test-ns.net"
export NS_NAME_UPDATE="updated-test-ns.net"
export NS_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
NS_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
export NS_ID
export NS_ID_FLAG="--id $NS_ID"
}

Expand Down Expand Up @@ -87,13 +88,13 @@ teardown_file() {

@test "List namespaces - when active" {
run_otdfctl_ns list --json
echo $output | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)'
echo "$output" | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)'

run_otdfctl_ns list --state inactive --json
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"

run_otdfctl_ns list --state active
echo $output | assert_output --partial "$NS_ID"
echo "$output" | assert_output --partial "$NS_ID"
}

@test "Update namespace - Safe" {
Expand Down Expand Up @@ -133,20 +134,20 @@ teardown_file() {

@test "List namespaces - when inactive" {
run_otdfctl_ns list --json
echo $output | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)'
echo "$output" | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)'

# json
run_otdfctl_ns list --state inactive --json
echo $output | assert_output --partial "$NS_ID"
echo "$output" | assert_output --partial "$NS_ID"

run_otdfctl_ns list --state active --json
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"
# table
run_otdfctl_ns list --state inactive
echo $output | assert_output --partial "$NS_ID"
echo "$output" | assert_output --partial "$NS_ID"

run_otdfctl_ns list --state active
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"
}

@test "Unsafe reactivate namespace" {
Expand All @@ -157,13 +158,13 @@ teardown_file() {

@test "List namespaces - when reactivated" {
run_otdfctl_ns list --json
echo $output | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)'
echo "$output" | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)'

run_otdfctl_ns list --state inactive --json
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"

run_otdfctl_ns list --state active
echo $output | assert_output --partial "$NS_ID"
echo "$output" | assert_output --partial "$NS_ID"
}

@test "Unsafe delete namespace" {
Expand All @@ -175,11 +176,11 @@ teardown_file() {

@test "List namespaces - when deleted" {
run_otdfctl_ns list --json
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"

run_otdfctl_ns list --state inactive --json
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"

run_otdfctl_ns list --state active
echo $output | refute_output --partial "$NS_ID"
echo "$output" | refute_output --partial "$NS_ID"
}
39 changes: 20 additions & 19 deletions e2e/subject-mapping.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ setup_file() {

# Create two namespaced values to be used in other tests
NS_NAME="subject-mappings.net"
export NS_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
ATTR_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes create --namespace "$NS_ID" --name attr1 --rule ANY_OF --json | jq -r '.id')
export VAL1_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes values create --attribute-id "$ATTR_ID" --value val1 --json | jq -r '.id')
export VAL2_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes values create --attribute-id "$ATTR_ID" --value value2 --json | jq -r '.id')
NS_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes namespaces create -n "$NS_NAME" --json | jq -r '.id')
ATTR_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes create --namespace "$NS_ID" --name attr1 --rule ANY_OF --json | jq -r '.id')
VAL1_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes values create --attribute-id "$ATTR_ID" --value val1 --json | jq -r '.id')
VAL2_ID=$(./otdfctl "$HOST" "$WITH_CREDS" policy attributes values create --attribute-id "$ATTR_ID" --value value2 --json | jq -r '.id')
export NS_ID VAL1_ID VAL2_ID

export SCS_1='[{"condition_groups":[{"conditions":[{"operator":1,"subject_external_values":["ShinyThing"],"subject_external_selector_value":".team.name"},{"operator":2,"subject_external_values":["marketing"],"subject_external_selector_value":".org.name"}],"boolean_operator":1}]}]'
export SCS_2='[{"condition_groups":[{"conditions":[{"operator":2,"subject_external_values":["CoolTool","RadService"],"subject_external_selector_value":".team.name"},{"operator":1,"subject_external_values":["sales"],"subject_external_selector_value":".org.name"}],"boolean_operator":2}]}]'
Expand All @@ -31,14 +32,14 @@ setup() {

teardown_file() {
# remove the created namespace with all underneath upon test suite completion
./otdfctl $HOST $WITH_CREDS policy attributes namespaces unsafe delete --force --id "$NS_ID"
./otdfctl "$HOST" "$WITH_CREDS" policy attributes namespaces unsafe delete --force --id "$NS_ID"

unset HOST WITH_CREDS VAL1_ID VAL2_ID NS_ID SCS_1 SCS_2
}

@test "Create subject mapping" {
# create with simultaneous new SCS
run ./otdfctl $HOST $WITH_CREDS policy subject-mappings create -a "$VAL1_ID" -s TRANSMIT --action-standard DECRYPT --subject-condition-set-new "$SCS_2"
run ./otdfctl "$HOST" "$WITH_CREDS" policy subject-mappings create -a "$VAL1_ID" -s TRANSMIT --action-standard DECRYPT --subject-condition-set-new "$SCS_2"
assert_success
assert_output --partial "Subject Condition Set: Id"
assert_output --partial '"Standard":1'
Expand All @@ -58,8 +59,8 @@ assert_output --regexp "Attribute Value Id.*$VAL1_ID"
}

@test "Get subject mapping" {
new_scs=$(./otdfctl $HOST $WITH_CREDS policy scs create -s "$SCS_2" --json | jq -r '.id')
created=$(./otdfctl $HOST $WITH_CREDS policy sm create -a "$VAL2_ID" -s TRANSMIT --subject-condition-set-id "$new_scs" --json | jq -r '.id')
new_scs=$(./otdfctl "$HOST" "$WITH_CREDS" policy scs create -s "$SCS_2" --json | jq -r '.id')
created=$(./otdfctl "$HOST" "$WITH_CREDS" policy sm create -a "$VAL2_ID" -s TRANSMIT --subject-condition-set-id "$new_scs" --json | jq -r '.id')
# table
run_otdfctl_sm get --id "$created"
assert_success
Expand All @@ -71,38 +72,38 @@ assert_output --regexp "Attribute Value Id.*$VAL1_ID"
# json
run_otdfctl_sm get --id "$created" --json
assert_success
[ "$(echo $output | jq -r '.id')" = "$created" ]
[ "$(echo $output | jq -r '.attribute_value.id')" = "$VAL2_ID" ]
[ "$(echo $output | jq -r '.subject_condition_set.id')" = "$new_scs" ]
[ "$(echo "$output" | jq -r '.id')" = "$created" ]
[ "$(echo "$output" | jq -r '.attribute_value.id')" = "$VAL2_ID" ]
[ "$(echo "$output" | jq -r '.subject_condition_set.id')" = "$new_scs" ]
}

@test "Update a subject mapping" {
created=$(./otdfctl $HOST $WITH_CREDS policy sm create -a "$VAL1_ID" -s DECRYPT --subject-condition-set-new "$SCS_1" --json | jq -r '.id')
additional_scs=$(./otdfctl $HOST $WITH_CREDS policy scs create -s "$SCS_2" --json | jq -r '.id')
created=$(./otdfctl "$HOST" "$WITH_CREDS" policy sm create -a "$VAL1_ID" -s DECRYPT --subject-condition-set-new "$SCS_1" --json | jq -r '.id')
additional_scs=$(./otdfctl "$HOST" "$WITH_CREDS" policy scs create -s "$SCS_2" --json | jq -r '.id')

# replace the action (always destructive replacement)
run_otdfctl_sm update --id "$created" -s TRANSMIT --json
assert_success
[ "$(echo $output | jq -r '.id')" = "$created" ]
[ "$(echo $output | jq -r '.actions[0].Value.Standard')" = 2 ]
[ "$(echo "$output" | jq -r '.id')" = "$created" ]
[ "$(echo "$output" | jq -r '.actions[0].Value.Standard')" = 2 ]

# reassign the SCS being mapped to
run_otdfctl_sm update --id "$created" --subject-condition-set-id "$additional_scs" --json
assert_success
[ "$(echo $output | jq -r '.id')" = "$created" ]
[ "$(echo $output | jq -r '.subject_condition_set.id')" = "$additional_scs" ]
[ "$(echo "$output" | jq -r '.id')" = "$created" ]
[ "$(echo "$output" | jq -r '.subject_condition_set.id')" = "$additional_scs" ]
}

@test "List subject mappings" {
created=$(./otdfctl $HOST $WITH_CREDS policy sm create -a "$VAL1_ID" -s TRANSMIT --subject-condition-set-new "$SCS_2" --json | jq -r '.id')
created=$(./otdfctl "$HOST" "$WITH_CREDS" policy sm create -a "$VAL1_ID" -s TRANSMIT --subject-condition-set-new "$SCS_2" --json | jq -r '.id')

run_otdfctl_sm list
assert_success
assert_output --partial "$created"
}

@test "Delete subject mapping" {
first_listed=$(./otdfctl $HOST $WITH_CREDS policy sm list --json | jq -r '.[0].id')
first_listed=$(./otdfctl "$HOST" "$WITH_CREDS" policy sm list --json | jq -r '.[0].id')
# --force to avoid indefinite hang waiting for confirmation
run_otdfctl_sm delete --id "$first_listed" --force
assert_success
Expand Down

0 comments on commit 4234c84

Please sign in to comment.