Project

General

Profile

« Previous | Next » 

Revision 7675

Added by Jing Tao over 11 years ago

Use the MNode to query the server when we use certificates to set up the session.

View differences:

test/edu/ucsb/nceas/metacat/dataone/SolrQueryAccessFilterTest.java
19 19
import junit.framework.TestSuite;
20 20

  
21 21
import org.apache.http.HttpResponse;
22
import org.dataone.client.D1Client;
22 23
import org.dataone.client.D1RestClient;
24
import org.dataone.client.MNode;
23 25
import org.dataone.client.ObjectFormatCache;
24 26
import org.dataone.client.RestClient;
25 27
import org.dataone.client.auth.CertificateManager;
......
56 58
    private static final String GROUP2 = "CN=dataone-coredev,DC=cilogon,DC=org";
57 59
    private static final String USERWITHCERT = "CN=Jing Tao,OU=NCEAS,O=UCSB,ST=California,C=US";
58 60
    private static final String EMLFILE = "test/restfiles/knb-lter-gce.109.6.xml";
59
    private static final String INTRUSTCERTFILE = "test/test-credentials/ecp.pem";
61
    private static final String INTRUSTCERTFILE = "test/test-credentials/test-user.pem";
60 62
    private static final String IDXPATH = "//response/result/doc/str[@name='id']/text()";
61 63
    
62 64
    /**
......
66 68
    public static Test suite() {
67 69
      
68 70
      TestSuite suite = new TestSuite();
69
      //suite.addTest(new SolrQueryAccessFilterTest("testPublicReadable"));
70
      //suite.addTest(new SolrQueryAccessFilterTest("testOnlyUserReadable"));
71
      //suite.addTest(new SolrQueryAccessFilterTest("testGroupReadable"));
72
      //suite.addTest(new SolrQueryAccessFilterTest("testOnlyRightHolderReadable"));
71
      suite.addTest(new SolrQueryAccessFilterTest("testPublicReadable"));
72
      suite.addTest(new SolrQueryAccessFilterTest("testOnlyUserReadable"));
73
      suite.addTest(new SolrQueryAccessFilterTest("testGroupReadable"));
74
      suite.addTest(new SolrQueryAccessFilterTest("testOnlyRightHolderReadable"));
73 75
      suite.addTest(new SolrQueryAccessFilterTest("testDistrustCertificate"));
74 76
      
75 77
      return suite;
......
212 214
        Thread.sleep(10000);
213 215
        
214 216
        //use faking session, the user can query the document
215
        //Session querySession = getSession(USERWITHCERT, null);
216
        //String resultId = query(querySession, id);
217
        //assertTrue("In the testGroupReadable method, the query result id should be "+id.getValue(), id.getValue().equals(resultId));
217
        Session querySession = getSession(USERWITHCERT, null);
218
        String resultId = query(querySession, id);
219
        assertTrue("In the testDistrustCertificate method, the query result id should be "+id.getValue(), id.getValue().equals(resultId));
218 220
        
219 221
        //Use the libclient without the session, the user shouldn't query the document since its certificate is distrusted and it will be considered as the public.
220 222
        CertificateManager.getInstance().setCertificateLocation(INTRUSTCERTFILE);
221
        //InputStream input = MNodeService.getInstance(request).query(SOLR, generateQuery(id.getValue()));
222
        D1RestClient client = new D1RestClient();
223
        String url = "https://chico1.dyndns.org/knb/d1/mn/v1/query/solr/"+generateQuery(id.getValue());
224
        System.out.println("url is \n"+url);
225
        InputStream response = client.doGetRequest(url);
226
        String resultId = extractId(response);
227
        System.out.println("The id is "+resultId);
228
        
223
        CertificateManager.getInstance().loadCertificate();
224
        org.dataone.service.types.v1.Node node = MNodeService.getInstance(request).getCapabilities();
225
        String baseURL = node.getBaseURL();
226
        System.out.println("================The base url is "+baseURL);
227
        MNode mnNode = D1Client.getMN(baseURL);
228
        InputStream input = mnNode.query(SOLR, generateQuery(id.getValue()));
229
        String resultId2 = extractId(input);
230
        assertTrue("In the testDistrustCertificate method, the query result id should be null", resultId2==null);
229 231
        archive(session, id);
230 232
        
231 233
    }
......
358 360
        return query;
359 361
    }
360 362
    
361
    /*
362
     * Generate a solr query url for the RestClient
363
     */
364
    private String generateQueryURL(String id) {
365
        String url = "";
366
        return url;
367
    }
363
  
368 364
}

Also available in: Unified diff