1 package org.apache.archiva.redback.struts2.action;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
28 import java.util.HashMap;
30 import org.apache.archiva.redback.policy.DefaultUserSecurityPolicy;
31 import org.apache.archiva.redback.policy.MustChangePasswordException;
32 import org.apache.archiva.redback.policy.UserSecurityPolicy;
33 import org.apache.archiva.redback.policy.UserValidationSettings;
34 import org.apache.archiva.redback.struts2.action.LoginAction;
35 import org.apache.archiva.redback.users.UserNotFoundException;
36 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
37 import org.apache.archiva.redback.authentication.AuthenticationException;
38 import org.apache.archiva.redback.authentication.AuthenticationResult;
39 import org.apache.archiva.redback.policy.AccountLockedException;
40 import org.apache.archiva.redback.system.DefaultSecuritySession;
41 import org.apache.archiva.redback.system.SecuritySession;
42 import org.apache.archiva.redback.system.SecuritySystem;
44 import com.opensymphony.xwork2.Action;
45 import com.opensymphony.xwork2.XWorkTestCase;
47 public class LoginActionTest
53 protected void setUp()
57 action = new LoginAction();
58 action.session = new HashMap<String, Object>();
61 public void testRedback265()
62 throws SecurityException, NoSuchMethodException, AccountLockedException, MustChangePasswordException,
63 AuthenticationException, UserNotFoundException
65 String principal = "authenticates_but_does_not_exist";
67 // Setup authentication success, with no user found
68 AuthenticationResult result = new AuthenticationResult( true, principal, null );
69 SecuritySession session = new DefaultSecuritySession( result );
70 UserSecurityPolicy policy = new DefaultUserSecurityPolicy();
72 SecuritySystem system = createMock( SecuritySystem.class );
73 UserValidationSettings validationSettings = createMock( UserValidationSettings.class );
74 expect( system.authenticate( (AuthenticationDataSource) anyObject() ) ).andReturn( session );
75 expect( system.getPolicy() ).andReturn( policy ).anyTimes();
76 expect( validationSettings.isEmailValidationRequired() ).andReturn( true ).anyTimes();
78 // Hook-up action to mock objects
79 action.securitySystem = system;
80 action.setUsername( principal );
82 replay( system, validationSettings );
84 String actionResult = action.login();
86 verify( system, validationSettings );
88 assertEquals( Action.ERROR, actionResult );