Skip to content

Commit 0900a7e

Browse files
committed
update aws_policy_equal.c
1 parent acc6937 commit 0900a7e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/aws_policy_equal/aws_policy_equal.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,28 @@ static cJSON_bool aws_policy_compare_items(const cJSON *a, const cJSON *b, int p
110110
}
111111

112112
// If either is NULL or they have different types, they're not equal
113-
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) {
113+
if ((a == NULL) || (b == NULL)) {
114+
return 0;
115+
}
116+
117+
// Special case for comparing array with single value
118+
if (((a->type & 0xFF) == cJSON_Array && (b->type & 0xFF) == cJSON_String) ||
119+
((a->type & 0xFF) == cJSON_String && (b->type & 0xFF) == cJSON_Array)) {
120+
121+
const cJSON *array = ((a->type & 0xFF) == cJSON_Array) ? a : b;
122+
const cJSON *string = ((a->type & 0xFF) == cJSON_String) ? a : b;
123+
124+
// Only valid if array has exactly one element
125+
if (cJSON_GetArraySize(array) != 1) {
126+
return 0;
127+
}
128+
129+
// Compare the single array element with the string
130+
return aws_policy_compare_items(cJSON_GetArrayItem(array, 0), string, parent_is_unordered);
131+
}
132+
133+
// Normal case - types must match
134+
if ((a->type & 0xFF) != (b->type & 0xFF)) {
114135
return 0;
115136
}
116137

test/aws_policy_equal.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SELECT '5_01', aws_policy_equal(
5454
-- Test for external ID policy example from your conversation
5555
SELECT '6_01', aws_policy_equal(
5656
'{"Version":"2012-10-17","Statement":[{"Condition":{"StringEquals":{"sts:ExternalId":"0000"}},"Action":"sts:AssumeRole","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL"}}]}',
57-
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":["arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL"]},"Action":"sts:AssumeRole","Condition":{"StringEquals":{"sts:ExternalId":"0000"}}}]}'
57+
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL"},"Action":"sts:AssumeRole","Condition":{"StringEquals":{"sts:ExternalId":"0000"}}}]}'
5858
) = 1;
5959

6060
-- Test for complex policy with multiple statements and different ordering

0 commit comments

Comments
 (0)