1
+ package org .elasticsearch .rest .action .readonlyrest .acl .test ;
2
+
3
+ import org .elasticsearch .plugin .readonlyrest .acl .ACL ;
4
+ import org .elasticsearch .plugin .readonlyrest .acl .RequestContext ;
5
+ import org .elasticsearch .plugin .readonlyrest .acl .blocks .Block ;
6
+ import org .elasticsearch .plugin .readonlyrest .acl .blocks .BlockExitResult ;
7
+ import org .junit .BeforeClass ;
8
+ import org .junit .Test ;
9
+
10
+ import static org .junit .Assert .assertEquals ;
11
+ import static org .junit .Assert .assertFalse ;
12
+ import static org .junit .Assert .assertTrue ;
13
+
14
+ public class KibanaACLTest {
15
+ private static ACL acl ;
16
+
17
+ @ BeforeClass
18
+ public static void setUpBeforeClass () throws Exception {
19
+ acl = ACLTest .mkACL ("/src/test/kibana_test_rules.yml" );
20
+ }
21
+
22
+ @ Test
23
+ public final void testKibanaROClusterAction () throws Throwable {
24
+ RequestContext rc = ACLTest .mockReq ("xyz" , "1.1.1.1" , "" , "" , 0 , null , null , new String []{"random-idx" }, "cluster:monitor/health" );
25
+ BlockExitResult res = acl .check (rc );
26
+ assertTrue (res .isMatch ());
27
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
28
+ assertEquals (res .getBlock ().getName (), "1" );
29
+ }
30
+
31
+ @ Test
32
+ public final void testKibanaROreadAction () throws Throwable {
33
+ RequestContext rc = ACLTest .mockReq ("xyz" , "1.1.1.1" , "" , "" , 0 , null , null , new String []{"random-idx" }, "indices:admin/get" );
34
+ BlockExitResult res = acl .check (rc );
35
+ assertTrue (res .isMatch ());
36
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
37
+ assertEquals (res .getBlock ().getName (), "1" );
38
+ }
39
+ @ Test
40
+ public final void testKibanaROwriteKibanaDevNull () throws Throwable {
41
+ RequestContext rc = ACLTest .mockReq ("xyz" , "1.1.1.1" , "" , "" , 0 , null , null , new String []{".kibana-devnull" }, "indices:data/write/update" );
42
+ BlockExitResult res = acl .check (rc );
43
+ assertTrue (res .isMatch ());
44
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
45
+ assertEquals (res .getBlock ().getName (), "1" );
46
+ }
47
+
48
+ @ Test
49
+ public final void testKibanaROwriteAction_FORBID () throws Throwable {
50
+ RequestContext rc = ACLTest .mockReq ("xyz" , "1.1.1.1" , "" , "" , 0 , null , null , new String []{"random-idx" }, "indices:data/write/update" );
51
+ BlockExitResult res = acl .check (rc );
52
+ assertFalse (res .isMatch ());
53
+ }
54
+
55
+ @ Test
56
+ public final void testKibanaRWreadAction () throws Throwable {
57
+ RequestContext rc = ACLTest .mockReq ("xyz" , "2.2.2.2" , "" , "" , 0 , null , null , new String []{"random-idx" }, "indices:admin/get" );
58
+ BlockExitResult res = acl .check (rc );
59
+ assertTrue (res .isMatch ());
60
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
61
+ assertEquals (res .getBlock ().getName (), "2" );
62
+ }
63
+ @ Test
64
+ public final void testKibanaRWwriteAction () throws Throwable {
65
+ RequestContext rc = ACLTest .mockReq ("xyz" , "2.2.2.2" , "" , "" , 0 , null , null , new String []{"random-idx" }, "indices:data/write/update" );
66
+ BlockExitResult res = acl .check (rc );
67
+ assertTrue (res .isMatch ());
68
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
69
+ assertEquals (res .getBlock ().getName (), "2" );
70
+ }
71
+ @ Test
72
+ public final void testKibanaRWClusterAction () throws Throwable {
73
+ RequestContext rc = ACLTest .mockReq ("xyz" , "2.2.2.2" , "" , "" , 0 , null , null , new String []{"random-idx" }, "cluster:monitor/health" );
74
+ BlockExitResult res = acl .check (rc );
75
+ assertTrue (res .isMatch ());
76
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
77
+ assertEquals (res .getBlock ().getName (), "2" );
78
+ }
79
+
80
+ @ Test
81
+ public final void testKibanaR0writeDashboard () throws Throwable {
82
+ RequestContext rc = ACLTest .mockReq ("xyz" , "1.1.1.1" , "" , "" , 0 , null , null , new String []{".kibana" }, "indices:data/write/update" );
83
+ BlockExitResult res = acl .check (rc );
84
+ assertFalse (res .isMatch ());
85
+ }
86
+
87
+ @ Test
88
+ public final void testKibanaRWwriteDashboard () throws Throwable {
89
+ RequestContext rc = ACLTest .mockReq ("xyz" , "2.2.2.2" , "" , "" , 0 , null , null , new String []{".kibana" }, "indices:data/write/update" );
90
+ BlockExitResult res = acl .check (rc );
91
+ assertTrue (res .isMatch ());
92
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
93
+ assertEquals (res .getBlock ().getName (), "2" );
94
+ }
95
+
96
+ @ Test
97
+ public final void testKibanaR0PlusWriteDashboard () throws Throwable {
98
+ RequestContext rc = ACLTest .mockReq ("xyz" , "3.3.3.3" , "" , "" , 0 , null , null , new String []{".kibana" }, "indices:data/write/update" );
99
+ BlockExitResult res = acl .check (rc );
100
+ assertTrue (res .isMatch ());
101
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
102
+ assertEquals (res .getBlock ().getName (), "3" );
103
+ }
104
+
105
+ @ Test
106
+ public final void testKibanaR0PlusWriteKibanaDevnull () throws Throwable {
107
+ RequestContext rc = ACLTest .mockReq ("xyz" , "3.3.3.3" , "" , "" , 0 , null , null , new String []{".kibana-devnull" }, "indices:data/write/update" );
108
+ BlockExitResult res = acl .check (rc );
109
+ assertTrue (res .isMatch ());
110
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
111
+ assertEquals (res .getBlock ().getName (), "3" );
112
+ }
113
+
114
+ @ Test
115
+ public final void testKibanaR0WriteKibanaDevnull () throws Throwable {
116
+ RequestContext rc = ACLTest .mockReq ("xyz" , "3.3.3.3" , "" , "" , 0 , null , null , new String []{".kibana-devnull" }, "indices:data/write/update" );
117
+ BlockExitResult res = acl .check (rc );
118
+ assertTrue (res .isMatch ());
119
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
120
+ assertEquals (res .getBlock ().getName (), "3" );
121
+ }
122
+
123
+ @ Test
124
+ public final void testKibanaR0WriteDashboardCustomKibanaIdx () throws Throwable {
125
+ RequestContext rc = ACLTest .mockReq ("xyz" , "4.4.4.4" , "" , "" , 0 , null , null , new String []{"custom-kibana-idx" }, "indices:data/write/update" );
126
+ BlockExitResult res = acl .check (rc );
127
+ assertTrue (res .isMatch ());
128
+ assertTrue (res .getBlock ().getPolicy () == Block .Policy .ALLOW );
129
+ assertEquals (res .getBlock ().getName (), "4" );
130
+ }
131
+
132
+ }
0 commit comments