📄 acceptusersauthenticationhandlertests.java
字号:
/* * Copyright 2004 The JA-SIG Collaborative. All rights reserved. See license * distributed with this file and available online at * http://www.ja-sig.org/products/cas/overview/license/ */package org.jasig.cas.adaptors.generic;import java.net.MalformedURLException;import java.net.URL;import java.util.HashMap;import java.util.Map;import org.jasig.cas.adaptors.generic.AcceptUsersAuthenticationHandler;import org.jasig.cas.authentication.handler.AuthenticationException;import org.jasig.cas.authentication.principal.HttpBasedServiceCredentials;import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;import junit.framework.TestCase;/** * @author Scott Battaglia * @version $Revision: 39690 $ $Date: 2007-04-07 14:35:03 -0400 (Sat, 07 Apr 2007) $ */public class AcceptUsersAuthenticationHandlerTests extends TestCase { final private Map<String, String> users; final private AcceptUsersAuthenticationHandler authenticationHandler; public AcceptUsersAuthenticationHandlerTests() throws Exception { this.users = new HashMap<String, String>(); this.users.put("scott", "rutgers"); this.users.put("dima", "javarules"); this.users.put("bill", "thisisAwesoME"); this.authenticationHandler = new AcceptUsersAuthenticationHandler(); this.authenticationHandler.setUsers(this.users); } public void testSupportsProperUserCredentials() throws Exception { UsernamePasswordCredentials c = new UsernamePasswordCredentials(); c.setUsername("scott"); c.setPassword("rutgers"); this.authenticationHandler.authenticate(c); } public void testDoesntSupportBadUserCredentials() { try { assertFalse(this.authenticationHandler .supports(new HttpBasedServiceCredentials(new URL( "http://www.rutgers.edu")))); } catch (MalformedURLException e) { fail("Could not resolve URL."); } } public void testAuthenticatesUserInMap() { final UsernamePasswordCredentials c = new UsernamePasswordCredentials(); c.setUsername("scott"); c.setPassword("rutgers"); try { assertTrue(this.authenticationHandler.authenticate(c)); } catch (AuthenticationException e) { fail("AuthenticationException caught but it should not have been thrown."); } } public void testFailsUserNotInMap() { final UsernamePasswordCredentials c = new UsernamePasswordCredentials(); c.setUsername("fds"); c.setPassword("rutgers"); try { assertFalse(this.authenticationHandler.authenticate(c)); } catch (AuthenticationException e) { // this is okay because it means the test failed. } } public void testFailsNullUserName() { final UsernamePasswordCredentials c = new UsernamePasswordCredentials(); c.setUsername(null); c.setPassword("user"); try { assertFalse(this.authenticationHandler.authenticate(c)); } catch (AuthenticationException e) { // this is okay because it means the test failed. } } public void testFailsNullUserNameAndPassword() { final UsernamePasswordCredentials c = new UsernamePasswordCredentials(); c.setUsername(null); c.setPassword(null); try { assertFalse(this.authenticationHandler.authenticate(c)); } catch (AuthenticationException e) { // this is okay because it means the test failed. } } public void testFailsNullPassword() { final UsernamePasswordCredentials c = new UsernamePasswordCredentials(); c.setUsername("scott"); c.setPassword(null); try { assertFalse(this.authenticationHandler.authenticate(c)); } catch (AuthenticationException e) { // this is okay because it means the test failed. } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -