15
15
16
16
package org .apache .geode .connectors .jdbc .internal .cli ;
17
17
18
+ import java .util .HashMap ;
19
+ import java .util .Map ;
20
+
18
21
import org .junit .BeforeClass ;
19
22
import org .junit .ClassRule ;
20
23
import org .junit .Rule ;
@@ -48,20 +51,6 @@ CliFunctionResult getFunctionResult(JdbcConnectorService service,
48
51
49
52
@ Category ({IntegrationTest .class , SecurityException .class })
50
53
public class JDBCConnectorFunctionsSecurityTest {
51
-
52
- private static Function alterConnectionFunction = new AlterConnectionFunction ();
53
- private static Function alterMappingFunction = new AlterMappingFunction ();
54
- private static Function createConnectionFunction = new CreateConnectionFunction ();
55
- private static Function createMappingFunction = new CreateMappingFunction ();
56
- private static Function describeConnectionFunction = new DescribeConnectionFunction ();
57
- private static Function describeMappingFunction = new DescribeMappingFunction ();
58
- private static Function destroyConnectionFunction = new DestroyConnectionFunction ();
59
- private static Function destroyMappingFunction = new DestroyMappingFunction ();
60
- private static Function listConnectionFunction = new ListConnectionFunction ();
61
- private static Function listMappingFunction = new ListMappingFunction ();
62
- private static Function inheritsDefaultPermissionsFunction =
63
- new InheritsDefaultPermissionsJDBCFunction ();
64
-
65
54
@ ClassRule
66
55
public static ServerStarterRule server = new ServerStarterRule ().withJMXManager ()
67
56
.withSecurityManager (SimpleSecurityManager .class ).withAutoStart ();
@@ -70,81 +59,35 @@ public class JDBCConnectorFunctionsSecurityTest {
70
59
public GfshCommandRule gfsh =
71
60
new GfshCommandRule (server ::getJmxPort , GfshCommandRule .PortType .jmxManager );
72
61
62
+ private static Map <Function , String > functionStringMap = new HashMap <>();
63
+
73
64
@ BeforeClass
74
65
public static void setupClass () {
75
- FunctionService .registerFunction (alterConnectionFunction );
76
- FunctionService .registerFunction (alterMappingFunction );
77
- FunctionService .registerFunction (createConnectionFunction );
78
- FunctionService .registerFunction (createMappingFunction );
79
- FunctionService .registerFunction (describeConnectionFunction );
80
- FunctionService .registerFunction (describeMappingFunction );
81
- FunctionService .registerFunction (destroyConnectionFunction );
82
- FunctionService .registerFunction (destroyMappingFunction );
83
- FunctionService .registerFunction (listConnectionFunction );
84
- FunctionService .registerFunction (listMappingFunction );
85
- FunctionService .registerFunction (inheritsDefaultPermissionsFunction );
86
- }
87
-
88
- @ Test
89
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
90
- public void testInvalidPermissionsForAlterConnectionFunction () {
91
- gfsh .executeAndAssertThat ("execute function --id=" + alterConnectionFunction .getId ())
92
- .containsOutput ("not authorized for CLUSTER:MANAGE" ).statusIsError ();
66
+ functionStringMap .put (new AlterConnectionFunction (), "CLUSTER:MANAGE" );
67
+ functionStringMap .put (new AlterMappingFunction (), "CLUSTER:MANAGE" );
68
+ functionStringMap .put (new CreateConnectionFunction (), "CLUSTER:MANAGE" );
69
+ functionStringMap .put (new CreateMappingFunction (), "CLUSTER:MANAGE" );
70
+ functionStringMap .put (new DescribeConnectionFunction (), "CLUSTER:READ" );
71
+ functionStringMap .put (new DescribeMappingFunction (), "CLUSTER:READ" );
72
+ functionStringMap .put (new DestroyConnectionFunction (), "CLUSTER:MANAGE" );
73
+ functionStringMap .put (new DestroyMappingFunction (), "CLUSTER:MANAGE" );
74
+ functionStringMap .put (new ListConnectionFunction (), "CLUSTER:READ" );
75
+ functionStringMap .put (new ListMappingFunction (), "CLUSTER:READ" );
76
+ functionStringMap .put (new InheritsDefaultPermissionsJDBCFunction (), "CLUSTER:READ" );
77
+ functionStringMap .keySet ().forEach (FunctionService ::registerFunction );
93
78
}
94
79
95
- @ Test
96
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
97
- public void testInvalidPermissionsForAlterMappingFunction () {
98
- gfsh .executeAndAssertThat ("execute function --id=" + alterMappingFunction .getId ())
99
- .containsOutput ("not authorized for CLUSTER:MANAGE" ).statusIsError ();
100
- }
101
-
102
- @ Test
103
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
104
- public void testInvalidPermissionsForCreateConnectionFunction () {
105
- gfsh .executeAndAssertThat ("execute function --id=" + createConnectionFunction .getId ())
106
- .containsOutput ("not authorized for CLUSTER:MANAGE" ).statusIsError ();
107
- }
108
-
109
- @ Test
110
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
111
- public void testInvalidPermissionsForCreateMappingFunction () {
112
- gfsh .executeAndAssertThat ("execute function --id=" + createMappingFunction .getId ())
113
- .containsOutput ("not authorized for CLUSTER:MANAGE" ).statusIsError ();
114
- }
115
-
116
- @ Test
117
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
118
- public void testInvalidPermissionsForDescribeConnectionFunction () {
119
- gfsh .executeAndAssertThat ("execute function --id=" + describeConnectionFunction .getId ())
120
- .containsOutput ("not authorized for CLUSTER:READ" ).statusIsError ();
121
- }
122
-
123
- @ Test
124
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
125
- public void testInvalidPermissionsForDescribeMappingFunction () {
126
- gfsh .executeAndAssertThat ("execute function --id=" + describeMappingFunction .getId ())
127
- .containsOutput ("not authorized for CLUSTER:READ" ).statusIsError ();
128
- }
129
-
130
- @ Test
131
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
132
- public void testInvalidPermissionsForDestroyConnectionFunction () {
133
- gfsh .executeAndAssertThat ("execute function --id=" + destroyConnectionFunction .getId ())
134
- .containsOutput ("not authorized for CLUSTER:MANAGE" ).statusIsError ();
135
- }
136
-
137
- @ Test
138
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
139
- public void testInvalidPermissionsForDestroyMappingFunction () {
140
- gfsh .executeAndAssertThat ("execute function --id=" + destroyMappingFunction .getId ())
141
- .containsOutput ("not authorized for CLUSTER:MANAGE" ).statusIsError ();
142
- }
143
80
144
81
@ Test
145
- @ ConnectionConfiguration (user = "dataWrite" , password = "dataWrite" )
146
- public void testInvalidPermissionsForFunctionInheritingDefaultPermissions () {
147
- gfsh .executeAndAssertThat ("execute function --id=" + inheritsDefaultPermissionsFunction .getId ())
148
- .containsOutput ("not authorized for CLUSTER:READ" ).statusIsError ();
82
+ @ ConnectionConfiguration (user = "user" , password = "user" )
83
+ public void functionRequireExpectedPermission () throws Exception {
84
+ functionStringMap .entrySet ().stream ().forEach (entry -> {
85
+ Function function = entry .getKey ();
86
+ String permission = entry .getValue ();
87
+ gfsh .executeAndAssertThat ("execute function --id=" + function .getId ())
88
+ .tableHasRowCount ("Function Execution Result" , 1 )
89
+ .tableHasColumnWithValuesContaining ("Function Execution Result" , permission )
90
+ .statusIsError ();
91
+ });
149
92
}
150
93
}
0 commit comments