1 package org.codehaus.plexus.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.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;
43 import com.opensymphony.xwork2.Action;
44 import com.opensymphony.xwork2.XWorkTestCase;
46 public class LoginActionTest
52 protected void setUp()
56 action = new LoginAction();
57 action.session = new HashMap<String, Object>();
60 public void testRedback265()
61 throws SecurityException, NoSuchMethodException, AccountLockedException, MustChangePasswordException,
62 AuthenticationException, UserNotFoundException
64 String principal = "authenticates_but_does_not_exist";
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();
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();
77 // Hook-up action to mock objects
78 action.securitySystem = system;
79 action.setUsername( principal );
81 replay( system, validationSettings );
83 String actionResult = action.login();
85 verify( system, validationSettings );
87 assertEquals( Action.ERROR, actionResult );