2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2018-2023 Nordix Foundation. All rights reserved.
4 * Copyright (C) 2020 Nokia. All rights reserved.
5 * ===============================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
7 * except in compliance with the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the
12 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language governing permissions
14 * and limitations under the License.
15 * ============LICENSE_END========================================================================
18 package org.oran.datafile.ftp;
20 import static org.assertj.core.api.Assertions.assertThat;
23 import java.nio.file.Path;
25 import org.junit.jupiter.api.Test;
26 import org.junit.jupiter.api.io.TempDir;
27 import org.oran.datafile.configuration.SftpConfig;
29 public class SftpClientSettingsTest {
32 public void shouldUseFtpStrictHostChecking(@TempDir Path tempDir) throws Exception {
33 File knowHostsFile = new File(tempDir.toFile(), "known_hosts");
34 knowHostsFile.createNewFile();
36 SftpConfig config = createSampleSftpConfigWithStrictHostChecking(knowHostsFile.getAbsolutePath());
37 SftpClientSettings sftpClient = new SftpClientSettings(config);
39 assertThat(sftpClient.shouldUseStrictHostChecking()).isTrue();
43 public void shouldNotUseFtpStrictHostChecking_whenFileDoesNotExist() {
44 SftpConfig config = createSampleSftpConfigWithStrictHostChecking("unknown_file");
45 SftpClientSettings sftpClient = new SftpClientSettings(config);
47 sftpClient.shouldUseStrictHostChecking();
48 assertThat(sftpClient.shouldUseStrictHostChecking()).isFalse();
52 public void shouldNotUseFtpStrictHostChecking_whenExplicitlySwitchedOff() {
53 SftpClientSettings sftpClient = new SftpClientSettings(createSampleSftpConfigNoStrictHostChecking());
54 sftpClient.shouldUseStrictHostChecking();
55 assertThat(sftpClient.shouldUseStrictHostChecking()).isFalse();
58 private SftpConfig createSampleSftpConfigNoStrictHostChecking() {
59 return SftpConfig.builder() //
60 .strictHostKeyChecking(false).knownHostsFilePath("N/A").build();
63 private SftpConfig createSampleSftpConfigWithStrictHostChecking(String pathToKnownHostsFile) {
64 return SftpConfig.builder() //
65 .strictHostKeyChecking(true).knownHostsFilePath(pathToKnownHostsFile).build();