1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 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 ******************************************************************************/
22 package org.onap.aaf.auth.dao.aaf.test;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.io.InputStream;
29 import java.security.NoSuchAlgorithmException;
30 import java.util.Properties;
32 import org.junit.After;
33 import org.junit.AfterClass;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.onap.aaf.auth.dao.CassAccess;
37 import org.onap.aaf.auth.dao.CassDAOImpl;
38 import org.onap.aaf.auth.env.AuthzEnv;
39 import org.onap.aaf.auth.env.AuthzTrans;
40 import org.onap.aaf.cadi.Hash;
41 import org.onap.aaf.cadi.Symm;
42 import org.onap.aaf.misc.env.APIException;
43 import org.onap.aaf.misc.env.Env;
44 import org.onap.aaf.misc.env.Trans.Metric;
46 import com.datastax.driver.core.Cluster;
48 import junit.framework.Assert;
51 * Do Setup of Cassandra for Cassandra JUnit Testing
55 public class AbsJUCass {
56 protected static final String AUTHZ = "authz";
57 protected static Cluster cluster;
58 protected static AuthzEnv env;
59 protected static int iterations = 0;
60 protected static float totals=0.0f;
61 protected static float remote = 0.0f;
62 protected static float json = 0.0f;
63 protected static AuthzTrans trans;
64 protected static boolean details = true;
67 public static void startup() throws APIException, IOException {
70 final String resource = "cadi.properties";
71 File f = new File("etc" + resource);
73 Properties props = new Properties();
76 is = new FileInputStream(f);
78 URL rsrc = ClassLoader.getSystemResource(resource);
79 is = rsrc.openStream();
85 Assert.fail(resource + " must exist in etc dir, or in Classpath");
89 env = new AuthzEnv(props);
92 cluster = CassAccess.cluster(env,"LOCAL");
94 env.info().log("Connecting to Cluster");
96 cluster.connect(AUTHZ);
97 } catch(Exception e) {
100 Assert.fail("Not able to connect to DB: " + e.getLocalizedMessage());
102 env.info().log("Connected");
104 // Load special data here
107 env.setProperty("java.naming.provider.url","ldap://ldap.webphone.att.com:389");
108 env.setProperty("com.sun.jndi.ldap.connect.pool","true");
115 public static void shutdown() {
123 public void newTrans() {
124 trans = env.newTrans();
126 trans.setProperty(CassDAOImpl.USER_NAME, System.getProperty("user.name"));
130 public void auditTrail() {
131 if(totals==0) { // "updateTotals()" was not called... just do one Trans
132 StringBuilder sb = new StringBuilder();
133 Metric metric = trans.auditTrail(4, sb, Env.JSON, Env.REMOTE);
138 totals += metric.total,
145 totals += metric.total;
150 protected void updateTotals() {
151 Metric metric = trans.auditTrail(0, null, Env.JSON, Env.REMOTE);
152 totals+=metric.total;
153 json +=metric.buckets[0];
154 remote+=metric.buckets[1];
159 public static void print() {
164 transTime=totals/iterations;
181 * Take a User/Pass and turn into an MD5 Hashed BasicAuth
186 * @throws IOException
187 * @throws NoSuchAlgorithmException
189 //TODO: Gabe [JUnit] Issue
190 public static byte[] userPassToBytes(String user, String pass)
191 throws IOException, NoSuchAlgorithmException {
192 // Take the form of BasicAuth, so as to allow any character in Password
193 // (this is an issue in 1.0)
194 // Also, it makes it quicker to evaluate Basic Auth direct questions
195 String ba = Symm.base64url.encode(user + ':' + pass);
196 // Take MD5 Hash, so that data in DB can't be reversed out.
197 return Hash.hashMD5(ba.getBytes());