001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander V. Astapchuk
020: * @version $Revision$
021: */package org.apache.harmony.auth.module;
022:
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.security.auth.Subject;
027: import javax.security.auth.callback.CallbackHandler;
028: import javax.security.auth.callback.Callback;
029: import javax.security.auth.login.LoginException;
030:
031: import junit.framework.TestCase;
032: import org.apache.harmony.auth.module.UnixLoginModule;
033:
034: /**
035: * Unit test for UnixLoginModule
036: */
037: @SuppressWarnings("unchecked")
038: public class UnixLoginModuleTest extends TestCase {
039:
040: UnixLoginModule lm = new UnixLoginModule();
041:
042: @Override
043: protected void setUp() throws Exception {
044: Subject subj = new Subject();
045: CallbackHandler cbh = new TestCallbackHandler();
046: Map sharedState = new HashMap();
047: Map options = new HashMap();
048: lm.initialize(subj, cbh, sharedState, options);
049: }
050:
051: private static class TestCallbackHandler implements CallbackHandler {
052: public void handle(Callback[] cbs) {
053: // does nothing
054: }
055: }
056:
057: /**
058: * Test for UnixLoginModule.initialize()
059: */
060: public void testInitialize() {
061: // Need new, non initialized instance of LoginModule
062: lm = new UnixLoginModule();
063:
064: Map shared = new HashMap();
065: Map options = new HashMap();
066: CallbackHandler cbh = new TestCallbackHandler();
067: // must not accept null for subject
068: try {
069: lm.initialize(null, cbh, shared, options);
070: fail("must not pass here");
071: } catch (NullPointerException _) {
072: // gut
073: }
074: Subject subj = new Subject();
075: // must accept null for handler
076: lm.initialize(subj, null, shared, options);
077: // must accept null for sharedState
078: lm.initialize(subj, cbh, null, options);
079: // must not accept null for options
080: try {
081: lm.initialize(subj, cbh, shared, null);
082: fail("must not pass here");
083: } catch (NullPointerException _) {
084: // gut
085: }
086: }
087:
088: public void testAbort() throws LoginException {
089: lm.login();
090: lm.abort();
091: }
092:
093: public void testCommit() throws LoginException {
094: lm.login();
095: lm.commit();
096: lm.logout();
097: }
098:
099: public void testLogin() throws LoginException {
100: lm.login();
101: lm.abort();
102: }
103:
104: public void testLogout() throws LoginException {
105: lm.logout();
106: }
107:
108: }
|