001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.io.crypto.tls;
019
020import static org.hamcrest.MatcherAssert.assertThat;
021import static org.hamcrest.Matchers.instanceOf;
022import static org.junit.jupiter.api.Assertions.assertThrows;
023
024import org.apache.hadoop.hbase.testclassification.SecurityTests;
025import org.apache.hadoop.hbase.testclassification.SmallTests;
026import org.junit.jupiter.api.Tag;
027import org.junit.jupiter.api.Test;
028
029/**
030 * This file has been copied from the Apache ZooKeeper project.
031 * @see <a href=
032 *      "https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/test/java/org/apache/zookeeper/common/FileKeyStoreLoaderBuilderProviderTest.java">Base
033 *      revision</a>
034 */
035@Tag(SecurityTests.TAG)
036@Tag(SmallTests.TAG)
037public class TestFileKeyStoreLoaderBuilderProvider {
038
039  @Test
040  public void testGetBuilderForJKSFileType() {
041    FileKeyStoreLoader.Builder<?> builder =
042      FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.JKS);
043    assertThat(builder, instanceOf(JKSFileLoader.Builder.class));
044  }
045
046  @Test
047  public void testGetBuilderForPEMFileType() {
048    FileKeyStoreLoader.Builder<?> builder =
049      FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.PEM);
050    assertThat(builder, instanceOf(PEMFileLoader.Builder.class));
051  }
052
053  @Test
054  public void testGetBuilderForPKCS12FileType() {
055    FileKeyStoreLoader.Builder<?> builder =
056      FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(KeyStoreFileType.PKCS12);
057    assertThat(builder, instanceOf(PKCS12FileLoader.Builder.class));
058  }
059
060  @Test
061  public void testGetBuilderForNullFileType() {
062    assertThrows(NullPointerException.class,
063      () -> FileKeyStoreLoaderBuilderProvider.getBuilderForKeyStoreFileType(null));
064  }
065}