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 package fr.paris.lutece.portal.service.security;
35
36 import javax.security.auth.login.FailedLoginException;
37 import javax.security.auth.login.LoginException;
38
39 import org.springframework.mock.web.MockHttpServletRequest;
40 import org.springframework.test.util.ReflectionTestUtils;
41
42 import fr.paris.lutece.test.LuteceTestCase;
43
44
45
46
47 public class SecurityServiceTest extends LuteceTestCase
48 {
49
50
51
52
53
54 public void testLoginUserFail( )
55 {
56 MockHttpServletRequest request = new MockHttpServletRequest( );
57
58 String strUserName = "";
59 String strPassword = "";
60
61 try
62 {
63 SecurityService securityService = SecurityService.getInstance( );
64 MokeLuteceAuthenticationcation.html#MokeLuteceAuthentication">MokeLuteceAuthentication mockLuteceAuthentication = new MokeLuteceAuthentication( );
65 ReflectionTestUtils.setField( securityService, "_authenticationService", mockLuteceAuthentication );
66
67 securityService.loginUser( request, strUserName, strPassword );
68
69
70 assertTrue( false );
71 }
72 catch( LoginException e )
73 {
74 assertEquals( e.getClass( ), FailedLoginException.class );
75 }
76 catch( NullPointerException e )
77 {
78 assertTrue( false );
79 }
80 catch( LoginRedirectException e )
81 {
82 assertTrue( false );
83 }
84 }
85
86
87
88
89
90
91 public void testLoginUserSuccess( ) throws LoginException
92 {
93 MockHttpServletRequest request = new MockHttpServletRequest( );
94 String strUserName = "admin";
95 String strPassword = "adminadmin";
96 String sessionId = request.getSession( true ).getId( );
97
98 try
99 {
100 SecurityService securityService = SecurityService.getInstance( );
101 MokeLuteceAuthenticationcation.html#MokeLuteceAuthentication">MokeLuteceAuthentication mockLuteceAuthentication = new MokeLuteceAuthentication( );
102 ReflectionTestUtils.setField( securityService, "_authenticationService", mockLuteceAuthentication );
103
104 securityService.loginUser( request, strUserName, strPassword );
105
106 String newSessionId = request.getSession( true ).getId( );
107
108
109 assertTrue( sessionId.contentEquals( newSessionId ) );
110 }
111 catch( Exception e )
112 {
113 assertTrue( false );
114 }
115 }
116 }