This repository was archived by the owner on Jul 20, 2024. It is now read-only.
forked from splunk/splunk-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoleTest.java
More file actions
116 lines (102 loc) · 4.69 KB
/
RoleTest.java
File metadata and controls
116 lines (102 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright 2012 Splunk, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"): you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.splunk;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
public class RoleTest extends SDKTestCase {
@Test
public void testSymmetricAccessors() {
Role role = service.getRoles().create(createTemporaryName());
try {
role.setCapabilities(new String[] { "admin_all_objects" });
role.setDefaultApp("search");
role.setImportedRoles(new String[] { "user" });
role.setSearchDiskQuota(9000);
role.setSearchFilter("*");
role.setSearchIndexesAllowed(new String[] { "*" });
role.setSearchIndexesDefault(new String[] { "main", "_internal" });
role.setSearchJobsQuota(49);
role.setRealTimeSearchJobsQuota(99);
role.setSearchTimeWindow(99);
role.update();
role.refresh();
Assert.assertEquals(new String[] { "admin_all_objects" }, role.getCapabilities());
Assert.assertEquals("search", role.getDefaultApp());
Assert.assertArrayEquals(new String[]{"user"}, role.getImportedRoles());
Assert.assertEquals(9000, role.getSearchDiskQuota());
Assert.assertEquals("*", role.getSearchFilter());
Assert.assertArrayEquals(new String[]{"*"}, role.getSearchIndexesAllowed());
List<String> defaultIndexes = Arrays.asList(role.getSearchIndexesDefault());
Assert.assertEquals(2, defaultIndexes.size());
Assert.assertTrue(defaultIndexes.contains("main"));
Assert.assertTrue(defaultIndexes.contains("_internal"));
Assert.assertEquals(49, role.getSearchJobsQuota());
Assert.assertEquals(99, role.getRealTimeSearchJobsQuota());
Assert.assertEquals(99, role.getSearchTimeWindow());
}
finally {
role.remove();
}
}
@Test
public void testArrayPromotingSetters() {
Role role = service.getRoles().create(createTemporaryName());
try {
role.setCapabilities("admin_all_objects");
role.setImportedRoles("user");
role.setSearchIndexesAllowed("*");
role.setSearchIndexesDefault("main");
role.update();
role.refresh();
Assert.assertArrayEquals(new String[] { "admin_all_objects" }, role.getCapabilities());
Assert.assertArrayEquals(new String[] { "user" }, role.getImportedRoles());
Assert.assertArrayEquals(new String[] { "*" }, role.getSearchIndexesAllowed());
Assert.assertArrayEquals(new String[] { "main" }, role.getSearchIndexesDefault());
}
finally {
role.remove();
}
}
@Test
public void testUnpairedImportedGetters() {
Role role = service.getRoles().create(createTemporaryName());
try {
role.setImportedRoles("user");
role.update();
role.refresh();
/*
* NOTE: These expected values probably come from the "user" role.
* If the default values of the "user" role change in the
* future, this test should be rewritten to lookup the values
* from the "user" role to determine the expected values here.
*/
Assert.assertTrue(Arrays.asList(role.getImportedCapabilities()).contains(
"change_own_password"));
Assert.assertEquals(6, role.getImportedRealTimeSearchJobsQuota());
Assert.assertEquals(100, role.getImportedSearchDiskQuota());
Assert.assertEquals(null, role.getImportedSearchFilter());
Assert.assertArrayEquals(new String[] { "*" }, role.getImportedIndexesAllowed());
Assert.assertArrayEquals(new String[] { "main" }, role.getImportedIndexesDefault());
Assert.assertEquals(3, role.getImportedSearchJobsQuota());
Assert.assertEquals(-1, role.getImportedSearchTimeWindow());
}
finally {
role.remove();
}
}
}