2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property.
\r
6 * Copyright © 2017 Amdocs
\r
7 * All rights reserved.
\r
8 * ================================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 * ECOMP and OpenECOMP are trademarks
\r
21 * and service marks of AT&T Intellectual Property.
\r
23 package org.openecomp.modelloader.config;
\r
25 import static org.junit.Assert.assertEquals;
\r
26 import static org.junit.Assert.assertFalse;
\r
28 import java.io.FileInputStream;
\r
29 import java.io.IOException;
\r
30 import java.util.List;
\r
31 import java.util.Properties;
\r
33 import org.eclipse.jetty.util.security.Password;
\r
34 import org.junit.Test;
\r
35 import org.openecomp.modelloader.restclient.AaiRestClient;
\r
37 import org.openecomp.sdc.utils.ArtifactTypeEnum;
\r
39 public class ModelLoaderConfigTest {
\r
42 public void testYangModelArtifactType() {
\r
43 Properties props = new Properties();
\r
44 props.setProperty("ml.distribution.ARTIFACT_TYPES",
\r
45 "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
\r
46 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
48 List<String> types = config.getRelevantArtifactTypes();
\r
50 System.out.println("ArtifactType: " + types.get(0));
\r
52 types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
\r
54 System.out.println("ArtifactType: " + types.get(1));
\r
55 assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
\r
57 System.out.println("ArtifactType: " + types.get(2));
\r
58 assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
\r
60 assertEquals(3, types.size());
\r
64 public void testDecryptPassword() {
\r
65 Properties props = new Properties();
\r
66 String testPass = "youshallnotpass";
\r
67 String encryptedTestPass = Password.obfuscate(testPass);
\r
69 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
\r
71 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
\r
72 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
74 assertEquals(testPass, config.getPassword());
\r
78 public void testDecryptKeystorePassword() {
\r
79 Properties props = new Properties();
\r
80 String testPass = "youshallnotpass";
\r
81 String encryptedTestPass = Password.obfuscate(testPass);
\r
83 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
\r
85 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
\r
86 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
88 assertEquals(testPass, config.getKeyStorePassword());
\r
92 public void testDecryptAAIPassword() {
\r
94 Properties props = new Properties();
\r
95 String testPassword = "myvoiceismypassword";
\r
96 String encryptedTestPassword = Password.obfuscate(testPassword);
\r
98 props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
\r
99 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
101 assertEquals(testPassword, config.getAaiAuthenticationPassword());
\r
105 public void testNoAAIAuth() throws IOException {
\r
107 Properties props = new Properties();
\r
109 new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));
\r
111 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
112 AaiRestClient aaiClient = new AaiRestClient(config);
\r
114 assertFalse("Empty AAI Password should result in no basic authentication",
\r
115 aaiClient.useBasicAuth());
\r
117 props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
\r
118 config = new ModelLoaderConfig(props, null);
\r
119 aaiClient = new AaiRestClient(config);
\r
121 assertFalse("No AAI Password should result in no basic authentication",
\r
122 aaiClient.useBasicAuth());
\r