Skip to content

Commit b96ada0

Browse files
committed
Fix tests
1 parent 528bf5b commit b96ada0

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.common.Strings;
3737
import org.elasticsearch.common.util.set.Sets;
3838
import org.elasticsearch.core.Nullable;
39-
import org.elasticsearch.core.Predicates;
4039
import org.elasticsearch.index.seqno.RetentionLeaseActions;
4140
import org.elasticsearch.xpack.core.ccr.action.ForgetFollowerAction;
4241
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
@@ -483,7 +482,7 @@ public static Set<String> names() {
483482
* @see Privilege#sortByAccessLevel
484483
*/
485484
public static Collection<String> findPrivilegesThatGrant(String action) {
486-
return findPrivilegesThatGrant(action, Predicates.always());
485+
return findPrivilegesThatGrant(action, p -> p.getSelectorPredicate().test(IndexComponentSelector.DATA));
487486
}
488487

489488
public static Collection<String> findPrivilegesThatGrant(String action, Predicate<IndexPrivilege> preCondition) {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilegeTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collection;
2424
import java.util.List;
2525
import java.util.Set;
26+
import java.util.function.Predicate;
2627

2728
import static org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege.findPrivilegesThatGrant;
2829
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -68,6 +69,16 @@ public void testFindPrivilegesThatGrant() {
6869
equalTo(List.of("monitor", "cross_cluster_replication", "manage", "all"))
6970
);
7071
assertThat(findPrivilegesThatGrant(RefreshAction.NAME), equalTo(List.of("maintenance", "manage", "all")));
72+
73+
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
74+
Predicate<IndexPrivilege> failuresOnly = p -> p.getSelectorPredicate() == IndexComponentSelectorPredicate.FAILURES;
75+
assertThat(findPrivilegesThatGrant(TransportSearchAction.TYPE.name(), failuresOnly), equalTo(List.of("read_failure_store")));
76+
assertThat(findPrivilegesThatGrant(TransportIndexAction.NAME, failuresOnly), equalTo(List.of()));
77+
assertThat(findPrivilegesThatGrant(TransportUpdateAction.NAME, failuresOnly), equalTo(List.of()));
78+
assertThat(findPrivilegesThatGrant(TransportDeleteAction.NAME, failuresOnly), equalTo(List.of()));
79+
assertThat(findPrivilegesThatGrant(IndicesStatsAction.NAME, failuresOnly), equalTo(List.of("manage_failure_store")));
80+
assertThat(findPrivilegesThatGrant(RefreshAction.NAME, failuresOnly), equalTo(List.of("manage_failure_store")));
81+
}
7182
}
7283

7384
public void testGet() {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,15 +1001,7 @@ public void testUnknownRoleCausesDenial() {
10011001
)
10021002
)
10031003
);
1004-
assertThat(
1005-
securityException,
1006-
throwableWithMessage(
1007-
containsString(
1008-
"this action is granted by the index privileges [read,all] for data access"
1009-
+ ", or [read_failure_store,all] for access via the failures selector"
1010-
)
1011-
)
1012-
);
1004+
assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]")));
10131005

10141006
verify(auditTrail).accessDenied(eq(requestId), eq(authentication), eq(action), eq(request), authzInfoRoles(Role.EMPTY.names()));
10151007
verifyNoMoreInteractions(auditTrail);
@@ -1055,15 +1047,7 @@ public void testServiceAccountDenial() {
10551047
throwableWithMessage(containsString("[" + action + "] is unauthorized for service account [" + serviceUser.principal() + "]"))
10561048
);
10571049
verify(auditTrail).accessDenied(eq(requestId), eq(authentication), eq(action), eq(request), authzInfoRoles(role.names()));
1058-
assertThat(
1059-
securityException,
1060-
throwableWithMessage(
1061-
containsString(
1062-
"this action is granted by the index privileges [read,all] for data access"
1063-
+ ", or [read_failure_store,all] for access via the failures selector"
1064-
)
1065-
)
1066-
);
1050+
assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]")));
10671051
verifyNoMoreInteractions(auditTrail);
10681052
}
10691053

@@ -1113,15 +1097,7 @@ public void testThatRoleWithNoIndicesIsDenied() {
11131097
containsString("[" + action + "] is unauthorized" + " for user [test user]" + " with effective roles [no_indices]")
11141098
)
11151099
);
1116-
assertThat(
1117-
securityException,
1118-
throwableWithMessage(
1119-
containsString(
1120-
"this action is granted by the index privileges [read,all] for data access"
1121-
+ ", or [read_failure_store,all] for access via the failures selector"
1122-
)
1123-
)
1124-
);
1100+
assertThat(securityException, throwableWithMessage(containsString("this action is granted by the index privileges [read,all]")));
11251101

11261102
verify(auditTrail).accessDenied(
11271103
eq(requestId),

0 commit comments

Comments
 (0)