2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.db.catalog.beans;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
27 import java.security.GeneralSecurityException;
29 import org.junit.Test;
30 import org.onap.so.db.catalog.beans.AuthenticationType;
31 import org.onap.so.db.catalog.beans.CloudIdentity;
32 import org.onap.so.db.catalog.beans.ServerType;
33 import org.onap.so.utils.CryptoUtils;
35 public class CloudIdentityTest {
37 private CloudIdentity cloudIdentity = new CloudIdentity();
38 private static final String ID = "testId";
39 private static final String IDENTITY_URL = "testIdentityUrl";
40 private static final String MSO_ID = "testMsoId";
41 private static final String MSO_PASS = "testMsoPassword";
42 private static final String ADMIN_TENANT = "testAdminTenant";
43 private static final String MEMBER_ROLE = "testMemberRole";
44 private static final Boolean TENANT_METADATA = true;
47 public final void testCloudIdentity () {
48 CloudIdentity id = new CloudIdentity ();
49 id.setAdminTenant ("AdminTenant");
51 // id.setKeystoneUrl ("keystone");
52 id.setIdentityUrl ("keystone");
53 id.setMemberRole ("member");
54 id.setMsoId ("msoId");
55 id.setMsoPass (CryptoUtils.encryptCloudConfigPassword("password"));
56 id.setTenantMetadata (true);
57 id.setIdentityServerType(null);
58 id.setIdentityAuthenticationType(null);
61 assertTrue (id.getAdminTenant ().equals ("AdminTenant"));
62 assertTrue (id.getId ().equals ("id"));
63 // assertTrue (id.getKeystoneUrl ().equals ("keystone"));
64 assertTrue (id.getMemberRole ().equals ("member"));
65 assertTrue (id.getMsoId ().equals ("msoId"));
66 assertTrue (CryptoUtils.decryptCloudConfigPassword(id.getMsoPass()).equals ("password"));
67 assertTrue (id.getTenantMetadata ());
68 // assertTrue (id.toString ().contains ("keystone"));
69 assertTrue(id.toString().contains("null"));
73 public final void testEncryption () throws GeneralSecurityException {
74 String encrypted = CryptoUtils.encryptCloudConfigPassword("password");
75 assertTrue (encrypted != null);
76 assertTrue (!encrypted.equals ("password"));
80 public void cloneTest() {
81 cloudIdentity = setupCloudIdentity(cloudIdentity, ID, IDENTITY_URL, MSO_ID, MSO_PASS, ADMIN_TENANT,
82 MEMBER_ROLE, TENANT_METADATA, ServerType.ORM, AuthenticationType.USERNAME_PASSWORD);
83 CloudIdentity cloudIdentity2 = cloudIdentity.clone();
85 assertEquals(cloudIdentity.getClass(), cloudIdentity2.getClass());
88 private CloudIdentity setupCloudIdentity(CloudIdentity obj, String id, String identityUrl,
89 String msoId, String msoPass, String adminTenant, String memberRole, Boolean tenantMetadata,
90 ServerType identityServerType, AuthenticationType identityAuthenticationType) {
92 obj.setIdentityUrl(identityUrl);
94 obj.setMsoPass(msoPass);
95 obj.setAdminTenant(adminTenant);
96 obj.setMemberRole(memberRole);
97 obj.setTenantMetadata(tenantMetadata);
98 obj.setIdentityServerType(identityServerType);
99 obj.setIdentityAuthenticationType(identityAuthenticationType);