| 1 |
|
package com.atlassian.security.auth.trustedapps.seraph.filter; |
| 2 |
|
|
| 3 |
|
import com.atlassian.security.auth.trustedapps.filter.AuthenticationController; |
| 4 |
|
import com.atlassian.seraph.auth.RoleMapper; |
| 5 |
|
import com.atlassian.seraph.filter.BaseLoginFilter; |
| 6 |
|
import com.mockobjects.dynamic.C; |
| 7 |
|
import com.mockobjects.dynamic.Mock; |
| 8 |
|
import com.mockobjects.servlet.MockHttpServletRequest; |
| 9 |
|
import junit.framework.TestCase; |
| 10 |
|
|
| 11 |
|
import java.security.Principal; |
| 12 |
|
|
| 13 |
|
|
| 14 |
|
@link |
| 15 |
|
|
|
|
|
| 96.6% |
Uncovered Elements: 1 (29) |
Complexity: 9 |
Complexity Density: 0.43 |
|
| 16 |
|
public class TestSeraphAuthenticationController extends TestCase |
| 17 |
|
{ |
| 18 |
|
private AuthenticationController authenticationController; |
| 19 |
|
|
| 20 |
|
private Mock mockRoleMapper; |
| 21 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 22 |
5
|
protected void setUp() throws Exception... |
| 23 |
|
{ |
| 24 |
5
|
mockRoleMapper = new Mock(RoleMapper.class); |
| 25 |
5
|
authenticationController = new SeraphAuthenticationController((RoleMapper) mockRoleMapper.proxy()); |
| 26 |
|
} |
| 27 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 28 |
5
|
protected void tearDown() throws Exception... |
| 29 |
|
{ |
| 30 |
5
|
mockRoleMapper = null; |
| 31 |
5
|
authenticationController = null; |
| 32 |
|
} |
| 33 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 34 |
1
|
public void testCreateSeraphAuthenticationControllerWithNullRoleMapperThrowsIllegalArgumentException()... |
| 35 |
|
{ |
| 36 |
1
|
try |
| 37 |
|
{ |
| 38 |
1
|
new SeraphAuthenticationController(null); |
| 39 |
0
|
fail("Should throw exception"); |
| 40 |
|
} |
| 41 |
|
catch (IllegalArgumentException e) |
| 42 |
|
{ |
| 43 |
|
|
| 44 |
|
} |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 47 |
1
|
public void testShouldAttemptAuthenticationWithSeraphAuthenticationStatusAttributeNotPresent()... |
| 48 |
|
{ |
| 49 |
1
|
final MockHttpServletRequest request = new MockHttpServletRequest(); |
| 50 |
1
|
request.addExpectedGetAttributeName(BaseLoginFilter.OS_AUTHSTATUS_KEY); |
| 51 |
1
|
request.setupGetAttribute(null); |
| 52 |
1
|
assertTrue(authenticationController.shouldAttemptAuthentication(request)); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 55 |
1
|
public void testShouldAttemptAuthenticationWithSeraphAuthenticationStatusAttributePresent()... |
| 56 |
|
{ |
| 57 |
1
|
final MockHttpServletRequest request = new MockHttpServletRequest(); |
| 58 |
1
|
request.addExpectedGetAttributeName(BaseLoginFilter.OS_AUTHSTATUS_KEY); |
| 59 |
1
|
request.setupGetAttribute("some.value"); |
| 60 |
1
|
assertFalse(authenticationController.shouldAttemptAuthentication(request)); |
| 61 |
|
} |
| 62 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 63 |
1
|
public void testCanLoginWithRoleMapperDenyingLogin()... |
| 64 |
|
{ |
| 65 |
1
|
canLogin(false); |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 68 |
1
|
public void testCanLoginWithRoleMapperAllowingLogin()... |
| 69 |
|
{ |
| 70 |
1
|
canLogin(true); |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 73 |
2
|
private void canLogin(boolean roleMapperCanLogin)... |
| 74 |
|
{ |
| 75 |
2
|
final MockPrincipal principal = new MockPrincipal(); |
| 76 |
2
|
final MockHttpServletRequest request = new MockHttpServletRequest(); |
| 77 |
|
|
| 78 |
2
|
mockRoleMapper.matchAndReturn("canLogin", C.eq(principal, request), roleMapperCanLogin); |
| 79 |
2
|
assertEquals(roleMapperCanLogin, authenticationController.canLogin(principal, request)); |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
|
private static class MockPrincipal implements Principal |
| 83 |
|
{ |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
0
|
public String getName()... |
| 85 |
|
{ |
| 86 |
0
|
return "principal"; |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
} |