8
8
import com .atlassian .confluence .user .UserAccessor ;
9
9
import com .atlassian .sal .api .user .UserKey ;
10
10
import com .atlassian .sal .api .user .UserManager ;
11
- import com .atlassian .sal .api .user .UserProfile ;
12
11
import com .atlassian .user .User ;
13
12
import org .junit .jupiter .api .Test ;
14
13
import org .junit .jupiter .api .extension .ExtendWith ;
@@ -46,8 +45,6 @@ public class ConfluenceSlackLinkAccessManagerTest {
46
45
@ Mock
47
46
private UserAccessor userAccessor ;
48
47
49
- @ Mock
50
- private UserProfile userProfile ;
51
48
@ Mock
52
49
private ConfluenceUser user ;
53
50
@ Mock
@@ -67,9 +64,8 @@ public class ConfluenceSlackLinkAccessManagerTest {
67
64
@ Test
68
65
public void hasAccess_containerRequest_grantAccessForAdmin () {
69
66
when (userManager .isAdmin (userKey )).thenReturn (true );
70
- when (userProfile .getUserKey ()).thenReturn (userKey );
71
67
72
- boolean result = target .hasAccess (userProfile , containerRequest );
68
+ boolean result = target .hasAccess (userKey , containerRequest );
73
69
74
70
assertThat (result , is (true ));
75
71
}
@@ -78,9 +74,8 @@ public void hasAccess_containerRequest_grantAccessForAdmin() {
78
74
public void hasAccess_containerRequest_grantAccessForSysAdmin () {
79
75
when (userManager .isAdmin (userKey )).thenReturn (false );
80
76
when (userManager .isSystemAdmin (userKey )).thenReturn (true );
81
- when (userProfile .getUserKey ()).thenReturn (userKey );
82
77
83
- boolean result = target .hasAccess (userProfile , containerRequest );
78
+ boolean result = target .hasAccess (userKey , containerRequest );
84
79
85
80
assertThat (result , is (true ));
86
81
}
@@ -89,7 +84,6 @@ public void hasAccess_containerRequest_grantAccessForSysAdmin() {
89
84
public void hasAccess_containerRequest_grantAccessForSpaceAdmin () {
90
85
when (userManager .isAdmin (userKey )).thenReturn (false );
91
86
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
92
- when (userProfile .getUserKey ()).thenReturn (userKey );
93
87
UriInfo mockUriInfo = mock (UriInfo .class );
94
88
when (containerRequest .getUriInfo ()).thenReturn (mockUriInfo );
95
89
when (mockUriInfo .getQueryParameters ()).thenReturn (map );
@@ -98,7 +92,7 @@ public void hasAccess_containerRequest_grantAccessForSpaceAdmin() {
98
92
when (userAccessor .getExistingUserByKey (userKey )).thenReturn (user );
99
93
when (permissionManager .hasPermission (any (User .class ), eq (Permission .ADMINISTER ), eq (space ))).thenReturn (true );
100
94
101
- boolean result = target .hasAccess (userProfile , containerRequest );
95
+ boolean result = target .hasAccess (userKey , containerRequest );
102
96
103
97
assertThat (result , is (true ));
104
98
}
@@ -107,7 +101,6 @@ public void hasAccess_containerRequest_grantAccessForSpaceAdmin() {
107
101
public void hasAccess_containerRequest_notGrantAccessForNonSpaceAdmin () {
108
102
when (userManager .isAdmin (userKey )).thenReturn (false );
109
103
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
110
- when (userProfile .getUserKey ()).thenReturn (userKey );
111
104
UriInfo mockUriInfo = mock (UriInfo .class );
112
105
when (containerRequest .getUriInfo ()).thenReturn (mockUriInfo );
113
106
when (mockUriInfo .getQueryParameters ()).thenReturn (map );
@@ -116,7 +109,7 @@ public void hasAccess_containerRequest_notGrantAccessForNonSpaceAdmin() {
116
109
when (userAccessor .getExistingUserByKey (userKey )).thenReturn (user );
117
110
when (permissionManager .hasPermission (any (User .class ), eq (Permission .ADMINISTER ), eq (space ))).thenReturn (false );
118
111
119
- boolean result = target .hasAccess (userProfile , containerRequest );
112
+ boolean result = target .hasAccess (userKey , containerRequest );
120
113
121
114
assertThat (result , is (false ));
122
115
}
@@ -125,24 +118,22 @@ public void hasAccess_containerRequest_notGrantAccessForNonSpaceAdmin() {
125
118
public void hasAccess_containerRequest_notGrantAccessForNonExistingSpace () {
126
119
when (userManager .isAdmin (userKey )).thenReturn (false );
127
120
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
128
- when (userProfile .getUserKey ()).thenReturn (userKey );
129
121
UriInfo mockUriInfo = mock (UriInfo .class );
130
122
when (containerRequest .getUriInfo ()).thenReturn (mockUriInfo );
131
123
when (mockUriInfo .getQueryParameters ()).thenReturn (map );
132
124
when (map .getFirst ("key" )).thenReturn (SPACE_KEY );
133
125
when (spaceManager .getSpace (SPACE_KEY )).thenReturn (null );
134
126
135
- boolean result = target .hasAccess (userProfile , containerRequest );
127
+ boolean result = target .hasAccess (userKey , containerRequest );
136
128
137
129
assertThat (result , is (false ));
138
130
}
139
131
140
132
@ Test
141
133
public void hasAccess_servletRequest_grantAccessForAdmin () {
142
134
when (userManager .isAdmin (userKey )).thenReturn (true );
143
- when (userProfile .getUserKey ()).thenReturn (userKey );
144
135
145
- boolean result = target .hasAccess (userProfile , httpServletRequest );
136
+ boolean result = target .hasAccess (userKey , httpServletRequest );
146
137
147
138
assertThat (result , is (true ));
148
139
}
@@ -151,9 +142,8 @@ public void hasAccess_servletRequest_grantAccessForAdmin() {
151
142
public void hasAccess_servletRequest_grantAccessForSysAdmin () {
152
143
when (userManager .isAdmin (userKey )).thenReturn (false );
153
144
when (userManager .isSystemAdmin (userKey )).thenReturn (true );
154
- when (userProfile .getUserKey ()).thenReturn (userKey );
155
145
156
- boolean result = target .hasAccess (userProfile , httpServletRequest );
146
+ boolean result = target .hasAccess (userKey , httpServletRequest );
157
147
158
148
assertThat (result , is (true ));
159
149
}
@@ -162,13 +152,12 @@ public void hasAccess_servletRequest_grantAccessForSysAdmin() {
162
152
public void hasAccess_servletRequest_grantAccessForSpaceAdmin () {
163
153
when (userManager .isAdmin (userKey )).thenReturn (false );
164
154
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
165
- when (userProfile .getUserKey ()).thenReturn (userKey );
166
155
when (httpServletRequest .getParameter ("key" )).thenReturn (SPACE_KEY );
167
156
when (spaceManager .getSpace (SPACE_KEY )).thenReturn (space );
168
157
when (userAccessor .getExistingUserByKey (userKey )).thenReturn (user );
169
158
when (permissionManager .hasPermission (any (User .class ), eq (Permission .ADMINISTER ), eq (space ))).thenReturn (true );
170
159
171
- boolean result = target .hasAccess (userProfile , httpServletRequest );
160
+ boolean result = target .hasAccess (userKey , httpServletRequest );
172
161
173
162
assertThat (result , is (true ));
174
163
}
@@ -177,13 +166,12 @@ public void hasAccess_servletRequest_grantAccessForSpaceAdmin() {
177
166
public void hasAccess_servletRequest_notGrantAccessForNonSpaceAdmin () {
178
167
when (userManager .isAdmin (userKey )).thenReturn (false );
179
168
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
180
- when (userProfile .getUserKey ()).thenReturn (userKey );
181
169
when (httpServletRequest .getParameter ("key" )).thenReturn (SPACE_KEY );
182
170
when (spaceManager .getSpace (SPACE_KEY )).thenReturn (space );
183
171
when (userAccessor .getExistingUserByKey (userKey )).thenReturn (user );
184
172
when (permissionManager .hasPermission (any (User .class ), eq (Permission .ADMINISTER ), eq (space ))).thenReturn (false );
185
173
186
- boolean result = target .hasAccess (userProfile , httpServletRequest );
174
+ boolean result = target .hasAccess (userKey , httpServletRequest );
187
175
188
176
assertThat (result , is (false ));
189
177
}
@@ -192,11 +180,10 @@ public void hasAccess_servletRequest_notGrantAccessForNonSpaceAdmin() {
192
180
public void hasAccess_servletRequest_notGrantAccessForNonExistingSpace () {
193
181
when (userManager .isAdmin (userKey )).thenReturn (false );
194
182
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
195
- when (userProfile .getUserKey ()).thenReturn (userKey );
196
183
when (httpServletRequest .getParameter ("key" )).thenReturn (SPACE_KEY );
197
184
when (spaceManager .getSpace (SPACE_KEY )).thenReturn (null );
198
185
199
- boolean result = target .hasAccess (userProfile , httpServletRequest );
186
+ boolean result = target .hasAccess (userKey , httpServletRequest );
200
187
201
188
assertThat (result , is (false ));
202
189
}
@@ -205,7 +192,6 @@ public void hasAccess_servletRequest_notGrantAccessForNonExistingSpace() {
205
192
public void hasAccess_servletRequest_grantAccessForSpaceKeyInSession () {
206
193
when (userManager .isAdmin (userKey )).thenReturn (false );
207
194
when (userManager .isSystemAdmin (userKey )).thenReturn (false );
208
- when (userProfile .getUserKey ()).thenReturn (userKey );
209
195
when (httpServletRequest .getParameter ("key" )).thenReturn (null );
210
196
when (httpServletRequest .getSession ()).thenReturn (session );
211
197
when (session .getAttribute (FROM_SPACE_ATTRIBUTE_KEY )).thenReturn (true );
@@ -214,7 +200,7 @@ public void hasAccess_servletRequest_grantAccessForSpaceKeyInSession() {
214
200
when (userAccessor .getExistingUserByKey (userKey )).thenReturn (user );
215
201
when (permissionManager .hasPermission (any (User .class ), eq (Permission .ADMINISTER ), eq (space ))).thenReturn (true );
216
202
217
- boolean result = target .hasAccess (userProfile , httpServletRequest );
203
+ boolean result = target .hasAccess (userKey , httpServletRequest );
218
204
219
205
assertThat (result , is (true ));
220
206
}
0 commit comments