blob: 65bec3bd83b6e5219bce8db405b528d927e9ad81 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.directory.server.core.security;
import static org.junit.Assert.*;
import java.io.FileInputStream;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import javax.naming.NamingException;
import org.apache.directory.server.core.entry.DefaultServerEntry;
import org.apache.directory.server.schema.bootstrap.ApacheSchema;
import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
import org.apache.directory.server.schema.bootstrap.CoreSchema;
import org.apache.directory.server.schema.bootstrap.CosineSchema;
import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
import org.apache.directory.server.schema.bootstrap.Schema;
import org.apache.directory.server.schema.bootstrap.SystemSchema;
import org.apache.directory.server.schema.registries.DefaultOidRegistry;
import org.apache.directory.server.schema.registries.DefaultRegistries;
import org.apache.directory.server.schema.registries.OidRegistry;
import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Test for the TlsKeyGenerator class.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
public class TlsKeyGeneratorTest
{
private static final Logger LOG = LoggerFactory.getLogger( TlsKeyGeneratorTest.class );
private static BootstrapSchemaLoader loader;
private static Registries registries;
private static OidRegistry oidRegistry;
/**
* Initialize the registries once for the whole test suite
*/
@BeforeClass
public static void setup() throws NamingException
{
loader = new BootstrapSchemaLoader();
oidRegistry = new DefaultOidRegistry();
registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
// load essential bootstrap schemas
Set<Schema> bootstrapSchemas = new HashSet<Schema>();
bootstrapSchemas.add( new ApachemetaSchema() );
bootstrapSchemas.add( new ApacheSchema() );
bootstrapSchemas.add( new CoreSchema() );
bootstrapSchemas.add( new SystemSchema() );
bootstrapSchemas.add( new InetorgpersonSchema() );
bootstrapSchemas.add( new CosineSchema() );
loader.loadWithDependencies( bootstrapSchemas, registries );
}
/**
* Test method for all methods in one.
*/
@Test
public void testAll() throws NamingException
{
DefaultServerEntry entry = new DefaultServerEntry( registries, new LdapDN() );
TlsKeyGenerator.addKeyPair( entry );
LOG.debug( "Entry: {}", entry );
assertTrue( entry.contains( SchemaConstants.OBJECT_CLASS_AT, TlsKeyGenerator.TLS_KEY_INFO_OC ) );
KeyPair keyPair = TlsKeyGenerator.getKeyPair( entry );
assertNotNull( keyPair );
X509Certificate cert = TlsKeyGenerator.getCertificate( entry );
assertNotNull( cert );
}
}