Clover Coverage Report - Atlassian Trusted Apps(Aggregated)
Coverage timestamp: Tue Jun 9 2009 19:34:44 CDT
22   89   10   2.44
0   71   0.45   4.5
9     1.11  
2    
 
 
  TestSeraphAuthenticationController       Line # 16 21 9 96.6% 0.9655172
  TestSeraphAuthenticationController.MockPrincipal       Line # 82 1 1 0% 0.0
 
  (5)
 
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    * Tests for {@link SeraphAuthenticationController}
15    */
 
16    public class TestSeraphAuthenticationController extends TestCase
17    {
18    private AuthenticationController authenticationController;
19   
20    private Mock mockRoleMapper;
21   
 
22  5 toggle protected void setUp() throws Exception
23    {
24  5 mockRoleMapper = new Mock(RoleMapper.class);
25  5 authenticationController = new SeraphAuthenticationController((RoleMapper) mockRoleMapper.proxy());
26    }
27   
 
28  5 toggle protected void tearDown() throws Exception
29    {
30  5 mockRoleMapper = null;
31  5 authenticationController = null;
32    }
33   
 
34  1 toggle 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    // expected
44    }
45    }
46   
 
47  1 toggle 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   
 
55  1 toggle 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   
 
63  1 toggle public void testCanLoginWithRoleMapperDenyingLogin()
64    {
65  1 canLogin(false);
66    }
67   
 
68  1 toggle public void testCanLoginWithRoleMapperAllowingLogin()
69    {
70  1 canLogin(true);
71    }
72   
 
73  2 toggle 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   
 
82    private static class MockPrincipal implements Principal
83    {
 
84  0 toggle public String getName()
85    {
86  0 return "principal";
87    }
88    }
89    }