Skip to content

Commit 7f6d62f

Browse files
whummerclaude
andcommitted
add test for AppSync Evaluate* operations in read-only mode
Test that EvaluateCode and EvaluateMappingTemplate are correctly identified as read operations and work with read_only proxy config. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4eb9a05 commit 7f6d62f

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

aws-proxy/tests/proxy/test_appsync.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,77 @@ def test_appsync_readonly_mode(
234234
assert local_api_id not in aws_api_ids
235235

236236

237+
def test_appsync_readonly_evaluate_operations(
238+
start_aws_proxy, appsync_client_aws, create_graphql_api_aws
239+
):
240+
"""Test that EvaluateCode and EvaluateMappingTemplate work in read-only proxy mode.
241+
242+
These operations are functionally read-only (they evaluate code/templates without
243+
modifying state) but don't follow the standard Describe*/Get*/List* naming convention.
244+
This test ensures they are correctly identified as read operations.
245+
"""
246+
# Start proxy in read-only mode
247+
config = ProxyConfig(services={"appsync": {"resources": ".*", "read_only": True}})
248+
start_aws_proxy(config)
249+
250+
# Create clients
251+
appsync_client = connect_to().appsync
252+
253+
# EvaluateCode - test with a simple APPSYNC_JS function
254+
# This should work in read-only mode since it's a read operation
255+
code = """
256+
export function request(ctx) {
257+
return { version: "2018-05-29", payload: ctx.arguments };
258+
}
259+
export function response(ctx) {
260+
return ctx.result;
261+
}
262+
"""
263+
context = '{"arguments": {"id": "123", "name": "test"}, "result": {"success": true}}'
264+
265+
evaluate_code_response = appsync_client.evaluate_code(
266+
runtime={"name": "APPSYNC_JS", "runtimeVersion": "1.0.0"},
267+
code=code,
268+
context=context,
269+
function="request",
270+
)
271+
272+
# Verify the response - EvaluateCode should return evaluation result
273+
assert "evaluationResult" in evaluate_code_response
274+
# The error field should be None or not present for successful evaluation
275+
assert evaluate_code_response.get("error") is None
276+
277+
# Compare with direct AWS call to verify proxy is forwarding correctly
278+
evaluate_code_response_aws = appsync_client_aws.evaluate_code(
279+
runtime={"name": "APPSYNC_JS", "runtimeVersion": "1.0.0"},
280+
code=code,
281+
context=context,
282+
function="request",
283+
)
284+
assert evaluate_code_response_aws.get("error") is None
285+
286+
# EvaluateMappingTemplate - test with a simple VTL template
287+
# This should also work in read-only mode
288+
template = '{"version": "2018-05-29", "payload": $util.toJson($context.arguments)}'
289+
context_vtl = '{"arguments": {"id": "456", "value": "test-value"}}'
290+
291+
evaluate_template_response = appsync_client.evaluate_mapping_template(
292+
template=template,
293+
context=context_vtl,
294+
)
295+
296+
# Verify the response
297+
assert "evaluationResult" in evaluate_template_response
298+
assert evaluate_template_response.get("error") is None
299+
300+
# Compare with direct AWS call
301+
evaluate_template_response_aws = appsync_client_aws.evaluate_mapping_template(
302+
template=template,
303+
context=context_vtl,
304+
)
305+
assert evaluate_template_response_aws.get("error") is None
306+
307+
237308
def test_appsync_operations_filtering(
238309
start_aws_proxy, appsync_client_aws, create_graphql_api_aws
239310
):

0 commit comments

Comments
 (0)