17
17
import org .elasticsearch .common .settings .SecureString ;
18
18
import org .elasticsearch .common .settings .Settings ;
19
19
import org .elasticsearch .common .util .concurrent .ThreadContext ;
20
+ import org .elasticsearch .core .PathUtils ;
20
21
import org .elasticsearch .rest .RestStatus ;
22
+ import org .elasticsearch .test .cluster .ElasticsearchCluster ;
23
+ import org .elasticsearch .test .cluster .FeatureFlag ;
24
+ import org .elasticsearch .test .cluster .local .distribution .DistributionType ;
25
+ import org .elasticsearch .test .cluster .util .resource .Resource ;
21
26
import org .elasticsearch .test .rest .ESRestTestCase ;
22
27
import org .elasticsearch .test .rest .ObjectPath ;
28
+ import org .junit .BeforeClass ;
29
+ import org .junit .ClassRule ;
23
30
31
+ import java .io .FileNotFoundException ;
24
32
import java .io .IOException ;
33
+ import java .net .URISyntaxException ;
34
+ import java .net .URL ;
35
+ import java .nio .file .Path ;
25
36
import java .util .List ;
26
37
import java .util .Map ;
27
38
28
39
import static org .hamcrest .Matchers .equalTo ;
29
40
30
- public class PermissionsIT extends ESRestTestCase {
41
+ public class DlmPermissionsRestIT extends ESRestTestCase {
42
+
43
+ private static final String PASSWORD = "secret-test-password" ;
44
+ private static Path caPath ;
45
+
46
+ @ BeforeClass
47
+ public static void init () throws URISyntaxException , FileNotFoundException {
48
+ URL resource = DlmPermissionsRestIT .class .getResource ("/ssl/ca.crt" );
49
+ if (resource == null ) {
50
+ throw new FileNotFoundException ("Cannot find classpath resource /ssl/ca.crt" );
51
+ }
52
+ caPath = PathUtils .get (resource .toURI ());
53
+ }
54
+
55
+ @ ClassRule
56
+ public static ElasticsearchCluster cluster = ElasticsearchCluster .local ()
57
+ .feature (FeatureFlag .DLM_ENABLED )
58
+ .distribution (DistributionType .DEFAULT )
59
+ .setting ("xpack.watcher.enabled" , "false" )
60
+ .setting ("xpack.ml.enabled" , "false" )
61
+ .setting ("xpack.security.enabled" , "true" )
62
+ .setting ("xpack.license.self_generated.type" , "trial" )
63
+ .setting ("xpack.security.http.ssl.enabled" , "true" )
64
+ .setting ("xpack.security.http.ssl.certificate" , "node.crt" )
65
+ .setting ("xpack.security.http.ssl.key" , "node.key" )
66
+ .setting ("xpack.security.http.ssl.certificate_authorities" , "ca.crt" )
67
+ .setting ("xpack.security.transport.ssl.enabled" , "true" )
68
+ .setting ("xpack.security.transport.ssl.certificate" , "node.crt" )
69
+ .setting ("xpack.security.transport.ssl.key" , "node.key" )
70
+ .setting ("xpack.security.transport.ssl.certificate_authorities" , "ca.crt" )
71
+ .setting ("xpack.security.transport.ssl.verification_mode" , "certificate" )
72
+ .keystore ("xpack.security.transport.ssl.secure_key_passphrase" , "node-password" )
73
+ .keystore ("xpack.security.http.ssl.secure_key_passphrase" , "node-password" )
74
+ .keystore ("bootstrap.password" , PASSWORD )
75
+ .configFile ("node.key" , Resource .fromClasspath ("ssl/node.key" ))
76
+ .configFile ("node.crt" , Resource .fromClasspath ("ssl/node.crt" ))
77
+ .configFile ("ca.crt" , Resource .fromClasspath ("ssl/ca.crt" ))
78
+ .user ("test_admin" , PASSWORD , "superuser" )
79
+ .user ("test_dlm" , PASSWORD , "manage_dlm" )
80
+ .user ("test_non_privileged" , PASSWORD , "not_privileged" )
81
+ .rolesFile (Resource .fromClasspath ("roles.yml" ))
82
+ .build ();
83
+
84
+ @ Override
85
+ protected String getTestRestCluster () {
86
+ return cluster .getHttpAddresses ();
87
+ }
31
88
32
89
@ Override
33
90
protected Settings restClientSettings () {
34
- // Note: This user is defined in build.gradle, and assigned the role "manage_dlm". That role is defined in roles.yml.
35
- String token = basicAuthHeaderValue ("test_dlm" , new SecureString ("x-pack-test-password" .toCharArray ()));
36
- return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).build ();
91
+ // Note: This user is assigned the role "manage_dlm". That role is defined in roles.yml.
92
+ String token = basicAuthHeaderValue ("test_dlm" , new SecureString (PASSWORD .toCharArray ()));
93
+ return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).put ( CERTIFICATE_AUTHORITIES , caPath ). build ();
37
94
}
38
95
39
96
@ Override
40
97
protected Settings restAdminSettings () {
41
- String token = basicAuthHeaderValue ("test_admin" , new SecureString ("x-pack-test-password" .toCharArray ()));
42
- return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).build ();
98
+ String token = basicAuthHeaderValue ("test_admin" , new SecureString (PASSWORD .toCharArray ()));
99
+ return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).put ( CERTIFICATE_AUTHORITIES , caPath ). build ();
43
100
}
44
101
45
102
private Settings restUnprivilegedClientSettings () {
46
- // Note: This user is defined in build.gradle, and assigned the role "not_privileged". That role is defined in roles.yml.
47
- String token = basicAuthHeaderValue ("test_non_privileged" , new SecureString ("x-pack-test-password" .toCharArray ()));
48
- return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).build ();
103
+ // Note: This user is assigned the role "not_privileged". That role is defined in roles.yml.
104
+ String token = basicAuthHeaderValue ("test_non_privileged" , new SecureString (PASSWORD .toCharArray ()));
105
+ return Settings .builder ().put (ThreadContext .PREFIX + ".Authorization" , token ).put (CERTIFICATE_AUTHORITIES , caPath ).build ();
106
+ }
107
+
108
+ @ Override
109
+ protected String getProtocol () {
110
+ // Because http.ssl.enabled = true
111
+ return "https" ;
49
112
}
50
113
51
114
@ SuppressWarnings ("unchecked" )
@@ -58,8 +121,8 @@ public void testManageDLM() throws Exception {
58
121
*/
59
122
String dataStreamName = "dlm-test" ; // Needs to match the pattern of the names in roles.yml
60
123
createDataStreamAsAdmin (dataStreamName );
61
- Response getDatastreamRepsonse = adminClient ().performRequest (new Request ("GET" , "/_data_stream/" + dataStreamName ));
62
- final List <Map <String , Object >> nodes = ObjectPath .createFromResponse (getDatastreamRepsonse ).evaluate ("data_streams" );
124
+ Response getDataStreamResponse = adminClient ().performRequest (new Request ("GET" , "/_data_stream/" + dataStreamName ));
125
+ final List <Map <String , Object >> nodes = ObjectPath .createFromResponse (getDataStreamResponse ).evaluate ("data_streams" );
63
126
String index = (String ) ((List <Map <String , Object >>) nodes .get (0 ).get ("indices" )).get (0 ).get ("index_name" );
64
127
65
128
Request explainLifecycleRequest = new Request ("GET" , "/" + randomFrom ("_all" , "*" , index ) + "/_lifecycle/explain" );
@@ -161,5 +224,4 @@ private void createDataStreamAsAdmin(String name) throws IOException {
161
224
Request request = new Request ("PUT" , "/_data_stream/" + name );
162
225
assertOK (adminClient ().performRequest (request ));
163
226
}
164
-
165
227
}
0 commit comments