]> source.dussan.org Git - archiva.git/blob
97b274440452c0f62960b1b4eaa556448d51700e
[archiva.git] /
1 package org.codehaus.plexus.redback.struts2.action;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import static org.easymock.EasyMock.anyObject;
23 import static org.easymock.EasyMock.createMock;
24 import static org.easymock.EasyMock.expect;
25 import static org.easymock.EasyMock.replay;
26 import static org.easymock.EasyMock.verify;
27
28 import java.util.HashMap;
29
30 import org.apache.archiva.redback.users.UserNotFoundException;
31 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
32 import org.apache.archiva.redback.authentication.AuthenticationException;
33 import org.apache.archiva.redback.authentication.AuthenticationResult;
34 import org.codehaus.plexus.redback.policy.AccountLockedException;
35 import org.codehaus.plexus.redback.policy.DefaultUserSecurityPolicy;
36 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
37 import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
38 import org.codehaus.plexus.redback.policy.UserValidationSettings;
39 import org.codehaus.plexus.redback.system.DefaultSecuritySession;
40 import org.codehaus.plexus.redback.system.SecuritySession;
41 import org.codehaus.plexus.redback.system.SecuritySystem;
42
43 import com.opensymphony.xwork2.Action;
44 import com.opensymphony.xwork2.XWorkTestCase;
45
46 public class LoginActionTest
47     extends XWorkTestCase
48 {
49
50     LoginAction action;
51
52     protected void setUp()
53         throws Exception
54     {
55         super.setUp();
56         action = new LoginAction();
57         action.session = new HashMap<String, Object>();
58     }
59
60     public void testRedback265()
61         throws SecurityException, NoSuchMethodException, AccountLockedException, MustChangePasswordException,
62         AuthenticationException, UserNotFoundException
63     {
64         String principal = "authenticates_but_does_not_exist";
65
66         // Setup authentication success, with no user found
67         AuthenticationResult result = new AuthenticationResult( true, principal, null );
68         SecuritySession session = new DefaultSecuritySession( result );
69         UserSecurityPolicy policy = new DefaultUserSecurityPolicy();
70
71         SecuritySystem system = createMock( SecuritySystem.class );
72         UserValidationSettings validationSettings = createMock( UserValidationSettings.class );
73         expect( system.authenticate( (AuthenticationDataSource) anyObject() ) ).andReturn( session );
74         expect( system.getPolicy() ).andReturn( policy ).anyTimes();
75         expect( validationSettings.isEmailValidationRequired() ).andReturn( true ).anyTimes();
76
77         // Hook-up action to mock objects
78         action.securitySystem = system;
79         action.setUsername( principal );
80
81         replay( system, validationSettings );
82
83         String actionResult = action.login();
84
85         verify( system, validationSettings );
86
87         assertEquals( Action.ERROR, actionResult );
88     }
89 }