|
@@ -24,8 +24,10 @@ import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.API_KEY_ID_KEY;
|
|
import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.API_KEY_ID_KEY;
|
|
|
|
+import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.API_KEY_INTERNAL_KEY;
|
|
import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.API_KEY_NAME_KEY;
|
|
import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.API_KEY_NAME_KEY;
|
|
import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.CROSS_CLUSTER_ACCESS_AUTHENTICATION_KEY;
|
|
import static org.elasticsearch.xpack.core.security.authc.AuthenticationField.CROSS_CLUSTER_ACCESS_AUTHENTICATION_KEY;
|
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
public class XContentUtilsTests extends ESTestCase {
|
|
public class XContentUtilsTests extends ESTestCase {
|
|
@@ -62,6 +64,21 @@ public class XContentUtilsTests extends ESTestCase {
|
|
assertThat(json, equalTo("{\"authorization\":{\"api_key\":{\"id\":\"" + apiKeyId + "\",\"name\":\"" + apiKeyName + "\"}}}"));
|
|
assertThat(json, equalTo("{\"authorization\":{\"api_key\":{\"id\":\"" + apiKeyId + "\",\"name\":\"" + apiKeyName + "\"}}}"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void testAddAuthorizationInfoWithCloudApiKey() throws IOException {
|
|
|
|
+ User user = AuthenticationTestHelper.randomCloudApiKeyUser();
|
|
|
|
+ Authentication authentication = AuthenticationTestHelper.randomCloudApiKeyAuthentication(user);
|
|
|
|
+ String json = generateJson(Map.of(AuthenticationField.AUTHENTICATION_KEY, authentication.encode()));
|
|
|
|
+ assertThat(json, containsString("{\"authorization\":{\"cloud_api_key\":{\"id\":\"" + user.principal()));
|
|
|
|
+ assertThat(json, containsString("\"internal\":" + user.metadata().getOrDefault(API_KEY_INTERNAL_KEY, null)));
|
|
|
|
+ if (user.metadata().containsKey(API_KEY_NAME_KEY)) {
|
|
|
|
+ assertThat(json, containsString("\"name\":\"" + user.metadata().getOrDefault(API_KEY_NAME_KEY, null) + "\""));
|
|
|
|
+ }
|
|
|
|
+ for (String role : user.roles()) {
|
|
|
|
+ assertThat(json, containsString(role));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
public void testAddAuthorizationInfoWithServiceAccount() throws IOException {
|
|
public void testAddAuthorizationInfoWithServiceAccount() throws IOException {
|
|
String account = "elastic/" + randomFrom("kibana", "fleet-server");
|
|
String account = "elastic/" + randomFrom("kibana", "fleet-server");
|
|
User user = new User(account);
|
|
User user = new User(account);
|