Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions e2e/subject-mapping.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ setup_file() {
export HOST='--host http://localhost:8080'

# 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')
# Names prefixed with SM to avoid conflicts across tests when running in parallel
export SM_VAL1_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes values create --attribute-id "$ATTR_ID" --value val1 --json | jq -r '.id')
export SM_VAL2_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes values create --attribute-id "$ATTR_ID" --value value2 --json | jq -r '.id')
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')
# Names prefixed with SM to avoid conflicts across tests when running in parallel
export SM_VAL1_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes values create --attribute-id "$ATTR_ID" --value val1 --json | jq -r '.id')
export SM_VAL2_ID=$(./otdfctl $HOST $WITH_CREDS policy attributes values create --attribute-id "$ATTR_ID" --value value2 --json | jq -r '.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 Down Expand Up @@ -98,26 +98,29 @@ teardown_file() {
}

@test "Get subject mapping" {
run ./otdfctl $HOST $WITH_CREDS policy sm create -a "$SM_VAL2_ID" --action "custom_sm_action_test" --subject-condition-set-id "$SCS_2_ID" --json
run ./otdfctl $HOST $WITH_CREDS policy sm create -a "$SM_VAL2_ID" --action "custom_sm_action_test" --subject-condition-set-new "$SCS_1" --json
assert_success
created=$(echo "$output" | jq -r '.id')
scs_1_id=$(echo "$output" | jq -r '.subject_condition_set.id')
assert_not_equal "$created" "null"
assert_not_equal "$created" ""
assert_not_equal "$scs_1_id" "null"
assert_not_equal "$scs_1_id" ""

# table
run_otdfctl_sm get --id "$created"
assert_success
assert_line --regexp "Id.*$created"
assert_line --regexp "Attribute Value: Id.*$SM_VAL2_ID"
assert_line --regexp "Attribute Value: Value.*value2"
assert_line --regexp "Subject Condition Set: Id.*$SCS_2_ID"
assert_line --regexp "Subject Condition Set: Id.*$scs_1_id"

# json
run_otdfctl_sm get --id "$created" --json
assert_success
[ "$(echo $output | jq -r '.id')" = "$created" ]
[ "$(echo $output | jq -r '.attribute_value.id')" = "$SM_VAL2_ID" ]
[ "$(echo $output | jq -r '.subject_condition_set.id')" = "$SCS_2_ID" ]
[ "$(echo $output | jq -r '.subject_condition_set.id')" = "$scs_1_id" ]
[ "$(echo $output | jq -r '.actions[0].name')" = "custom_sm_action_test" ]
}

Expand All @@ -136,12 +139,19 @@ teardown_file() {
[ "$(echo $output | jq -r '.actions[0].id')" = "$ACTION_CREATE_ID" ]

# reassign the SCS being mapped to
run_otdfctl_sm update --id "$created" --subject-condition-set-id "$SCS_2_ID" --json
# retry up to 3 times with small backoff for eventual consistency
attempt=0
until [ $attempt -ge 3 ]; do
run_otdfctl_sm update --id "$created" --subject-condition-set-id "$SCS_2_ID" --json
if [ "$status" -eq 0 ]; then
break
fi
attempt=$((attempt+1))
sleep 1
done
assert_success
[ "$(echo $output | jq -r '.id')" = "$created" ]
[ "$(echo $output | jq -r '.subject_condition_set.id')" = "$SCS_2_ID" ]
# Add debug log for DSPX-1873
echo "$output" >&2
[ "$(echo "$output" | jq -r '.id')" = "$created" ]
[ "$(echo "$output" | jq -r '.subject_condition_set.id')" = "$SCS_2_ID" ]
}

@test "List subject mappings" {
Expand Down
Loading