Search in sources :

Example 1 with ColumnVisibilitySecurityMarking

use of datawave.marking.ColumnVisibilitySecurityMarking in project datawave by NationalSecurityAgency.

the class QueryExecutorBeanTest method setup.

@Before
public void setup() throws Exception {
    System.setProperty(NpeUtils.NPE_OU_PROPERTY, "iamnotaperson");
    System.setProperty("dw.metadatahelper.all.auths", "A,B,C,D");
    QueryTraceCache traceCache = new QueryTraceCache();
    Whitebox.invokeMethod(traceCache, "init");
    cache = new QueryCache();
    cache.init();
    closedCache = new ClosedQueryCache();
    bean = new QueryExecutorBean();
    connectionFactory = createStrictMock(AccumuloConnectionFactory.class);
    auditor = new AuditBean();
    auditService = createStrictMock(AuditService.class);
    metrics = createStrictMock(QueryMetricsBean.class);
    queryLogicFactory = createStrictMock(QueryLogicFactoryImpl.class);
    persister = createStrictMock(Persister.class);
    predictor = createStrictMock(QueryPredictor.class);
    ctx = createStrictMock(EJBContext.class);
    qlCache = new CreatedQueryLogicCacheBean();
    queryExpirationConf = new QueryExpirationConfiguration();
    queryExpirationConf.setPageSizeShortCircuitCheckTime(45);
    queryExpirationConf.setPageShortCircuitTimeout(58);
    queryExpirationConf.setCallTime(60);
    connectionRequestBean = createStrictMock(AccumuloConnectionRequestBean.class);
    setInternalState(auditor, AuditService.class, auditService);
    setInternalState(auditor, AuditParameterBuilder.class, new DefaultAuditParameterBuilder());
    setInternalState(connectionRequestBean, EJBContext.class, ctx);
    setInternalState(bean, QueryCache.class, cache);
    setInternalState(bean, ClosedQueryCache.class, closedCache);
    setInternalState(bean, AccumuloConnectionFactory.class, connectionFactory);
    setInternalState(bean, AuditBean.class, auditor);
    setInternalState(bean, QueryMetricsBean.class, metrics);
    setInternalState(bean, QueryLogicFactory.class, queryLogicFactory);
    setInternalState(bean, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(bean, Persister.class, persister);
    setInternalState(bean, QueryPredictor.class, predictor);
    setInternalState(bean, EJBContext.class, ctx);
    setInternalState(bean, CreatedQueryLogicCacheBean.class, qlCache);
    setInternalState(bean, QueryTraceCache.class, traceCache);
    setInternalState(bean, Multimap.class, HashMultimap.create());
    setInternalState(bean, LookupUUIDConfiguration.class, new LookupUUIDConfiguration());
    setInternalState(bean, SecurityMarking.class, new ColumnVisibilitySecurityMarking());
    setInternalState(bean, QueryParameters.class, new QueryParametersImpl());
    setInternalState(bean, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    setInternalState(bean, AccumuloConnectionRequestBean.class, connectionRequestBean);
    // RESTEasy mock stuff
    dispatcher = MockDispatcherFactory.createDispatcher();
    dispatcher.getRegistry().addSingletonResource(bean, "/DataWave/Query");
    response = new MockHttpResponse();
}
Also used : LookupUUIDConfiguration(datawave.webservice.query.configuration.LookupUUIDConfiguration) ClosedQueryCache(datawave.webservice.query.cache.ClosedQueryCache) QueryCache(datawave.webservice.query.cache.QueryCache) EJBContext(javax.ejb.EJBContext) QueryLogicFactoryImpl(datawave.webservice.query.logic.QueryLogicFactoryImpl) QueryExpirationConfiguration(datawave.webservice.query.cache.QueryExpirationConfiguration) AuditBean(datawave.webservice.common.audit.AuditBean) CreatedQueryLogicCacheBean(datawave.webservice.query.cache.CreatedQueryLogicCacheBean) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) ClosedQueryCache(datawave.webservice.query.cache.ClosedQueryCache) AccumuloConnectionFactory(datawave.webservice.common.connection.AccumuloConnectionFactory) ColumnVisibilitySecurityMarking(datawave.marking.ColumnVisibilitySecurityMarking) QueryTraceCache(datawave.webservice.query.cache.QueryTraceCache) QueryMetricsBean(datawave.webservice.query.metric.QueryMetricsBean) DefaultAuditParameterBuilder(datawave.webservice.common.audit.DefaultAuditParameterBuilder) Persister(datawave.webservice.query.factory.Persister) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) AuditService(datawave.webservice.common.audit.AuditService) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Before(org.junit.Before)

Example 2 with ColumnVisibilitySecurityMarking

use of datawave.marking.ColumnVisibilitySecurityMarking in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testCreateQuery_auditException.

@Test(expected = DatawaveWebApplicationException.class)
public void testCreateQuery_auditException() throws Exception {
    String queryLogicName = "queryLogicName";
    String query = "query";
    String queryName = "queryName";
    String queryVisibility = "A&B";
    long currentTime = System.currentTimeMillis();
    Date beginDate = new Date(currentTime - 5000);
    Date endDate = new Date(currentTime - 1000);
    String queryAuthorizations = "AUTH_1";
    Date expirationDate = new Date(currentTime + 999999);
    int pagesize = 10;
    QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
    boolean trace = false;
    String userName = "userName";
    String userSid = "userSid";
    String userDN = "userDN";
    SubjectIssuerDNPair userDNpair = SubjectIssuerDNPair.of(userDN);
    List<String> dnList = Collections.singletonList(userDN);
    UUID queryId = UUID.randomUUID();
    long pageNumber = 0L;
    HashMap<String, Collection<String>> authsMap = new HashMap<>();
    authsMap.put("USERDN", Arrays.asList(queryAuthorizations));
    MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
    queryParameters.putSingle(QueryParameters.QUERY_STRING, query);
    queryParameters.putSingle(QueryParameters.QUERY_NAME, queryName);
    queryParameters.putSingle(QueryParameters.QUERY_LOGIC_NAME, queryLogicName);
    queryParameters.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(beginDate));
    queryParameters.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(endDate));
    queryParameters.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expirationDate));
    queryParameters.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, queryAuthorizations);
    queryParameters.putSingle(QueryParameters.QUERY_PAGESIZE, String.valueOf(pagesize));
    queryParameters.putSingle(QueryParameters.QUERY_PERSISTENCE, persistenceMode.name());
    queryParameters.putSingle(QueryParameters.QUERY_TRACE, String.valueOf(trace));
    queryParameters.putSingle(ColumnVisibilitySecurityMarking.VISIBILITY_MARKING, queryVisibility);
    queryParameters.putSingle("valid", "param");
    expect(context.getCallerPrincipal()).andReturn(principal).anyTimes();
    expect(this.queryLogicFactory.getQueryLogic(queryLogicName, this.principal)).andReturn((QueryLogic) this.queryLogic1);
    queryLogic1.validate(queryParameters);
    expect(principal.getName()).andReturn(userName);
    expect(principal.getShortName()).andReturn(userSid);
    expect(principal.getUserDN()).andReturn(userDNpair);
    expect(principal.getDNs()).andReturn(new String[] { userDN });
    expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0)).anyTimes();
    expect(this.queryLogic1.containsDNWithAccess(Collections.singletonList(userDN))).andReturn(true);
    expect(this.queryLogic1.getAuditType(null)).andReturn(AuditType.ACTIVE);
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList(queryAuthorizations)));
    expect(this.queryLogic1.getMaxPageSize()).andReturn(10).anyTimes();
    expect(queryLogic1.getSelectors(null)).andReturn(null);
    expect(auditor.audit(queryParameters)).andThrow(new JMSRuntimeException("EXPECTED TESTING EXCEPTION"));
    queryLogic1.close();
    PowerMock.replayAll();
    QueryExecutorBean executor = new QueryExecutorBean();
    setInternalState(executor, EJBContext.class, context);
    setInternalState(executor, AccumuloConnectionFactory.class, connectionFactory);
    setInternalState(executor, ResponseObjectFactory.class, responseObjectFactory);
    setInternalState(executor, CreatedQueryLogicCacheBean.class, qlCache);
    setInternalState(executor, QueryCache.class, cache);
    setInternalState(executor, ClosedQueryCache.class, closedCache);
    setInternalState(executor, Persister.class, persister);
    setInternalState(executor, QueryLogicFactoryImpl.class, queryLogicFactory);
    setInternalState(executor, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(executor, AuditBean.class, auditor);
    setInternalState(executor, QueryMetricsBean.class, metrics);
    setInternalState(executor, Multimap.class, traceInfos);
    setInternalState(executor, SecurityMarking.class, new ColumnVisibilitySecurityMarking());
    setInternalState(executor, QueryParameters.class, new QueryParametersImpl());
    setInternalState(executor, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    setInternalState(connectionRequestBean, EJBContext.class, context);
    setInternalState(executor, AccumuloConnectionRequestBean.class, connectionRequestBean);
    executor.createQuery(queryLogicName, queryParameters);
    PowerMock.verifyAll();
}
Also used : SubjectIssuerDNPair(datawave.security.authorization.SubjectIssuerDNPair) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Date(java.util.Date) ColumnVisibilitySecurityMarking(datawave.marking.ColumnVisibilitySecurityMarking) QueryPersistence(datawave.webservice.query.QueryPersistence) Collection(java.util.Collection) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ColumnVisibilitySecurityMarking

use of datawave.marking.ColumnVisibilitySecurityMarking in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testDefineQuery_UncheckedException.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(expected = IllegalArgumentException.class)
public void testDefineQuery_UncheckedException() throws Exception {
    // Set local test input
    String queryLogicName = "queryLogicName";
    String query = "query";
    String queryName = "queryName";
    String queryVisibility = "A&B";
    long currentTime = System.currentTimeMillis();
    Date beginDate = new Date(currentTime - 5000);
    Date endDate = new Date(currentTime - 1000);
    String queryAuthorizations = "AUTH_1";
    Date expirationDate = new Date(currentTime + 10000);
    int pagesize = 10;
    int pageTimeout = -1;
    Long maxResultsOverride = null;
    QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
    String userName = "userName";
    String userSid = "userSid";
    String userDN = "userdn";
    SubjectIssuerDNPair userDNpair = SubjectIssuerDNPair.of(userDN);
    boolean trace = false;
    List<String> dnList = Collections.singletonList(userDN);
    UUID queryId = UUID.randomUUID();
    MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
    queryParameters.putAll(QueryParametersImpl.paramsToMap(null, query, queryName, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, null, trace));
    queryParameters.putSingle("valid", "param");
    ColumnVisibilitySecurityMarking marking = new ColumnVisibilitySecurityMarking();
    marking.validate(queryParameters);
    QueryParameters qp = new QueryParametersImpl();
    qp.validate(queryParameters);
    MultivaluedMap<String, String> op = new MultivaluedMapImpl<>();
    op.putAll(qp.getUnknownParameters(queryParameters));
    op.putSingle(PrivateAuditConstants.LOGIC_CLASS, queryLogicName);
    op.putSingle(PrivateAuditConstants.COLUMN_VISIBILITY, queryVisibility);
    op.putSingle(PrivateAuditConstants.USER_DN, userDNpair.subjectDN());
    // Set expectations
    queryLogic1.validate(queryParameters);
    expect(this.context.getCallerPrincipal()).andReturn(this.principal).anyTimes();
    expect(this.principal.getName()).andReturn(userName);
    expect(this.principal.getShortName()).andReturn(userSid);
    expect(this.principal.getDNs()).andReturn(new String[] { userDN });
    expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0));
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList(queryAuthorizations)));
    expect(this.principal.getUserDN()).andReturn(userDNpair);
    expect(persister.create(eq(userDNpair.subjectDN()), eq(dnList), eq(marking), eq(queryLogicName), eq(qp), eq(op))).andReturn(this.query);
    expect(this.query.getId()).andReturn(queryId).times(3);
    expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn((QueryLogic) this.queryLogic1);
    expect(this.queryLogic1.getMaxPageSize()).andReturn(100).times(2);
    expect(this.traceInfos.get(userSid)).andReturn(new ArrayList<>(0));
    expect(this.traceInfos.get(null)).andReturn(Arrays.asList(PatternWrapper.wrap(query)));
    PowerMock.mockStaticPartial(Trace.class, "start");
    expect(Trace.start("query:define")).andReturn(this.span);
    expect(this.queryLogic1.getConnectionPriority()).andThrow(ILLEGAL_STATE_EXCEPTION);
    // TODO: 1.8.1: no longer done
    // expect(this.span.parent()).andReturn(this.span);
    // expect(this.span.parent()).andReturn(this.span);
    this.span.stop();
    // Run the test
    PowerMock.replayAll();
    try {
        QueryExecutorBean subject = new QueryExecutorBean();
        setInternalState(subject, EJBContext.class, context);
        setInternalState(subject, Persister.class, persister);
        setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
        setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
        setInternalState(subject, Multimap.class, traceInfos);
        setInternalState(subject, SecurityMarking.class, new ColumnVisibilitySecurityMarking());
        setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
        setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
        subject.defineQuery(queryLogicName, queryParameters);
    } finally {
        PowerMock.verifyAll();
    }
}
Also used : SubjectIssuerDNPair(datawave.security.authorization.SubjectIssuerDNPair) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParameters(datawave.webservice.query.QueryParameters) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Date(java.util.Date) ColumnVisibilitySecurityMarking(datawave.marking.ColumnVisibilitySecurityMarking) QueryPersistence(datawave.webservice.query.QueryPersistence) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ColumnVisibilitySecurityMarking

use of datawave.marking.ColumnVisibilitySecurityMarking in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testPlanQueryWithValues.

@Test
public void testPlanQueryWithValues() throws Exception {
    // Set local test input
    String queryLogicName = "queryLogicName";
    String query = "query";
    String queryName = "queryName";
    String queryVisibility = "A&B";
    long currentTime = System.currentTimeMillis();
    Date beginDate = new Date(currentTime - 5000);
    Date endDate = new Date(currentTime - 1000);
    String queryAuthorizations = "AUTH_1";
    Date expirationDate = new Date(currentTime + 999999);
    int pagesize = 10;
    int pageTimeout = -1;
    QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
    boolean trace = false;
    String userName = "userName";
    String userSid = "userSid";
    String userDN = "userdn";
    SubjectIssuerDNPair userDNpair = SubjectIssuerDNPair.of(userDN);
    List<String> dnList = Collections.singletonList(userDN);
    UUID queryId = UUID.randomUUID();
    HashMap<String, Collection<String>> authsMap = new HashMap<>();
    authsMap.put("userdn", Arrays.asList(queryAuthorizations));
    MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
    queryParameters.putSingle(QueryParameters.QUERY_LOGIC_NAME, queryLogicName);
    queryParameters.putSingle(QueryParameters.QUERY_STRING, query);
    queryParameters.putSingle(QueryParameters.QUERY_NAME, queryName);
    queryParameters.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(beginDate));
    queryParameters.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(endDate));
    queryParameters.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expirationDate));
    queryParameters.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, queryAuthorizations);
    queryParameters.putSingle(QueryParameters.QUERY_PAGESIZE, String.valueOf(pagesize));
    queryParameters.putSingle(QueryParameters.QUERY_PAGETIMEOUT, String.valueOf(pageTimeout));
    queryParameters.putSingle(QueryParameters.QUERY_PERSISTENCE, persistenceMode.name());
    queryParameters.putSingle(QueryParameters.QUERY_TRACE, String.valueOf(trace));
    queryParameters.putSingle(ColumnVisibilitySecurityMarking.VISIBILITY_MARKING, queryVisibility);
    queryParameters.putSingle("valid", "param");
    queryParameters.putSingle(QueryExecutorBean.EXPAND_VALUES, "true");
    ColumnVisibilitySecurityMarking marking = new ColumnVisibilitySecurityMarking();
    marking.validate(queryParameters);
    QueryParameters qp = new QueryParametersImpl();
    qp.validate(queryParameters);
    MultivaluedMap<String, String> op = new MultivaluedMapImpl<>();
    op.putAll(qp.getUnknownParameters(queryParameters));
    // op.putSingle(PrivateAuditConstants.AUDIT_TYPE, AuditType.NONE.name());
    op.putSingle(PrivateAuditConstants.LOGIC_CLASS, queryLogicName);
    op.putSingle(PrivateAuditConstants.COLUMN_VISIBILITY, queryVisibility);
    op.putSingle(PrivateAuditConstants.USER_DN, userDNpair.subjectDN());
    // Set expectations of the create logic
    queryLogic1.validate(queryParameters);
    // this.query.populateMetric(isA(QueryMetric.class));
    expect(this.queryLogicFactory.getQueryLogic(queryLogicName, this.principal)).andReturn((QueryLogic) this.queryLogic1);
    expect(this.queryLogic1.getMaxPageSize()).andReturn(1000).times(2);
    expect(this.context.getCallerPrincipal()).andReturn(this.principal).anyTimes();
    expect(this.principal.getName()).andReturn(userName);
    expect(this.principal.getShortName()).andReturn(userSid);
    expect(this.principal.getUserDN()).andReturn(userDNpair);
    expect(this.principal.getDNs()).andReturn(new String[] { userDN });
    expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0)).anyTimes();
    expect(this.queryLogic1.containsDNWithAccess(Collections.singletonList(userDN))).andReturn(true);
    expect(this.queryLogic1.getAuditType(null)).andReturn(AuditType.PASSIVE);
    expect(this.queryLogic1.getSelectors(this.query)).andReturn(null);
    expect(auditor.audit(eq(queryParameters))).andReturn(null);
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList(queryAuthorizations)));
    expect(persister.create(eq(userDNpair.subjectDN()), eq(dnList), eq(marking), eq(queryLogicName), eq(qp), eq(op))).andReturn(this.query);
    expect(this.queryLogic1.getAuditType(this.query)).andReturn(AuditType.PASSIVE);
    expect(this.queryLogic1.getConnectionPriority()).andReturn(Priority.NORMAL);
    expect(this.queryLogic1.getConnPoolName()).andReturn("connPool1");
    expect(this.connectionFactory.getTrackingMap(isA(StackTraceElement[].class))).andReturn(null);
    this.connectionRequestBean.requestBegin(queryId.toString());
    expect(this.connectionFactory.getConnection("connPool1", Priority.NORMAL, null)).andReturn(this.connector);
    this.connectionRequestBean.requestEnd(queryId.toString());
    // expect(this.traceInfos.get(userSid)).andReturn(new ArrayList<>(0));
    // expect(this.traceInfos.get(null)).andReturn(Arrays.asList(PatternWrapper.wrap("NONMATCHING_REGEX")));
    // expect(this.qlCache.add(queryId.toString(), userSid, this.queryLogic1, this.connector)).andReturn(true);
    expect(this.principal.getPrimaryUser()).andReturn(dwUser);
    expect(this.dwUser.getAuths()).andReturn(Collections.singleton(queryAuthorizations));
    expect(this.principal.getProxiedUsers()).andReturn(Collections.singletonList(dwUser));
    expect(this.query.getOwner()).andReturn(userSid).anyTimes();
    expect(this.query.getId()).andReturn(queryId).anyTimes();
    expect(this.query.getQuery()).andReturn(queryName).anyTimes();
    expect(this.query.getQueryLogicName()).andReturn(queryLogicName).anyTimes();
    expect(this.query.getBeginDate()).andReturn(null).anyTimes();
    expect(this.query.getEndDate()).andReturn(null).anyTimes();
    expect(this.query.getColumnVisibility()).andReturn(null).anyTimes();
    expect(this.query.getQueryAuthorizations()).andReturn(queryAuthorizations).anyTimes();
    expect(this.query.getQueryName()).andReturn(null).anyTimes();
    expect(this.query.getPagesize()).andReturn(0).anyTimes();
    expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
    expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
    expect(this.query.getUncaughtExceptionHandler()).andReturn(new QueryUncaughtExceptionHandler()).anyTimes();
    // this.metrics.updateMetric(isA(QueryMetric.class));
    // PowerMock.expectLastCall().times(2);
    expect(this.query.getUserDN()).andReturn(userDN).anyTimes();
    // expect(this.genericConfiguration.getQueryString()).andReturn(queryName).once();
    // expect(this.qlCache.poll(queryId.toString())).andReturn(null);
    // Set expectations of the plan
    Authorizations queryAuths = new Authorizations(queryAuthorizations);
    expect(this.queryLogic1.getPlan(this.connector, this.query, Collections.singleton(queryAuths), true, true)).andReturn("a query plan");
    // Set expectations of the cleanup
    this.connectionFactory.returnConnection(this.connector);
    EasyMock.expectLastCall().times(2);
    queryLogic1.close();
    EasyMock.expectLastCall();
    // Run the test
    PowerMock.replayAll();
    QueryExecutorBean subject = new QueryExecutorBean();
    setInternalState(subject, EJBContext.class, context);
    setInternalState(subject, AccumuloConnectionFactory.class, connectionFactory);
    setInternalState(subject, ResponseObjectFactory.class, responseObjectFactory);
    setInternalState(subject, CreatedQueryLogicCacheBean.class, qlCache);
    setInternalState(subject, QueryCache.class, cache);
    setInternalState(subject, ClosedQueryCache.class, closedCache);
    setInternalState(subject, Persister.class, persister);
    setInternalState(subject, QueryLogicFactoryImpl.class, queryLogicFactory);
    setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(subject, AuditBean.class, auditor);
    setInternalState(subject, QueryMetricsBean.class, metrics);
    setInternalState(subject, Multimap.class, traceInfos);
    setInternalState(subject, SecurityMarking.class, new ColumnVisibilitySecurityMarking());
    setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
    setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    setInternalState(connectionRequestBean, EJBContext.class, context);
    setInternalState(subject, AccumuloConnectionRequestBean.class, connectionRequestBean);
    GenericResponse<String> result1 = subject.planQuery(queryLogicName, queryParameters);
    PowerMock.verifyAll();
    // Verify results
    assertNotNull("Expected a non-null response", result1);
    assertEquals("a query plan", result1.getResult());
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SubjectIssuerDNPair(datawave.security.authorization.SubjectIssuerDNPair) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ArrayList(java.util.ArrayList) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParameters(datawave.webservice.query.QueryParameters) QueryUncaughtExceptionHandler(datawave.webservice.query.util.QueryUncaughtExceptionHandler) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Date(java.util.Date) ColumnVisibilitySecurityMarking(datawave.marking.ColumnVisibilitySecurityMarking) QueryPersistence(datawave.webservice.query.QueryPersistence) Collection(java.util.Collection) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ColumnVisibilitySecurityMarking

use of datawave.marking.ColumnVisibilitySecurityMarking in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testDuplicateQuery_HappyPath.

@Ignore
// TODO: Fix Query duplicate method
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDuplicateQuery_HappyPath() throws Exception {
    // Set local test input
    String queryLogicName = "queryLogicName";
    String query = "query";
    String newQueryName = "newQueryName";
    String queryVisibility = "A&B";
    long currentTime = System.currentTimeMillis();
    Date beginDate = new Date(currentTime - 5000);
    Date endDate = new Date(currentTime - 1000);
    String queryAuthorizations = "AUTH_1";
    Date expirationDate = new Date(currentTime + 9999);
    int pagesize = 10;
    int pageTimeout = -1;
    Long maxResultsOverride = null;
    QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
    String parameters = "invalidparam; valid:param";
    boolean trace = true;
    String userName = "userName";
    String userSid = "userSid";
    String userDN = "userDN";
    SubjectIssuerDNPair userDNpair = SubjectIssuerDNPair.of(userDN);
    List<String> dnList = Collections.singletonList(userDN);
    UUID queryId = UUID.randomUUID();
    MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
    queryParameters.putSingle(QueryParameters.QUERY_STRING, query);
    queryParameters.putSingle(QueryParameters.QUERY_NAME, newQueryName);
    queryParameters.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(beginDate));
    queryParameters.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(endDate));
    queryParameters.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expirationDate));
    queryParameters.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, queryAuthorizations);
    queryParameters.putSingle(QueryParameters.QUERY_PARAMS, parameters);
    queryParameters.putSingle(QueryParameters.QUERY_PAGESIZE, String.valueOf(pagesize));
    queryParameters.putSingle(QueryParameters.QUERY_PAGETIMEOUT, String.valueOf(pageTimeout));
    queryParameters.putSingle(QueryParameters.QUERY_PERSISTENCE, persistenceMode.name());
    queryParameters.putSingle(QueryParameters.QUERY_TRACE, String.valueOf(trace));
    queryParameters.putSingle(ColumnVisibilitySecurityMarking.VISIBILITY_MARKING, queryVisibility);
    ColumnVisibilitySecurityMarking marking = new ColumnVisibilitySecurityMarking();
    marking.validate(queryParameters);
    QueryParameters qp = new QueryParametersImpl();
    qp.validate(queryParameters);
    MultivaluedMap<String, String> op = new MultivaluedMapImpl<>();
    op.putAll(qp.getUnknownParameters(queryParameters));
    op.putSingle(PrivateAuditConstants.LOGIC_CLASS, queryLogic1.getClass().getSimpleName());
    op.putSingle(PrivateAuditConstants.COLUMN_VISIBILITY, queryVisibility);
    op.putSingle(PrivateAuditConstants.USER_DN, userDN);
    // Set expectations of the create logic
    expect(this.context.getCallerPrincipal()).andReturn(this.principal).times(2);
    expect(this.principal.getName()).andReturn(userName).times(2);
    expect(this.principal.getShortName()).andReturn(userSid).times(2);
    expect(this.principal.getUserDN()).andReturn(userDNpair);
    expect(this.principal.getDNs()).andReturn(new String[] { userDN });
    expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0)).anyTimes();
    queryLogic1.validate(queryParameters);
    expect(this.queryLogic1.getAuditType(null)).andReturn(AuditType.NONE);
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList(queryAuthorizations))).times(2);
    expect(this.cache.get(queryId.toString())).andReturn(this.runningQuery);
    expect(this.runningQuery.getSettings()).andReturn(this.query).times(2);
    expect(this.query.getOwner()).andReturn(userSid);
    QueryImpl newQuery1 = new QueryImpl();
    newQuery1.setId(UUID.randomUUID());
    newQuery1.setQuery(query);
    newQuery1.setQueryName(newQueryName);
    newQuery1.setBeginDate(beginDate);
    newQuery1.setEndDate(endDate);
    newQuery1.setExpirationDate(expirationDate);
    newQuery1.setDnList(Collections.singletonList(userDN));
    expect(this.query.duplicate(newQueryName)).andReturn(newQuery1);
    expect(context.getCallerPrincipal()).andReturn(principal).times(2);
    expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn((QueryLogic) this.queryLogic1).times(2);
    expect(this.queryLogic1.getLogicName()).andReturn(queryLogicName).times(2);
    expect(this.queryLogic1.getMaxPageSize()).andReturn(100).times(2);
    QueryImpl newQuery2 = new TestQuery(newQuery1);
    expect(persister.create(eq(userDNpair.subjectDN()), eq(dnList), eq(marking), eq(queryLogicName), eq(qp), eq(op))).andReturn(newQuery2);
    expect(this.queryLogic1.getAuditType(newQuery2)).andReturn(AuditType.NONE);
    expect(this.queryLogic1.getConnectionPriority()).andReturn(Priority.NORMAL);
    expect(this.queryLogic1.getConnPoolName()).andReturn("connPool1");
    expect(this.connectionFactory.getTrackingMap(isA(StackTraceElement[].class))).andReturn(null);
    expect(this.connectionFactory.getConnection("connPool1", Priority.NORMAL, null)).andReturn(this.connector);
    expect(this.qlCache.add(newQuery1.getId().toString(), userSid, this.queryLogic1, this.connector)).andReturn(true);
    expect(this.queryLogic1.getCollectQueryMetrics()).andReturn(false);
    expect(this.queryLogic1.initialize(eq(this.connector), isA(Query.class), isA(Set.class))).andReturn(this.genericConfiguration);
    this.queryLogic1.setupQuery(this.genericConfiguration);
    expect(this.queryLogic1.getTransformIterator(eq(newQuery2))).andReturn(this.transformIterator);
    expect(this.genericConfiguration.getQueryString()).andReturn(query).once();
    this.cache.put(eq(newQuery2.getId().toString()), isA(RunningQuery.class));
    expect(this.qlCache.poll(newQuery1.getId().toString())).andReturn(null);
    // Run the test
    PowerMock.replayAll();
    QueryExecutorBean subject = new QueryExecutorBean();
    setInternalState(subject, EJBContext.class, context);
    setInternalState(subject, AccumuloConnectionFactory.class, connectionFactory);
    setInternalState(subject, ResponseObjectFactory.class, responseObjectFactory);
    setInternalState(subject, CreatedQueryLogicCacheBean.class, qlCache);
    setInternalState(subject, QueryCache.class, cache);
    setInternalState(subject, ClosedQueryCache.class, closedCache);
    setInternalState(subject, Persister.class, persister);
    setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
    setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(subject, QueryMetricsBean.class, metrics);
    setInternalState(subject, Multimap.class, traceInfos);
    setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
    setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    GenericResponse<String> result1 = subject.duplicateQuery(queryId.toString(), newQueryName, queryLogicName, query, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace);
    PowerMock.verifyAll();
    // Verify results
    assertNotNull("Expected a non-null response", result1);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Query(datawave.webservice.query.Query) ArrayList(java.util.ArrayList) QueryImpl(datawave.webservice.query.QueryImpl) QueryPersistence(datawave.webservice.query.QueryPersistence) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) SubjectIssuerDNPair(datawave.security.authorization.SubjectIssuerDNPair) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParameters(datawave.webservice.query.QueryParameters) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) QueryLogic(datawave.webservice.query.logic.QueryLogic) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Date(java.util.Date) ColumnVisibilitySecurityMarking(datawave.marking.ColumnVisibilitySecurityMarking) Collection(java.util.Collection) PowerMockIgnore(org.powermock.core.classloader.annotations.PowerMockIgnore) Ignore(org.junit.Ignore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ColumnVisibilitySecurityMarking (datawave.marking.ColumnVisibilitySecurityMarking)16 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)16 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)16 QueryPersistence (datawave.webservice.query.QueryPersistence)15 Date (java.util.Date)15 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)15 Test (org.junit.Test)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 QueryParameters (datawave.webservice.query.QueryParameters)14 ArrayList (java.util.ArrayList)13 SubjectIssuerDNPair (datawave.security.authorization.SubjectIssuerDNPair)11 UUID (java.util.UUID)9 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)8 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)7 QueryException (datawave.webservice.query.exception.QueryException)7 Collection (java.util.Collection)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 TreeSet (java.util.TreeSet)6