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