1313import fixture .s3 .S3HttpFixture ;
1414import fixture .s3 .S3HttpHandler ;
1515
16+ import com .carrotsearch .randomizedtesting .annotations .SuppressForbidden ;
1617import com .carrotsearch .randomizedtesting .annotations .ThreadLeakFilters ;
1718import com .carrotsearch .randomizedtesting .annotations .ThreadLeakScope ;
19+ import com .sun .net .httpserver .HttpExchange ;
1820import com .sun .net .httpserver .HttpHandler ;
1921
2022import org .elasticsearch .ExceptionsHelper ;
4042
4143@ ThreadLeakFilters (filters = { TestContainersThreadFilter .class })
4244@ ThreadLeakScope (ThreadLeakScope .Scope .NONE ) // https://github.com/elastic/elasticsearch/issues/102482
45+ @ SuppressForbidden ("HttpExchange and Headers are ok here" )
4346public class RepositoryS3ConditionalWritesUnsupportedRestIT extends AbstractRepositoryS3RestTestCase {
4447
4548 private static final String PREFIX = getIdentifierPrefix ("RepositoryS3BasicCredentialsRestIT" );
@@ -50,32 +53,46 @@ public class RepositoryS3ConditionalWritesUnsupportedRestIT extends AbstractRepo
5053 private static final String CLIENT = "no_conditional_writes_client" ;
5154
5255 private static final Supplier <String > regionSupplier = new DynamicRegionSupplier ();
56+
5357 private static final S3HttpFixture s3Fixture = new S3HttpFixture (
5458 true ,
5559 BUCKET ,
5660 BASE_PATH ,
5761 fixedAccessKey (ACCESS_KEY , regionSupplier , "s3" )
5862 ) {
5963 @ Override
64+ @ SuppressForbidden ("HttpExchange and Headers are ok here" )
6065 protected HttpHandler createHandler () {
61- final var delegateHandler = asInstanceOf (S3HttpHandler .class , super .createHandler ());
62- return exchange -> {
63- if (exchange .getRequestHeaders ().containsKey ("if-match" ) || exchange .getRequestHeaders ().containsKey ("if-none-match" )) {
64- final var exception = new AssertionError (
65- Strings .format (
66- "unsupported conditional write: [%s] with headers [%s]" ,
67- delegateHandler .parseRequest (exchange ),
68- exchange .getRequestHeaders ()
69- )
70- );
71- ExceptionsHelper .maybeDieOnAnotherThread (exception );
72- throw exception ;
73- }
74- delegateHandler .handle (exchange );
75- };
66+ return new AssertNoConditionalWritesHandler (asInstanceOf (S3HttpHandler .class , super .createHandler ()));
7667 }
7768 };
7869
70+ @ SuppressForbidden ("HttpExchange and Headers are ok here" )
71+ private static class AssertNoConditionalWritesHandler implements HttpHandler {
72+
73+ private final S3HttpHandler delegateHandler ;
74+
75+ private AssertNoConditionalWritesHandler (S3HttpHandler delegateHandler ) {
76+ this .delegateHandler = delegateHandler ;
77+ }
78+
79+ @ Override
80+ public void handle (HttpExchange exchange ) throws IOException {
81+ if (exchange .getRequestHeaders ().containsKey ("if-match" ) || exchange .getRequestHeaders ().containsKey ("if-none-match" )) {
82+ final var exception = new AssertionError (
83+ Strings .format (
84+ "unsupported conditional write: [%s] with headers [%s]" ,
85+ delegateHandler .parseRequest (exchange ),
86+ exchange .getRequestHeaders ()
87+ )
88+ );
89+ ExceptionsHelper .maybeDieOnAnotherThread (exception );
90+ throw exception ;
91+ }
92+ delegateHandler .handle (exchange );
93+ }
94+ }
95+
7996 @ Override
8097 protected Settings extraRepositorySettings () {
8198 return Settings .builder ()
0 commit comments