|
22 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | 23 |
|
24 | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
25 | | -import static org.hamcrest.Matchers.contains; |
26 | | -import static org.hamcrest.Matchers.empty; |
27 | 25 | import static org.hamcrest.Matchers.equalTo; |
28 | 26 | import static org.hamcrest.Matchers.is; |
29 | 27 | import static org.hamcrest.Matchers.nullValue; |
@@ -168,4 +166,42 @@ void removeProxyPrivilege_shouldHandleNullArrayGracefully() { |
168 | 166 | // assert - should still have the privilege since null was passed |
169 | 167 | assertThat(userContext.hasPrivilege("Privilege1"), is(true)); |
170 | 168 | } |
| 169 | + |
| 170 | + @Test |
| 171 | + void removeProxyPrivilege_shouldHandleNonExistentPrivilegeGracefully() { |
| 172 | + // arrange |
| 173 | + UserContext userContext = new UserContext(new TestUsernameAuthenticationScheme()); |
| 174 | + |
| 175 | + // act |
| 176 | + userContext.removeProxyPrivilege("Privilege 1"); |
| 177 | + |
| 178 | + // assert - no error thrown |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + void proxyPrivileges_shouldStackCorrectly() { |
| 183 | + // arrange |
| 184 | + UserContext userContext = new UserContext(new TestUsernameAuthenticationScheme()); |
| 185 | + |
| 186 | + // act - deep nesting |
| 187 | + userContext.addProxyPrivilege("Privilege1"); |
| 188 | + try { |
| 189 | + userContext.addProxyPrivilege("Privilege1"); |
| 190 | + try { |
| 191 | + userContext.addProxyPrivilege("Privilege1"); |
| 192 | + try { |
| 193 | + userContext.addProxyPrivilege("Privilege1"); |
| 194 | + } finally { |
| 195 | + userContext.removeProxyPrivilege("Privilege1"); |
| 196 | + } |
| 197 | + } finally { |
| 198 | + userContext.removeProxyPrivilege("Privilege1"); |
| 199 | + } |
| 200 | + } finally { |
| 201 | + userContext.removeProxyPrivilege("Privilege1"); |
| 202 | + } |
| 203 | + |
| 204 | + // assert |
| 205 | + assertThat(userContext.hasPrivilege("Privilege1"), is(true)); |
| 206 | + } |
171 | 207 | } |
0 commit comments