feat(rekognition): add Amazon Rekognition sync image-analysis actions (#2706)

* feat(rekognition): add Amazon Rekognition sync image-analysis actions

Implements DetectLabels, DetectFaces, DetectText, CompareFaces, and
DetectModerationLabels as fixed AWS-shaped stub responses over the
real JSON 1.1 wire protocol (X-Amz-Target: RekognitionService.*).
Image/SourceImage/TargetImage input is required and validated (must
specify Bytes or S3Object) but never decoded, matching the pattern
already used for Textract's Document input.

Content-listing operations (DetectLabels, DetectText) always return
one canned entry, matching TextractService's stub precedent. Face and
moderation operations (DetectFaces, CompareFaces,
DetectModerationLabels) return empty results by default rather than
fabricating biometric attributes or a moderation flag for content
that was never analyzed, matching ComprehendService's PII-detection
precedent.

Face-collection persistence, custom-model training, live video
(StreamProcessor), async video jobs, and Face Liveness sessions are
out of scope for this PR.

Closes #2705

* fix(rekognition): reject wrong-typed Bytes/S3Object as SerializationException

requireImage() only checked field presence via hasNonNull(), so a
wrong-typed Bytes (e.g. a number) or S3Object (e.g. a string) was
silently accepted instead of rejected, same class of bug as the
Comprehend Text/LanguageCode type-coercion fix. Bytes must now be
textual and S3Object must be an object when present, both rejected
as SerializationException (a shape/marshalling mismatch) otherwise.

Content-level validation (well-formed base64 in Bytes, S3Object's
Bucket/Name presence, rejecting both Bytes and S3Object together) is
intentionally not added: S3Object has no required members in AWS's
own model, and nothing in the model declares supplying both fields
invalid — documented as intentional deviations.

Addresses review feedback on #2706.
This commit is contained in:
Ahmed khaled authored and GitHub committed 2026-08-29 14:15:52 -04:00
1 parent 5600d21f32
commit cf6fede453
13 files changed
+543 -4

No files matched your search

@@ -0,0 +1,205 @@
package io.github.hectorvent.floci.services.rekognition;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
/**
* Integration tests for the Amazon Rekognition stub.
* Validates AWS-compatible wire format using RestAssured.
* Protocol: JSON 1.1 — Content-Type: application/x-amz-json-1.1, X-Amz-Target: RekognitionService.<Action>
*/
@QuarkusTest
class RekognitionIntegrationTest {
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/rekognition/aws4_request";
private static final String S3_IMAGE =
"{\"S3Object\":{\"Bucket\":\"my-bucket\",\"Name\":\"photo.jpg\"}}";
@Test
void detectLabels_returnsStubLabel() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":" + S3_IMAGE + "}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Labels", hasSize(1))
.body("Labels[0].Name", equalTo("Floci"))
.body("Labels[0].Confidence", notNullValue())
.body("LabelModelVersion", equalTo("1.0"));
}
@Test
void detectLabels_missingImage_returns400() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterException"));
}
@Test
void detectLabels_imageWithoutBytesOrS3Object_returns400() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":{}}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterException"));
}
@Test
void detectLabels_nonObjectImage_returnsSerializationException() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":\"banana\"}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void detectLabels_nonStringBytes_returnsSerializationException() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":{\"Bytes\":12345}}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void detectLabels_nonObjectS3Object_returnsSerializationException() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":{\"S3Object\":\"not-an-object\"}}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void detectLabels_bothBytesAndS3ObjectAccepted() {
// Neither field's content is read, and nothing in the Rekognition model
// declares supplying both invalid.
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":{\"Bytes\":\"aGVsbG8=\",\"S3Object\":{\"Bucket\":\"my-bucket\",\"Name\":\"photo.jpg\"}}}")
.when()
.post("/")
.then()
.statusCode(200)
.body("Labels", hasSize(1));
}
@Test
void detectFaces_returnsEmptyFaceDetails() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectFaces")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":" + S3_IMAGE + "}")
.when()
.post("/")
.then()
.statusCode(200)
.body("FaceDetails", hasSize(0));
}
@Test
void detectText_returnsLineAndWordDetections() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectText")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":" + S3_IMAGE + "}")
.when()
.post("/")
.then()
.statusCode(200)
.body("TextDetections", hasSize(2))
.body("TextDetections.Type", hasItems("LINE", "WORD"))
.body("TextDetections.findAll { it.Type == 'LINE' }.DetectedText", hasItem("Floci"))
.body("TextDetections[0].Geometry.BoundingBox.Width", notNullValue())
.body("TextDetections[0].Geometry.Polygon", hasSize(4))
.body("TextModelVersion", equalTo("1.0"));
}
@Test
void compareFaces_returnsEmptyMatches() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.CompareFaces")
.header("Authorization", AUTH_HEADER)
.body("{\"SourceImage\":" + S3_IMAGE + ",\"TargetImage\":" + S3_IMAGE + "}")
.when()
.post("/")
.then()
.statusCode(200)
.body("FaceMatches", hasSize(0))
.body("UnmatchedFaces", hasSize(0));
}
@Test
void compareFaces_missingTargetImage_returns400() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.CompareFaces")
.header("Authorization", AUTH_HEADER)
.body("{\"SourceImage\":" + S3_IMAGE + "}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterException"));
}
@Test
void detectModerationLabels_returnsEmptyLabels() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.DetectModerationLabels")
.header("Authorization", AUTH_HEADER)
.body("{\"Image\":" + S3_IMAGE + "}")
.when()
.post("/")
.then()
.statusCode(200)
.body("ModerationLabels", hasSize(0))
.body("ModerationModelVersion", equalTo("1.0"));
}
@Test
void unknownAction_returnsUnknownOperationError() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "RekognitionService.IndexFaces")
.header("Authorization", AUTH_HEADER)
.body("{}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("UnknownOperationException"));
}
}