1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18/**
19 * @author Alexey V. Varlamov
20 */
21
22package org.ietf.jgss;
23
24import java.security.Provider;
25import java.security.Security;
26
27import junit.framework.TestCase;
28
29
30/**
31 * Tests GSSManager class
32 */
33public class GSSManagerTest extends TestCase {
34    /**
35     * Tests loading of a default provider with valid class references.
36     */
37    public void testGetInstance_valid() {
38        String oldProvider = Security.getProperty(GSSManager.MANAGER);
39        try {
40            Security.setProperty(GSSManager.MANAGER, TestManager.class
41                .getName());
42            GSSManager m = GSSManager.getInstance();
43            assertNotNull(m);
44            assertEquals(TestManager.class.getName(), m.getClass().getName());
45        } finally {
46            Security.setProperty(GSSManager.MANAGER, (oldProvider == null) ? ""
47                : oldProvider);
48        }
49    }
50
51    /**
52     * Tests loading of a default provider with invalid class references.
53     */
54    public void testGetInstance_invalid() {
55        String oldProvider = Security.getProperty(GSSManager.MANAGER);
56        try {
57            try {
58                Security.setProperty(GSSManager.MANAGER, "a.b.c.D");
59                GSSManager.getInstance();
60                fail("should throw SecurityException for invalid klass");
61            } catch (SecurityException ok) {
62            }
63            try {
64                Security.setProperty(GSSManager.MANAGER, "");
65                GSSManager.getInstance();
66                fail("should throw SecurityException for empty klass");
67            } catch (SecurityException ok) {
68            }
69        } finally {
70            Security.setProperty(GSSManager.MANAGER, (oldProvider == null) ? ""
71                : oldProvider);
72        }
73    }
74
75    public static class TestManager extends GSSManager {
76
77        @Override
78        public void addProviderAtEnd(Provider p, Oid mech) throws GSSException {
79        }
80
81        @Override
82        public void addProviderAtFront(Provider p, Oid mech)
83            throws GSSException {
84        }
85
86        @Override
87        public GSSContext createContext(byte[] interProcessToken)
88            throws GSSException {
89            return null;
90        }
91
92        @Override
93        public GSSContext createContext(GSSCredential myCred)
94            throws GSSException {
95            return null;
96        }
97
98        @Override
99        public GSSContext createContext(GSSName peer, Oid mech,
100                                        GSSCredential myCred, int lifetime)
101            throws GSSException {
102            return null;
103        }
104
105        @Override
106        public GSSCredential createCredential(GSSName name, int lifetime,
107                                              Oid mech, int usage)
108            throws GSSException {
109            return null;
110        }
111
112        @Override
113        public GSSCredential createCredential(GSSName name, int lifetime,
114                                              Oid[] mechs, int usage)
115            throws GSSException {
116            return null;
117        }
118
119        @Override
120        public GSSCredential createCredential(int usage) throws GSSException {
121            return null;
122        }
123
124        @Override
125        public GSSName createName(byte[] name, Oid nameType, Oid mech)
126            throws GSSException {
127            return null;
128        }
129
130        @Override
131        public GSSName createName(byte[] name, Oid nameType)
132            throws GSSException {
133            return null;
134        }
135
136        @Override
137        public GSSName createName(String nameStr, Oid nameType, Oid mech)
138            throws GSSException {
139            return null;
140        }
141
142        @Override
143        public GSSName createName(String nameStr, Oid nameType)
144            throws GSSException {
145            return null;
146        }
147
148        @Override
149        public Oid[] getMechs() {
150            return null;
151        }
152
153        @Override
154        public Oid[] getMechsForName(Oid nameType) {
155            return null;
156        }
157
158        @Override
159        public Oid[] getNamesForMech(Oid mech) throws GSSException {
160            return null;
161        }
162    }
163}
164