32
32
33
33
import java .io .IOException ;
34
34
import java .util .Collection ;
35
+ import java .util .List ;
35
36
36
37
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
37
38
import static org .hamcrest .Matchers .hasItem ;
@@ -47,8 +48,16 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
47
48
@ Override
48
49
protected Settings nodeSettings () {
49
50
final var secureSettings = new MockSecureSettings ();
50
- secureSettings .setString (S3ClientSettings .ACCESS_KEY_SETTING .getConcreteSettingForNamespace ("default" ).getKey (), "test_access_key" );
51
- secureSettings .setString (S3ClientSettings .SECRET_KEY_SETTING .getConcreteSettingForNamespace ("default" ).getKey (), "test_secret_key" );
51
+ for (final var clientName : List .of ("default" , "with_purpose" , "without_purpose" )) {
52
+ secureSettings .setString (
53
+ S3ClientSettings .ACCESS_KEY_SETTING .getConcreteSettingForNamespace (clientName ).getKey (),
54
+ randomIdentifier ()
55
+ );
56
+ secureSettings .setString (
57
+ S3ClientSettings .SECRET_KEY_SETTING .getConcreteSettingForNamespace (clientName ).getKey (),
58
+ randomSecretKey ()
59
+ );
60
+ }
52
61
53
62
return Settings .builder ()
54
63
.put (super .nodeSettings ())
@@ -59,6 +68,9 @@ protected Settings nodeSettings() {
59
68
.build ();
60
69
}
61
70
71
+ private static final Matcher <Iterable <? super String >> HAS_CUSTOM_QUERY_PARAMETER = hasItem (S3BlobStore .CUSTOM_QUERY_PARAMETER_PURPOSE );
72
+ private static final Matcher <Iterable <? super String >> NO_CUSTOM_QUERY_PARAMETER = not (HAS_CUSTOM_QUERY_PARAMETER );
73
+
62
74
public void testCustomQueryParameterConfiguration () throws Throwable {
63
75
final var indexName = randomIdentifier ();
64
76
createIndex (indexName );
@@ -67,29 +79,21 @@ public void testCustomQueryParameterConfiguration() throws Throwable {
67
79
final var bucket = randomIdentifier ();
68
80
final var basePath = randomIdentifier ();
69
81
70
- runWithFixture (bucket , basePath , null , Settings .EMPTY , not (hasItem (S3BlobStore .CUSTOM_QUERY_PARAMETER_PURPOSE )));
71
- runWithFixture (bucket , basePath , "without_purpose" , Settings .EMPTY , not (hasItem (S3BlobStore .CUSTOM_QUERY_PARAMETER_PURPOSE )));
72
- runWithFixture (bucket , basePath , "with_purpose" , Settings .EMPTY , hasItem (S3BlobStore .CUSTOM_QUERY_PARAMETER_PURPOSE ));
73
-
74
- runWithFixture (
75
- bucket ,
76
- basePath ,
77
- randomFrom ("with_purpose" , "without_purpose" , null ), // client name doesn't matter if repository setting specified
78
- Settings .builder ().put ("add_purpose_custom_query_parameter" , false ).build (),
79
- not (hasItem (S3BlobStore .CUSTOM_QUERY_PARAMETER_PURPOSE ))
80
- );
81
-
82
- runWithFixture (
83
- bucket ,
84
- basePath ,
85
- randomFrom ("with_purpose" , "without_purpose" , null ), // client name doesn't matter if repository setting specified
86
- Settings .builder ().put ("add_purpose_custom_query_parameter" , true ).build (),
87
- hasItem (S3BlobStore .CUSTOM_QUERY_PARAMETER_PURPOSE )
88
- );
89
-
82
+ runCustomQueryParameterTest (bucket , basePath , null , Settings .EMPTY , NO_CUSTOM_QUERY_PARAMETER );
83
+ runCustomQueryParameterTest (bucket , basePath , "default" , Settings .EMPTY , NO_CUSTOM_QUERY_PARAMETER );
84
+ runCustomQueryParameterTest (bucket , basePath , "without_purpose" , Settings .EMPTY , NO_CUSTOM_QUERY_PARAMETER );
85
+ runCustomQueryParameterTest (bucket , basePath , "with_purpose" , Settings .EMPTY , HAS_CUSTOM_QUERY_PARAMETER );
86
+
87
+ final var falseRepositorySetting = Settings .builder ().put ("add_purpose_custom_query_parameter" , false ).build ();
88
+ final var trueRepositorySetting = Settings .builder ().put ("add_purpose_custom_query_parameter" , true ).build ();
89
+ for (final var clientName : new String [] { null , "default" , "with_purpose" , "without_purpose" }) {
90
+ // client name doesn't matter if repository setting specified
91
+ runCustomQueryParameterTest (bucket , basePath , clientName , falseRepositorySetting , NO_CUSTOM_QUERY_PARAMETER );
92
+ runCustomQueryParameterTest (bucket , basePath , clientName , trueRepositorySetting , HAS_CUSTOM_QUERY_PARAMETER );
93
+ }
90
94
}
91
95
92
- private void runWithFixture (
96
+ private void runCustomQueryParameterTest (
93
97
String bucket ,
94
98
String basePath ,
95
99
String clientName ,
0 commit comments