Repository navigation
fix(streams): DescribeStream refuses a Limit below 1 or above 100 #633
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
base: main
Are you sure you want to change the base?
Changes from all commits
b26d1ed
61f3542
e41b5c6
c2a801f
358fb7b
eaba19c
0c97f41
4af9d30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright 2026 ExtendDB contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! `DescribeStream` refuses a `Limit` below 1 together with the other member | ||
| //! constraints before it looks the stream up, and a `Limit` above 100 only | ||
| //! after it has found the stream. | ||
| //! | ||
| //! Measured in us-east-1 with the SDK's own parameter validation switched | ||
| //! off, so the requests reached the service. On 2026-10-22, on an existing | ||
| //! stream: | ||
| //! | ||
| //! ```text | ||
| //! Limit 0 and Limit -1: | ||
| //! 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"} | ||
| //! Limit 101 and Limit 1000: | ||
| //! 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"} | ||
| //! ``` | ||
| //! | ||
| //! On 2026-11-25, each request twice, on a stream of a table that does not | ||
| //! exist: Limit 0 and -1 got the first body above; Limit 1, 101 and 1000, and | ||
| //! Limit 101 with a 36-character `ExclusiveStartShardId`, got 400 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same note as the one above, answered there: the body's table now says 37, and the test comment stays as it is. |
||
| //! `ResourceNotFoundException` "Requested resource not found: Stream: <arn> | ||
| //! not found"; Limit 0 with a 13-character `ExclusiveStartShardId` got the | ||
| //! two clauses in one message ([`SHORT_START_AND_BELOW_ONE`]); Limit 101 with | ||
| //! that start got the start clause alone ([`SHORT_START`]). | ||
| //! | ||
| //! The tests run the handler on the engine's test context over a migrated | ||
| //! in-memory engine, so a request that reaches storage for a missing stream | ||
| //! gets `ResourceNotFoundException`. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use serde_json::json; | ||
|
|
||
| use extenddb_core::error::DynamoDbError; | ||
|
|
||
| use super::handle_describe_stream; | ||
| use crate::OperationContext; | ||
| use crate::partiql::test_context::context; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new tests do not compile without the engine's
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 0c97f41. |
||
|
|
||
| const MISSING: &str = | ||
| "arn:aws:dynamodb:us-east-1:000000000000:table/Missing/stream/2026-10-22T00:00:00.000"; | ||
| const SHORT_ID: &str = "shardId-short"; | ||
| const VALID_ID: &str = "shardId-00000001700000000000-00000000"; | ||
|
|
||
| const BELOW_ONE: &str = "1 validation error detected: Value at 'limit' failed to satisfy \ | ||
| constraint: Member must have value greater than or equal to 1"; | ||
| const ABOVE_MAX: &str = | ||
| "One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"; | ||
| const SHORT_START: &str = "1 validation error detected: Value at 'exclusiveStartShardId' \ | ||
| failed to satisfy constraint: Member must have length greater \ | ||
| than or equal to 28"; | ||
| const SHORT_START_AND_BELOW_ONE: &str = "2 validation errors detected: Value at \ | ||
| 'exclusiveStartShardId' failed to satisfy constraint: Member must have length greater \ | ||
| than or equal to 28; Value at 'limit' failed to satisfy constraint: Member must have \ | ||
| value greater than or equal to 1"; | ||
|
|
||
| /// The answer a row expects. | ||
| enum Answer { | ||
| Refused(&'static str), | ||
| NotFound, | ||
| Served, | ||
| } | ||
|
|
||
| /// The test context over a migrated in-memory engine holding the table | ||
| /// `Orders` with a stream. Returns the context and the stream's ARN. | ||
| async fn context_with_stream() -> (OperationContext, String) { | ||
| let mut ctx = context(None).await; | ||
| let storage = | ||
| extenddb_storage_sqlite::SqliteEngine::new_in_memory("us-east-1", &ctx.account_id, 409_600) | ||
| .await | ||
| .expect("a migrated in-memory engine opens"); | ||
| ctx.storage = Arc::new(storage); | ||
| let created = crate::handle_create_table( | ||
| json!({ | ||
| "TableName": "Orders", | ||
| "AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}], | ||
| "KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}], | ||
| "BillingMode": "PAY_PER_REQUEST", | ||
| "StreamSpecification": {"StreamEnabled": true, "StreamViewType": "KEYS_ONLY"} | ||
| }), | ||
| &ctx, | ||
| ) | ||
| .await | ||
| .expect("the table is created"); | ||
| let arn = created["TableDescription"]["LatestStreamArn"] | ||
| .as_str() | ||
| .expect("the table has a stream") | ||
| .to_owned(); | ||
| (ctx, arn) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn describe_stream_checks_limit_where_the_service_does() { | ||
| let (ctx, existing) = context_with_stream().await; | ||
| let not_found = format!("Requested resource not found: Stream: {MISSING} not found"); | ||
| let rows: [(&str, i64, Option<&str>, Answer); 14] = [ | ||
| (existing.as_str(), 0, None, Answer::Refused(BELOW_ONE)), | ||
| (existing.as_str(), -1, None, Answer::Refused(BELOW_ONE)), | ||
| (existing.as_str(), 101, None, Answer::Refused(ABOVE_MAX)), | ||
| (existing.as_str(), 1000, None, Answer::Refused(ABOVE_MAX)), | ||
| (existing.as_str(), 1, None, Answer::Served), | ||
| (existing.as_str(), 100, None, Answer::Served), | ||
| (MISSING, 0, None, Answer::Refused(BELOW_ONE)), | ||
| (MISSING, -1, None, Answer::Refused(BELOW_ONE)), | ||
| (MISSING, 1, None, Answer::NotFound), | ||
| (MISSING, 101, None, Answer::NotFound), | ||
| (MISSING, 1000, None, Answer::NotFound), | ||
| ( | ||
| MISSING, | ||
| 0, | ||
| Some(SHORT_ID), | ||
| Answer::Refused(SHORT_START_AND_BELOW_ONE), | ||
| ), | ||
| (MISSING, 101, Some(SHORT_ID), Answer::Refused(SHORT_START)), | ||
| (MISSING, 101, Some(VALID_ID), Answer::NotFound), | ||
| ]; | ||
| for (arn, limit, start, expected) in rows { | ||
| let mut body = json!({"StreamArn": arn, "Limit": limit}); | ||
| if let Some(start) = start { | ||
| body["ExclusiveStartShardId"] = json!(start); | ||
| } | ||
| let row = format!("{arn} Limit {limit} start {start:?}"); | ||
| let answer = handle_describe_stream(body, &ctx).await; | ||
| match (answer, expected) { | ||
| (Err(DynamoDbError::ValidationException(m)), Answer::Refused(e)) => { | ||
| assert_eq!(m, e, "{row}"); | ||
| } | ||
| (Err(DynamoDbError::ResourceNotFoundException(m)), Answer::NotFound) => { | ||
| assert_eq!(m, not_found, "{row}"); | ||
| } | ||
| (Ok(v), Answer::Served) => { | ||
| assert_eq!(v["StreamDescription"]["StreamArn"], json!(arn), "{row}"); | ||
| } | ||
| (other, _) => panic!("{row}: got {other:?}"), | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional.
VALID_IDis 37 characters, so this line and the PR body's table say 36 for a 37-character id. The answer is the same at either length.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, you're right. The measured id was
shardId-00000001700000000000-00000000, which is 37 characters, and the body's table now says 37. The test comment stays as it is, because the answer is the same at either length.