content: /*
   * Copyright 2021-2024 Aklivity Inc.
   *
   * Aklivity 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 io.aklivity.zilla.runtime.vault.filesystem.internal;
  
  import static org.hamcrest.MatcherAssert.assertThat;
  import static org.hamcrest.Matchers.not;
  import static org.hamcrest.Matchers.nullValue;
  
  import java.net.URI;
  import java.net.URL;
  import java.nio.file.Path;
  import java.util.List;
  
  import javax.net.ssl.KeyManagerFactory;
  import javax.net.ssl.TrustManagerFactory;
  
  import org.junit.Test;
  
  import io.aklivity.zilla.runtime.vault.filesystem.config.FileSystemOptionsConfig;
  
  public class FileSystemVaultTest
  {
      @Test
      public void shouldResolveServer() throws Exception
      {
          FileSystemOptionsConfig options = FileSystemOptionsConfig.builder()
              .keys()
                  .store("stores/server/keys")
                  .type("pkcs12")
                  .password("generated")
                  .build()
              .trust()
                  .store("stores/server/trust")
                  .type("pkcs12")
                  .password("generated")
                  .build()
              .build();
  
          FileSystemVaultHandler vault = new FileSystemVaultHandler(options, FileSystemVaultTest::resourcePath);
  
          KeyManagerFactory keys = vault.initKeys(List.of("localhost"));
          TrustManagerFactory trust = vault.initTrust(List.of("clientca"), null);
  
          assertThat(keys, not(nullValue()));
          assertThat(trust, not(nullValue()));
      }
  
      @Test
      public void shouldResolveClient() throws Exception
      {
          FileSystemOptionsConfig options = FileSystemOptionsConfig.builder()
              .keys()
                  .store("stores/client/keys")
                  .type("pkcs12")
                  .password("generated")
                  .build()
              .signers()
                  .store("stores/server/trust")
                  .type("pkcs12")
                  .password("generated")
                  .build()
              .build();
  
          FileSystemVaultHandler vault = new FileSystemVaultHandler(options, FileSystemVaultTest::resourcePath, null);
  
          KeyManagerFactory keys = vault.initSigners(List.of("clientca"));
  
          assertThat(keys, not(nullValue()));
      }
  
      public static Path resourcePath(
          String resource)
      {
          URL url = FileSystemVaultTest.class.getResource(resource);
          assert url != null;
          return Path.of(URI.create(url.toString()));
      }
  }
  