/** * '$RCSfile$' * Copyright: 2004 Regents of the University of California and the * National Center for Ecological Analysis and Synthesis * Purpose: To test the Access Controls in metacat by JUnit * * '$Author$' * '$Date$' * '$Revision$' * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package edu.ucsb.nceas.metacattest; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.SimpleTimeZone; import java.util.TimeZone; import edu.ucsb.nceas.MCTestCase; import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; import edu.ucsb.nceas.metacat.client.Metacat; import edu.ucsb.nceas.metacat.client.MetacatAuthException; import edu.ucsb.nceas.metacat.client.MetacatException; import edu.ucsb.nceas.metacat.client.MetacatFactory; import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; import edu.ucsb.nceas.metacat.properties.PropertyService; import edu.ucsb.nceas.utilities.IOUtil; import edu.ucsb.nceas.utilities.PropertyNotFoundException; import junit.framework.Test; import junit.framework.TestSuite; /** * A JUnit test for testing Access Control for Inline data in Metacat */ public class InlineDataAccessTest extends MCTestCase { private static String username; private static String password; private static String anotheruser; private static String anotherpassword; static { try { username = PropertyService.getProperty("test.mcUser"); password = PropertyService.getProperty("test.mcPassword"); anotheruser = PropertyService.getProperty("test.mcAnotherUser"); anotherpassword = PropertyService.getProperty("test.mcAnotherPassword"); } catch (PropertyNotFoundException pnfe) { System.err.println("Could not get property in static block: " + pnfe.getMessage()); } } private String prefix = "test"; private String newdocid = null; private String testdocument = ""; private Metacat m; private String testEml_200_Header = ""; private String testEml_201_Header = ""; private String testEml_210_Header = ""; private String testEmlCreatorBlock = " " + " " + " Smith " + " " + " "; private String testEmlContactBlock = " " + " " + " Jackson " + " " + " "; private String testEmlInlineBlock1 = " " + " " + " Operator " + " PSI " + " " + " "; private String testEmlInlineBlock2 = " " + " LCQ " + " " + " " + " "; /** * This function returns an access block based on the params passed */ protected String getAccessBlock(String principal, boolean grantAccess, boolean read, boolean write, boolean changePermission, boolean all) { String accessBlock = ""; if (grantAccess) { accessBlock += ""; } else { accessBlock += ""; } accessBlock = accessBlock + "" + principal + ""; if (all) { accessBlock += "all"; } else { if (read) { accessBlock += "read"; } if (write) { accessBlock += "write"; } if (changePermission) { accessBlock += "changePermission"; } } if (grantAccess) { accessBlock += ""; } else { accessBlock += ""; } accessBlock += ""; return accessBlock; } /** * This function returns a valid eml 2.0 1 document */ private String get201TestEmlDoc(String title, String inlineData1, String inlineData2, String onlineUrl1, String onlineUrl2, String docAccessBlock, String inlineAccessBlock1, String inlineAccessBlock2, String onlineAccessBlock1, String onlineAccessBlock2) { String testDocument = testEml_201_Header; testDocument += "" + title + "" + testEmlCreatorBlock; // The inline/online level access block sits at the same level as the // inline element. if (inlineData1 != null) { testDocument += "" + "" + inlineData1 + ""; } if (inlineData2 != null) { testDocument = testDocument + "" + "" + inlineData2 + ""; } if (onlineUrl1 != null) { testDocument = testDocument + "" + "" + onlineUrl1 + ""; } if (onlineUrl2 != null) { testDocument = testDocument + "" + "" + onlineUrl2 + ""; } testDocument += testEmlContactBlock; // The document level access block sits inside the dataset element. if (docAccessBlock != null) { testDocument += docAccessBlock; } testDocument += ""; // The inline access blocks live in additionalMetadata elements at // the same level as the dataset. if (inlineAccessBlock1 != null) { testDocument += ""; testDocument += "inlineEntity1"; testDocument += inlineAccessBlock1; testDocument += ""; } if (inlineAccessBlock2 != null) { testDocument += ""; testDocument += "inlineEntity2"; testDocument += inlineAccessBlock2; testDocument += ""; } if (onlineAccessBlock1 != null) { testDocument += ""; testDocument += "InlineEntity1"; testDocument += onlineAccessBlock1; testDocument += ""; } if (onlineAccessBlock2 != null) { testDocument += ""; testDocument += "InlineEntity2"; testDocument += onlineAccessBlock2; testDocument += ""; } testDocument += ""; debug("get201TestEmlDoc returning following document: " + testDocument); return testDocument; } /** * This function returns a valid eml document */ private String get210TestEmlDoc(String title, String inlineData1, String inlineData2, String onlineUrl1, String onlineUrl2, String docAccessBlock, String inlineAccessBlock1, String inlineAccessBlock2, String onlineAccessBlock1, String onlineAccessBlock2) { String testDocument = testEml_210_Header; // the document level access block sits at the same level and // before the dataset element. if (docAccessBlock != null) { testDocument += docAccessBlock; } testDocument += "" + title + "" + testEmlCreatorBlock + testEmlContactBlock + "" + " Test Data" + " " + " 2.1.0 test physical" + " 1" + " ASCII" + " " + " " + " 1" + " column" + " " + " ," + " " + " " + " "; // The inline/online level access block sits at the same level as the // inline element. if (inlineData1 != null) { testDocument += "" + inlineData1 + ""; if (inlineAccessBlock1 != null) { testDocument += inlineAccessBlock1; } testDocument += ""; } if (inlineData2 != null) { testDocument += "" + inlineData2 + ""; if (inlineAccessBlock2 != null) { testDocument += inlineAccessBlock2; } testDocument += ""; } if (onlineUrl1 != null) { testDocument = testDocument + "" + onlineUrl1 + ""; if (onlineAccessBlock1 != null) { testDocument += onlineAccessBlock1; } testDocument += ""; } if (onlineUrl2 != null) { testDocument = testDocument + "" + onlineUrl2 + ""; if (onlineAccessBlock2 != null) { testDocument += onlineAccessBlock2; } testDocument += ""; } testDocument += " " + " " + " " + " rain" + " Surface Rainfall" + " The amount of rainfall on the sampling unit." + " " + " float" + " double" + " " + " " + " millimeter" + " 0.5" + " " + " real" + " " + " 0" + " " + " " + " " + " " + " " + " " + ""; debug("get210TestEmlDoc returning following document: " + testDocument); return testDocument; } /** * Constructor to build the test * * @param name * the name of the test method */ public InlineDataAccessTest(String name) { super(name); newdocid = generateDocid(); } /** * Establish a testing framework by initializing appropriate objects */ public void setUp() { try { System.err.println("Test Metacat: " + metacatUrl); m = MetacatFactory.createMetacatConnection(metacatUrl); } catch (MetacatInaccessibleException mie) { System.err.println("Metacat is: " + metacatUrl); fail("Metacat connection failed." + mie.getMessage()); } } /** * Release any objects after tests are complete */ public void tearDown() { } /** * Create a suite of tests to be run together */ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new InlineDataAccessTest("initialize")); suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_1")); suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_1")); suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_2")); suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_2")); suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_3")); suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_3")); suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_4")); suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_4")); suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_5")); suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_5")); suite.addTest(new InlineDataAccessTest("inlineData201CasesTest_6")); suite.addTest(new InlineDataAccessTest("inlineData210CasesTest_6")); return suite; } /** * Run an initial test that always passes to check that the test * harness is working. */ public void initialize() { assertTrue(1 == 1); } /** * For EML 2.0.1, checking the following cases: * when only Inline data is uploaded by a user and * -> he tries to read it - success * -> he tries to add same docid again - failure * -> he tries to update it - success * -> he removes it and adds it again - success * -> he tries to delete it - success * -> he tries to read it after deleteing - failure */ public void inlineData201CasesTest_1() { debug("\nRunning: inlineData201CasesTest_1()"); try { newdocid = generateDocid(); m.login(username, password); // insert a document testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1, null, null, null, null, null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); // insert same document again insertDocid(newdocid + ".1", testdocument, FAILURE, false); // update by changing inline data testdocument = get201TestEmlDoc("Testing update inline", testEmlInlineBlock2, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true); // update by removing inline data testdocument = get201TestEmlDoc("Testing update inline", null, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".3", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true); // update by introducing inline data testdocument = get201TestEmlDoc("Testing update inline", testEmlInlineBlock1, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".4", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true); // read inline data only readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // delete the inline data // sleep needed only in case of inline data - jing said that // somehow the thread writing data to xml_index takes too much time // when used with inline data. hence if delete is requested too soon // database gives an error of xml_index records left with FK to // xml_document record which is going to be deleted. Thread.sleep(10000); deleteDocid(newdocid + ".4", SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /** * For EML 2.1.0, checking the following cases: when only Inline data is * uploaded by a user and -> he tries to read it - success -> he tries to * add same docid again - failure -> he tries to update it - success -> he * removes it and adds it again - success -> he tries to delete it - success -> * he tries to read it after deleteing - failure */ public void inlineData210CasesTest_1() { debug("\nRunning: inlineData210CasesTest_1()"); try { newdocid = generateDocid(); m.login(username, password); // insert a document testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1, null, null, null, null, null, null, null, null); debug("testdocument: " + testdocument); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); // insert same document again insertDocid(newdocid + ".1", testdocument, FAILURE, false); // update by changing inline data testdocument = get210TestEmlDoc("Testing update inline", testEmlInlineBlock2, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, true); // update by removing inline data testdocument = get210TestEmlDoc("Testing update inline", null, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".3", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".3", testdocument, SUCCESS, true); // update by introducing inline data testdocument = get210TestEmlDoc("Testing update inline", testEmlInlineBlock1, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".4", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, true); // read inline data only readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // delete the inline data // sleep needed only in case of inline data - jing said that // somehow the thread writing data to xml_index takes too much time // when used with inline data. hence if delete is requested too soon // database gives an error of xml_index records left with FK to // xml_document record which is going to be deleted. Thread.sleep(10000); deleteDocid(newdocid + ".4", SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".4", testdocument, SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.0.1, checking the following cases: when only inline data is * uploaded by a user and another user -> tries to read it - failure -> * tries to read inline data only - failure -> tries to update - failure -> * tries to delete it - failure */ public void inlineData201CasesTest_2() { debug("\nRunning: inlineData201CasesTest_2()"); try { newdocid = generateDocid(); m.login(username, password); // insert a document testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1, null, null, null, null, null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); // login as another user m.logout(); m.login(anotheruser, anotherpassword); // try to read document or data only readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the document testdocument = get201TestEmlDoc("Testing insert", testEmlInlineBlock1, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.1.0, checking the following cases: when only inline data is * uploaded by a user and another user -> tries to read it - failure -> * tries to read inline data only - failure -> tries to update - failure -> * tries to delete it - failure */ public void inlineData210CasesTest_2() { debug("\nRunning: inlineData210CasesTest_2()"); try { newdocid = generateDocid(); m.login(username, password); // insert a document testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1, null, null, null, null, null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, true); // login as another user m.logout(); m.login(anotheruser, anotherpassword); // try to read document or data only readDocidWhichEqualsDoc(newdocid, testdocument, FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the document testdocument = get210TestEmlDoc("Testing insert", testEmlInlineBlock1, null, null, null, null, null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.0.1, checking the following cases: * when only inline data is uploaded by a user with the following different * access controls in another document 1.read 2.write 3.change permission * 4.all And another user tries to do the following: -> tries to read it -> * tries to update it -> tries to set permissions on it -> tries to delete it */ public void inlineData201CasesTest_3() { debug("\nRunning: inlineData201CasesTest_3()"); try { // ///////Case 1.///////////////////// // insert an inline document - read only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, true, false, false, false), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", SUCCESS, false); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, true, false, false, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 2.///////////////////// // insert an inline document - write only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, true, false, false), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, false, true, false, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".3", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".2", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".2", SUCCESS, false); m.logout(); // ///////Case 3.///////////////////// // insert an inline document - change permission only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, true, false), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, false, false, true, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); // ERRRRRRRRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to delete the document //deleteDocid(newdocid + ".2", FAILURE, true); //m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".2", SUCCESS, false); m.logout(); // ///////Case 4.///////////////////// // insert an inline document - change permission only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", SUCCESS, false); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, true, true, true, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".3", testdocument, SUCCESS, false); // try to delete the document // sleep needed only in case of inline data - jing said that // somehow the thread writing data to xml_index takes too much time // when used with inline data. hence if delete is requested too soon // database gives an error of xml_index records left with FK to // xml_document record which is going to be deleted. Thread.sleep(10000); deleteDocid(newdocid + ".3", SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.1.0, checking the following cases: * when only inline data is uploaded by a user with the following different * access controls in another document 1.read 2.write 3.change permission * 4.all And another user tries to do the following: -> tries to read it -> * tries to update it -> tries to set permissions on it -> tries to delete it */ public void inlineData210CasesTest_3() { debug("\nRunning: inlineData210CasesTest_3()"); try { // ///////Case 1.///////////////////// // insert an inline document - read only debug("Case 1:"); m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, true, false, false, false), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", SUCCESS, false); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, true, false, false, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 2.///////////////////// // insert an inline document - write only debug("Case 2:"); m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document debug("Inserting doc: " + newdocid + ".1, which allows document level" + " write access for " + anotheruser + " and expect SUCCESS"); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, true, false, false), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data debug("Try to read:" + newdocid + ".1 as user: " + anotheruser + " and expect FAILURE since write access does not imply read access"); readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data debug("Updating doc: " + newdocid + ".2, with new inline data." + " as: " + anotheruser + " and expect SUCCESS"); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, false, true, false, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".3", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".2", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".2", SUCCESS, false); m.logout(); // ///////Case 3.///////////////////// // insert an inline document - change permission only debug("Case 3:"); m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, true, false), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, false, false, true, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); // ERRRRRRRRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to delete the document //deleteDocid(newdocid + ".2", FAILURE, true); //m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".2", SUCCESS, false); m.logout(); // ///////Case 4.///////////////////// // insert an inline document - change permission only debug("Case 4:"); m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", SUCCESS, false); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, true, true, true, false), null, null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".3", testdocument, SUCCESS, false); // try to delete the document // sleep needed only in case of inline data - jing said that // somehow the thread writing data to xml_index takes too much time // when used with inline data. hence if delete is requested too soon // database gives an error of xml_index records left with FK to // xml_document record which is going to be deleted. Thread.sleep(10000); deleteDocid(newdocid + ".3", SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.0.1, checking the following cases: when only Inline data is * uploaded by a user with the following different access controls specified * in addiotnal metadata in another document 1.read 2.write 3.change permission * 4.all And another user tries to do the following: -> tries to read it -> * tries to update it -> tries to set permissions on it -> tries to delete it */ public void inlineData201CasesTest_4() { debug("\nRunning: inlineData201CasesTest_4()"); try { // ///////Case 1.///////////////////// // insert an inline document - read only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, true, false, false, false), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); // ERRRRRRRRRRRRRRR readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, true, false, false, false), null, null, null); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); try { Thread.sleep(5000); } catch(Exception e) { } deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 2.///////////////////// // insert an inline document - write only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, true, false, false), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, false, true, false, false), null, null, null); // ERRRRRRRRRRRRRRRRRRRRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); try { Thread.sleep(5000); } catch(Exception e) { } deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 3.///////////////////// // insert an inline document - change permission only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, true, false), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, false, false, true, false), null, null, null); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); // ERRRRRRRRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); try { Thread.sleep(5000); } catch(Exception e) { } deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 4.///////////////////// // insert an inline document - change permission only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); // ERRRRRRRRRRRRRRR // readInlineDataWhichEqualsDoc(newdocid + ".1.1", // testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); // ERRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, true, true, true, false), null, null, null); // ERRRRRRRRRR // updateDocid(newdocid + ".3", testdocument, SUCCESS, false); // try to delete the document deleteDocid(newdocid + ".3", FAILURE, true); m.logout(); // delete the document m.login(username, password); try { Thread.sleep(5000); } catch(Exception e) { } deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.1.0, checking the following cases: when only Inline data is * uploaded by a user with the following different access controls specified * in addiotnal metadata in another document 1.read 2.write 3.change permission * 4.all And another user tries to do the following: -> tries to read it -> * tries to update it -> tries to set permissions on it -> tries to delete it */ public void inlineData210CasesTest_4() { debug("\nRunning: inlineData210CasesTest_4()"); try { // ///////Case 1.///////////////////// // insert an inline document - read only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, true, false, false, false), null, null, null); debug("testdocument: " + testdocument); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); // ERRRRRRRRRRRRRRR readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, true, false, false, false), null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 2.///////////////////// // insert an inline document - write only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, true, false, false), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, false, true, false, false), null, null, null); // ERRRRRRRRRRRRRRRRRRRRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 3.///////////////////// // insert an inline document - change permission only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, true, false), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, false, false, true, false), null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, FAILURE, true); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); // ERRRRRRRRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to delete the document deleteDocid(newdocid + ".1", FAILURE, true); m.logout(); // delete the document m.login(username, password); try { Thread.sleep(5000); } catch(Exception e) { } deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); // ///////Case 4.///////////////////// // insert an inline document - change permission only m.login(username, password); newdocid = generateDocid(); // insert a document which gives read access to the inline document testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // login as another user m.login(anotheruser, anotherpassword); // try to read the document and the inline data readDocid(newdocid + ".1", FAILURE, true); // ERRRRRRRRRRRRRRR // readInlineDataWhichEqualsDoc(newdocid + ".1.1", // testEmlInlineBlock1, SUCCESS, false); // try to update the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, null, null, null, null, getAccessBlock( anotheruser, true, false, false, false, true), null, null, null); // ERRRRRR // updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try to set the permissions for the inline data testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, null, getAccessBlock( anotheruser, true, true, true, true, false), null, null, null); // ERRRRRRRRRR // updateDocid(newdocid + ".3", testdocument, SUCCESS, false); // try to delete the document deleteDocid(newdocid + ".3", FAILURE, true); m.logout(); // delete the document m.login(username, password); try { Thread.sleep(5000); } catch(Exception e) { } deleteDocid(newdocid + ".1", SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.0.1, checking the following cases: -> when no inline data is * specified in the document but rules are specified in additional metadata -> * when a user has RW permission for inline data, can he delete it -> when * inline data with document refering to it is uploaded with read access for * metadata and no access for data */ public void inlineData201CasesTest_5() { debug("\nRunning: inlineData201CasesTest_5()"); try { m.login(username, password); /////////Case 1 debug("Case 1:"); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", null, null, null, null, null, getAccessBlock(anotheruser, true, true, false, false, false), null, null, null); newdocid = generateDocid(); // try to insert the wrong document. This document is wrong because // it has an access block but no distribution. insertDocid(newdocid + ".1", testdocument, FAILURE, false); m.logout(); /////////Case 2 debug("Case 2:"); m.login(username, password); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, true, true, false, false), null, null, null, null); newdocid = generateDocid(); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); m.login(anotheruser, anotherpassword); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", null, null, null, null, getAccessBlock(anotheruser, true, true, true, false, false), null, null, null, null); /// ERRRRRRRRRRRR Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); /////////Case 3 debug("Case 3:"); // insert a document m.login(username, password); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null, null); newdocid = generateDocid(); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // try to read the Inline data m.login(anotheruser, anotherpassword); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", "", null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null, null); readDocidWhichEqualsDoc(newdocid + ".1", testdocument, SUCCESS, false); // try to update the rules for inline data // / ERRRRRRRRRRRR it lets you do that testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), getAccessBlock(anotheruser, true, false, false, false, true), null, null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * For EML 2.1.0, checking the following cases: -> when no inline data is * specified in the document but rules are specified in additional metadata -> * when a user has RW permission for inline data, can he delete it -> when * inline data with document refering to it is uploaded with read access for * metadata and no access for data */ public void inlineData210CasesTest_5() { debug("\nRunning: inlineData210CasesTest_5()"); try { /////////Case 2 debug("Case 2:"); m.login(username, password); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, true, true, false, false), null, null, null, null); newdocid = generateDocid(); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); m.login(anotheruser, anotherpassword); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", null, null, null, null, getAccessBlock(anotheruser, true, true, true, false, false), null, null, null, null); /// ERRRRRRRRRRRR Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); /////////Case 3 debug("Case 3:"); // insert a document m.login(username, password); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null, null); newdocid = generateDocid(); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // try to read the Inline data m.login(anotheruser, anotherpassword); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", "", null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null, null); readDocidWhichEqualsDoc(newdocid + ".1", testdocument, SUCCESS, false); // try to update the rules for inline data // shouldn't succeed testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, null, null, null, getAccessBlock(anotheruser, true, false, false, false, true), getAccessBlock(anotheruser, true, false, false, false, true), null, null, null); debug("inserting this: " + testdocument); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); readDocidWhichEqualsDoc(newdocid + ".2", testdocument, SUCCESS, false); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * for EML 2.0.1, checking the following cases: -> when inline data is * inserted and updated, do access rules apply to the old document */ public void inlineData201CasesTest_6() { debug("\nRunning: inlineData201CasesTest_6()"); try { // insert the document m.login(username, password); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, testEmlInlineBlock2, null, null, getAccessBlock( anotheruser, true, true, true, false, false), getAccessBlock( anotheruser, false, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null); newdocid = generateDocid(); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // update the document m.login(anotheruser, anotherpassword); testdocument = get201TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, testEmlInlineBlock1, null, null, getAccessBlock( anotheruser, true, true, true, false, false), getAccessBlock( anotheruser, false, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try reading the inline document readInlineDataWhichEqualsDoc(newdocid + ".2.1", testEmlInlineBlock1, FAILURE, true); System.out.print("Trying to read " + newdocid + ".1.1"); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /*************************************************************************** * for EML 2.1.0, checking the following cases: -> when inline data is * inserted and updated, do access rules apply to the old document */ public void inlineData210CasesTest_6() { debug("\nRunning: inlineData210CasesTest_6()"); try { // insert the document m.login(username, password); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing insert", testEmlInlineBlock1, testEmlInlineBlock2, null, null, getAccessBlock( anotheruser, true, true, true, false, false), getAccessBlock( anotheruser, false, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null); newdocid = generateDocid(); insertDocid(newdocid + ".1", testdocument, SUCCESS, false); m.logout(); // update the document m.login(anotheruser, anotherpassword); testdocument = get210TestEmlDoc("InlineDataAccessTest: Doing update", testEmlInlineBlock2, testEmlInlineBlock1, null, null, getAccessBlock( anotheruser, true, true, true, false, false), getAccessBlock( anotheruser, false, false, false, false, true), getAccessBlock(anotheruser, false, false, false, false, true), null, null); Thread.sleep(2000); updateDocid(newdocid + ".2", testdocument, SUCCESS, false); // try reading the inline document readInlineDataWhichEqualsDoc(newdocid + ".2.1", testEmlInlineBlock1, FAILURE, true); System.out.print("Trying to read " + newdocid + ".1.1"); readInlineDataWhichEqualsDoc(newdocid + ".1.1", testEmlInlineBlock1, FAILURE, true); m.logout(); } catch (MetacatAuthException mae) { fail("Authorization failed:\n" + mae.getMessage()); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /** * Insert a document into metacat. The expected result is passed as result */ private String insertDocid(String docid, String docText, boolean result, boolean expectKarmaException) { String response = null; try { response = m.insert(docid, new StringReader(testdocument), null); if (result) { assertTrue( (response.indexOf("") != -1)); assertTrue(response.indexOf(docid) != -1); } else { assertTrue( (response.indexOf("") == -1)); } System.err.println(response); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (InsufficientKarmaException ike) { if (!expectKarmaException) { fail("Insufficient karma:\n" + ike.getMessage()); } } catch (MetacatException me) { if (result) { fail("Metacat Error:\n" + me.getMessage()); } else { System.err.println("Metacat Error: " + me.getMessage()); } } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } return response; } /** * Insert a document into metacat. The expected result is passed as result */ // private String uploadDocid(String docid, String filePath, boolean result, // boolean expectedKarmaException) { // String response = null; // try { // response = m.upload(docid, new File(filePath)); // if (result) { // assertTrue( (response.indexOf("") != -1)); // assertTrue(response.indexOf(docid) != -1); // } // else { // assertTrue( (response.indexOf("") == -1)); // } // System.err.println("respose from metacat: " + response); // } // catch (MetacatInaccessibleException mie) { // fail("Metacat Inaccessible:\n" + mie.getMessage()); // } // catch (InsufficientKarmaException ike) { // if (!expectedKarmaException) { // fail("Insufficient karma:\n" + ike.getMessage()); // } // } // catch (MetacatException me) { // if (result) { // fail("Metacat Error:\n" + me.getMessage()); // } // else { // System.err.println("Metacat Error: " + me.getMessage()); // } // } // catch (Exception e) { // fail("General exception:\n" + e.getMessage()); // } // return response; // } /** * Update a document in metacat. The expected result is passed as result */ private String updateDocid(String docid, String docText, boolean result, boolean expectedKarmaFailure) { String response = null; try { response = m.update(docid, new StringReader(testdocument), null); if (result) { assertTrue( (response.indexOf("") != -1)); assertTrue(response.indexOf(docid) != -1); } else { assertTrue( (response.indexOf("") == -1)); } System.err.println(response); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (InsufficientKarmaException ike) { if (!expectedKarmaFailure) { fail("Insufficient karma:\n" + ike.getMessage()); } } catch (MetacatException me) { if (! (expectedKarmaFailure && (me.getMessage().indexOf( "User tried to update an access module when they don't have \"ALL\" permission") != -1))) { fail("Metacat Error:\n" + me.getMessage()); } } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } return response; } /** * Delete a document into metacat. The expected result is passed as result */ private void deleteDocid(String docid, boolean result, boolean expectedKarmaFailure) { try { String response = m.delete(docid); if (result) { assertTrue(response.indexOf("") != -1); } else { assertTrue(response.indexOf("") == -1); } System.err.println(response); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (InsufficientKarmaException ike) { if (!expectedKarmaFailure) { fail("Insufficient karma:\n" + ike.getMessage()); } } catch (MetacatException me) { if (result) { fail("Metacat Error:\n" + me.getMessage()); } else { System.err.println("Metacat Error:\n" + me.getMessage()); } } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /** * Read inline data from metacat. The expected result is passed as result */ private void readInlineDataWhichEqualsDoc(String docid, String testDoc, boolean result, boolean expextedKarmaFailure) { try { debug("before read, docid: " + docid); Reader r = new InputStreamReader(m.readInlineData(docid)); debug("after read, docid: " + docid); String doc = IOUtil.getAsString(r, true); debug("after get as string, doc: " + doc); if (result) { if (!testDoc.equals(doc)) { System.out.println("doc :" + doc); System.out.println("testDoc:" + testDoc); } assertTrue(testDoc.equals(doc)); } else { System.out.println("doc :" + doc); System.out.println("testDoc:" + testDoc); assertTrue(doc.indexOf("") != -1); } } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (InsufficientKarmaException ike) { if (!expextedKarmaFailure) { fail("Insufficient karma:\n" + ike.getMessage()); } } catch (MetacatException me) { if (result) { fail("Metacat Error:\n" + me.getMessage()); } else { System.err.println("Metacat Error:\n" + me.getMessage()); } } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /** * Read a document from metacat. The expected result is passed as result */ private void readDocid(String docid, boolean result, boolean expextedKarmaFailure) { try { Reader r = new InputStreamReader(m.read(docid)); String response = IOUtil.getAsString(r, true); if (!result) { assertTrue(response.indexOf("") == -1); } System.err.println(response); } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (InsufficientKarmaException ike) { if (!expextedKarmaFailure) { fail("Insufficient karma:\n" + ike.getMessage()); } } catch (MetacatException me) { if (result) { fail("Metacat Error:\n" + me.getMessage()); } else { System.err.println("Metacat Error:\n" + me.getMessage()); } } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /** * Read a document from metacat and check if it is equal to a given string. * The expected result is passed as result */ private void readDocidWhichEqualsDoc(String docid, String testDoc, boolean result, boolean expextedKarmaFailure) { try { Reader r = new InputStreamReader(m.read(docid)); String doc = IOUtil.getAsString(r, true); if (result) { if (!testDoc.equals(doc)) { System.out.println("doc ***********************"); System.out.println(doc); System.out.println("end doc ***********************"); System.out.println("testDoc ***********************"); System.out.println(testDoc); System.out.println("end testDoc ***********************"); } assertTrue(testDoc.equals(doc)); } else { assertTrue(doc.indexOf("") != -1); } } catch (MetacatInaccessibleException mie) { fail("Metacat Inaccessible:\n" + mie.getMessage()); } catch (InsufficientKarmaException ike) { if (result) { fail("Metacat Error:\n" + ike.getMessage()); } else { System.out.println("Metacat Error:\n" + ike.getMessage()); } } catch (MetacatException me) { if (result) { fail("Metacat Error:\n" + me.getMessage()); } else { System.out.println("Metacat Error:\n" + me.getMessage()); } } catch (Exception e) { fail("General exception:\n" + e.getMessage()); } } /** * Create a hopefully unique docid for testing insert and update. Does * not include the 'revision' part of the id. * * @return a String docid based on the current date and time */ private String generateDocid() { StringBuffer docid = new StringBuffer(prefix); docid.append("."); try { Thread.sleep(1100); } catch (InterruptedException ie) { System.out.println("Warning: generateDocid() could not sleep 1100 ms"); } // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs( -8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone( -8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime); docid.append(calendar.get(Calendar.YEAR)); docid.append(calendar.get(Calendar.DAY_OF_YEAR)); docid.append(calendar.get(Calendar.HOUR_OF_DAY)); docid.append(calendar.get(Calendar.MINUTE)); docid.append(calendar.get(Calendar.SECOND)); return docid.toString(); } }