Skip to content

Commit 210ce86

Browse files
authored
[Test] Fix authentication creation in example project (#86385)
In #86206, we closed down Authentication constructors to favour dedicated convenient methods for instantiation. The constructor usages in the example project were however left out (another refactor fallout). Relates: #86206 Resolves: #86378
1 parent afe8b42 commit 210ce86

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

plugins/examples/security-authorization-engine/src/test/java/org/elasticsearch/example/CustomAuthorizationEngineTests.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public void testAuthorizeRunAs() {
5252
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
5353
// unauthorized
5454
{
55-
Authentication authentication =
56-
new Authentication(new User("joe", new String[]{"custom_superuser"}, new User("bar", "not_superuser")),
57-
new RealmRef("test", "test", "node"), new RealmRef("test", "test", "node"));
55+
Authentication authentication = Authentication
56+
.newRealmAuthentication(new User("bar", "not_superuser"), new RealmRef("test", "test", "node"))
57+
.runAs(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"));
5858
RequestInfo info = new RequestInfo(authentication, request, action, null);
5959
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
6060
engine.resolveAuthorizationInfo(info, future);
@@ -69,9 +69,9 @@ public void testAuthorizeRunAs() {
6969

7070
// authorized
7171
{
72-
Authentication authentication =
73-
new Authentication(new User("joe", new String[]{"not_superuser"}, new User("bar", "custom_superuser")),
74-
new RealmRef("test", "test", "node"), new RealmRef("test", "test", "node"));
72+
Authentication authentication = Authentication
73+
.newRealmAuthentication(new User("bar", "custom_superuser"), new RealmRef("test", "test", "node"))
74+
.runAs(new User("joe", "not_superuser"), new RealmRef("test", "test", "node"));
7575
RequestInfo info = new RequestInfo(authentication, request, action, null);
7676
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
7777
engine.resolveAuthorizationInfo(info, future);
@@ -103,7 +103,8 @@ public void testAuthorizeClusterAction() {
103103
// unauthorized
104104
{
105105
RequestInfo unauthReqInfo =
106-
new RequestInfo(new Authentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node"), null),
106+
new RequestInfo(
107+
Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")),
107108
requestInfo.getRequest(), requestInfo.getAction(), null);
108109
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
109110
engine.resolveAuthorizationInfo(unauthReqInfo, future);
@@ -128,7 +129,8 @@ public void testAuthorizeIndexAction() {
128129
// authorized
129130
{
130131
RequestInfo requestInfo =
131-
new RequestInfo(new Authentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"), null),
132+
new RequestInfo(
133+
Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node")),
132134
new SearchRequest(), "indices:data/read/search", null);
133135
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
134136
engine.resolveAuthorizationInfo(requestInfo, future);
@@ -149,7 +151,8 @@ public void testAuthorizeIndexAction() {
149151
// unauthorized
150152
{
151153
RequestInfo requestInfo =
152-
new RequestInfo(new Authentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node"), null),
154+
new RequestInfo(
155+
Authentication.newRealmAuthentication(new User("joe", "not_superuser"), new RealmRef("test", "test", "node")),
153156
new SearchRequest(), "indices:data/read/search", null);
154157
PlainActionFuture<AuthorizationInfo> future = new PlainActionFuture<>();
155158
engine.resolveAuthorizationInfo(requestInfo, future);
@@ -171,7 +174,7 @@ private RequestInfo getRequestInfo() {
171174
final String action = "cluster:monitor/foo";
172175
final TransportRequest request = new TransportRequest() {};
173176
final Authentication authentication =
174-
new Authentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"), null);
177+
Authentication.newRealmAuthentication(new User("joe", "custom_superuser"), new RealmRef("test", "test", "node"));
175178
return new RequestInfo(authentication, request, action, null);
176179
}
177180
}

plugins/examples/settings.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ plugins {
1111
}
1212

1313
// Include all subdirectories as example projects
14-
rootDir.listFiles().findAll { it.directory && new File(it, 'build.gradle').exists() }
15-
// filter out failing project till https://github.com/elastic/elasticsearch/issues/86378
16-
// is addressed
17-
.findAll {projectDir -> (projectDir.name == 'security-authorization-engine') == false }
18-
.each { subDir ->
14+
rootDir.listFiles().findAll { it.directory && new File(it, 'build.gradle').exists() }.each { subDir ->
1915
include ":${subDir.name}"
2016
}
2117

0 commit comments

Comments
 (0)