Revision 3868
Added by Jing Tao over 16 years ago
test/edu/ucsb/nceas/metacattest/AccessControlTest.java | ||
---|---|---|
42 | 42 |
import edu.ucsb.nceas.metacat.client.MetacatFactory; |
43 | 43 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException; |
44 | 44 |
import edu.ucsb.nceas.utilities.IOUtil; |
45 |
import edu.ucsb.nceas.utilities.Options; |
|
45 | 46 |
import junit.framework.Test; |
46 | 47 |
import junit.framework.TestCase; |
47 | 48 |
import junit.framework.TestSuite; |
... | ... | |
50 | 51 |
/** |
51 | 52 |
* A JUnit test for testing Access Control in Metacat |
52 | 53 |
*/ |
53 |
public class AccessControlTest |
|
54 |
extends TestCase { |
|
54 |
public class AccessControlTest extends TestCase { |
|
55 |
/* Initialize Options*/ |
|
56 |
static |
|
57 |
{ |
|
58 |
try |
|
59 |
{ |
|
60 |
Options.initialize(new File("build/tests/metacat.properties")); |
|
61 |
MetaCatUtil.pathsForIndexing |
|
62 |
= MetaCatUtil.getOptionList(MetaCatUtil.getOption("indexPaths")); |
|
63 |
} |
|
64 |
catch(Exception e) |
|
65 |
{ |
|
66 |
System.err.println("Exception in initialize option in MetacatServletNetTest "+e.getMessage()); |
|
67 |
} |
|
68 |
} |
|
55 | 69 |
|
56 | 70 |
private String metacatUrl = MetaCatUtil.getOption("metacatUrl"); |
57 | 71 |
private String username = MetaCatUtil.getOption("mcuser"); |
... | ... | |
441 | 455 |
accessRules.add(accessRule2); |
442 | 456 |
String access = getAccessBlock(accessRules, ALLOWFIRST); |
443 | 457 |
System.out.println("the access part is "+access); |
444 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
458 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
445 | 459 |
null, null, null, |
446 | 460 |
null, access , |
447 | 461 |
null, null, null, null); |
... | ... | |
456 | 470 |
//fails to update this document |
457 | 471 |
updateDocid(newdocid + ".2", testdocument, FAILURE, true); |
458 | 472 |
//fails to update access part |
459 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
473 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
460 | 474 |
null, null, null, |
461 | 475 |
null, getAccessBlock(anotheruser, true, |
462 | 476 |
true, false, false, false), |
... | ... | |
478 | 492 |
accessRules.add(accessRule2); |
479 | 493 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
480 | 494 |
System.out.println("the access part is "+access); |
481 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
495 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
482 | 496 |
null, null, null, |
483 | 497 |
null, access , |
484 | 498 |
null, null, null, null); |
... | ... | |
493 | 507 |
//fails to update this document |
494 | 508 |
updateDocid(newdocid + ".3", testdocument, FAILURE, true); |
495 | 509 |
//fails to update access part |
496 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
510 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
497 | 511 |
null, null, null, |
498 | 512 |
null, getAccessBlock(anotheruser, true, |
499 | 513 |
true, false, false, false), |
... | ... | |
515 | 529 |
accessRules.add(accessRule2); |
516 | 530 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
517 | 531 |
System.out.println("the access part is "+access); |
518 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
532 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
519 | 533 |
null, null, null, |
520 | 534 |
null, access , |
521 | 535 |
null, null, null, null); |
... | ... | |
530 | 544 |
//fails to update this document |
531 | 545 |
updateDocid(newdocid + ".4", testdocument, FAILURE, true); |
532 | 546 |
//fails to update access part |
533 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
547 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
534 | 548 |
null, null, null, |
535 | 549 |
null, getAccessBlock(anotheruser, true, |
536 | 550 |
true, false, false, false), |
... | ... | |
555 | 569 |
accessRules.add(accessRule2); |
556 | 570 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
557 | 571 |
System.out.println("the access part is "+access); |
558 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
572 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
559 | 573 |
null, null, null, |
560 | 574 |
null, access , |
561 | 575 |
null, null, null, null); |
... | ... | |
570 | 584 |
//fails to update this document |
571 | 585 |
updateDocid(newdocid + ".5", testdocument, FAILURE, true); |
572 | 586 |
//fails to update access part |
573 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
587 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
574 | 588 |
null, null, null, |
575 | 589 |
null, getAccessBlock(anotheruser, true, |
576 | 590 |
true, false, false, false), |
... | ... | |
592 | 606 |
accessRules.add(accessRule2); |
593 | 607 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
594 | 608 |
System.out.println("the access part is "+access); |
595 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
609 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
596 | 610 |
null, null, null, |
597 | 611 |
null, access , |
598 | 612 |
null, null, null, null); |
... | ... | |
607 | 621 |
//fails to update this document |
608 | 622 |
updateDocid(newdocid + ".6", testdocument, SUCCESS, false); |
609 | 623 |
//fails to update access part |
610 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
624 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
611 | 625 |
null, null, null, |
612 | 626 |
null, getAccessBlock(anotheruser, true, |
613 | 627 |
true, false, false, false), |
... | ... | |
632 | 646 |
accessRules.add(accessRule2); |
633 | 647 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
634 | 648 |
System.out.println("the access part is "+access); |
635 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
649 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
636 | 650 |
null, null, null, |
637 | 651 |
null, access , |
638 | 652 |
null, null, null, null); |
... | ... | |
647 | 661 |
//fails to update this document |
648 | 662 |
updateDocid(newdocid + ".8", testdocument, FAILURE, true); |
649 | 663 |
//fails to update access part |
650 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
664 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
651 | 665 |
null, null, null, |
652 | 666 |
null, getAccessBlock(anotheruser, true, |
653 | 667 |
true, false, false, false), |
... | ... | |
670 | 684 |
accessRules.add(accessRule2); |
671 | 685 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
672 | 686 |
System.out.println("the access part is "+access); |
673 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
687 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
674 | 688 |
null, null, null, |
675 | 689 |
null, access , |
676 | 690 |
null, null, null, null); |
... | ... | |
685 | 699 |
//fails to update this document |
686 | 700 |
updateDocid(newdocid + ".9", testdocument, FAILURE, true); |
687 | 701 |
//fails to update access part |
688 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
702 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
689 | 703 |
null, null, null, |
690 | 704 |
null, getAccessBlock(anotheruser, true, |
691 | 705 |
true, false, false, false), |
... | ... | |
708 | 722 |
accessRules.add(accessRule2); |
709 | 723 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
710 | 724 |
System.out.println("the access part is "+access); |
711 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
725 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
712 | 726 |
null, null, null, |
713 | 727 |
null, access , |
714 | 728 |
null, null, null, null); |
... | ... | |
723 | 737 |
//fails to update this document |
724 | 738 |
updateDocid(newdocid + ".10", testdocument, FAILURE, true); |
725 | 739 |
//fails to update access part |
726 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
740 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
727 | 741 |
null, null, null, |
728 | 742 |
null, getAccessBlock(anotheruser, true, |
729 | 743 |
true, false, false, false), |
... | ... | |
749 | 763 |
accessRules.add(accessRule2); |
750 | 764 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
751 | 765 |
System.out.println("the access part is "+access); |
752 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
766 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
753 | 767 |
null, null, null, |
754 | 768 |
null, access , |
755 | 769 |
null, null, null, null); |
... | ... | |
764 | 778 |
//fails to update this document |
765 | 779 |
updateDocid(newdocid + ".11", testdocument, FAILURE, true); |
766 | 780 |
//fails to update access part |
767 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
781 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
768 | 782 |
null, null, null, |
769 | 783 |
null, getAccessBlock(anotheruser, true, |
770 | 784 |
true, false, false, false), |
... | ... | |
788 | 802 |
accessRules.add(accessRule2); |
789 | 803 |
access = getAccessBlock(accessRules, ALLOWFIRST); |
790 | 804 |
System.out.println("the access part is "+access); |
791 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
805 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
792 | 806 |
null, null, null, |
793 | 807 |
null, access , |
794 | 808 |
null, null, null, null); |
... | ... | |
803 | 817 |
//succeed to update this document |
804 | 818 |
updateDocid(newdocid + ".12", testdocument, SUCCESS, false); |
805 | 819 |
//fails to update access part |
806 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
820 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
807 | 821 |
null, null, null, |
808 | 822 |
null, getAccessBlock(anotheruser, true, |
809 | 823 |
true, false, false, false), |
... | ... | |
904 | 918 |
accessRules.add(accessRule2); |
905 | 919 |
String access = getAccessBlock(accessRules, DENYFIRST); |
906 | 920 |
System.out.println("the access part is "+access); |
907 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
921 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
908 | 922 |
null, null, null, |
909 | 923 |
null, access , |
910 | 924 |
null, null, null, null); |
... | ... | |
919 | 933 |
//fails to update this document |
920 | 934 |
updateDocid(newdocid + ".2", testdocument, FAILURE, true); |
921 | 935 |
//fails to update access part |
922 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
936 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
923 | 937 |
null, null, null, |
924 | 938 |
null, getAccessBlock(anotheruser, true, |
925 | 939 |
true, false, false, false), |
... | ... | |
941 | 955 |
accessRules.add(accessRule2); |
942 | 956 |
access = getAccessBlock(accessRules, DENYFIRST); |
943 | 957 |
System.out.println("the access part is "+access); |
944 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
958 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
945 | 959 |
null, null, null, |
946 | 960 |
null, access , |
947 | 961 |
null, null, null, null); |
... | ... | |
956 | 970 |
//succeeds to update this document |
957 | 971 |
updateDocid(newdocid + ".3", testdocument, SUCCESS, false); |
958 | 972 |
//fails to update access part |
959 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
973 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
960 | 974 |
null, null, null, |
961 | 975 |
null, getAccessBlock(anotheruser, true, |
962 | 976 |
true, false, false, false), |
... | ... | |
978 | 992 |
accessRules.add(accessRule2); |
979 | 993 |
access = getAccessBlock(accessRules, DENYFIRST); |
980 | 994 |
System.out.println("the access part is "+access); |
981 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
995 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
982 | 996 |
null, null, null, |
983 | 997 |
null, access , |
984 | 998 |
null, null, null, null); |
... | ... | |
993 | 1007 |
//succeeds to update this document |
994 | 1008 |
updateDocid(newdocid + ".5", testdocument, SUCCESS, false); |
995 | 1009 |
//succeed to update access part |
996 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1010 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
997 | 1011 |
null, null, null, |
998 | 1012 |
null, getAccessBlock(anotheruser, true, true, true, true, true), |
999 | 1013 |
null, null, null, null); |
... | ... | |
1017 | 1031 |
accessRules.add(accessRule2); |
1018 | 1032 |
access = getAccessBlock(accessRules, DENYFIRST); |
1019 | 1033 |
System.out.println("the access part is "+access); |
1020 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1034 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1021 | 1035 |
null, null, null, |
1022 | 1036 |
null, access , |
1023 | 1037 |
null, null, null, null); |
... | ... | |
1032 | 1046 |
//succeeds to update this document |
1033 | 1047 |
updateDocid(newdocid + ".2", testdocument, SUCCESS, false); |
1034 | 1048 |
//fails to update access part |
1035 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1049 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1036 | 1050 |
null, null, null, |
1037 | 1051 |
null, getAccessBlock(anotheruser, true, |
1038 | 1052 |
true, false, false, false), |
... | ... | |
1054 | 1068 |
accessRules.add(accessRule2); |
1055 | 1069 |
access = getAccessBlock(accessRules, DENYFIRST); |
1056 | 1070 |
System.out.println("the access part is "+access); |
1057 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1071 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1058 | 1072 |
null, null, null, |
1059 | 1073 |
null, access , |
1060 | 1074 |
null, null, null, null); |
... | ... | |
1069 | 1083 |
//succeed to update this document |
1070 | 1084 |
updateDocid(newdocid + ".11", testdocument, SUCCESS, false); |
1071 | 1085 |
//fails to update access part |
1072 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1086 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1073 | 1087 |
null, null, null, |
1074 | 1088 |
null, getAccessBlock(anotheruser, true, |
1075 | 1089 |
true, false, false, false), |
... | ... | |
1094 | 1108 |
accessRules.add(accessRule2); |
1095 | 1109 |
access = getAccessBlock(accessRules, DENYFIRST); |
1096 | 1110 |
System.out.println("the access part is "+access); |
1097 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1111 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1098 | 1112 |
null, null, null, |
1099 | 1113 |
null, access , |
1100 | 1114 |
null, null, null, null); |
... | ... | |
1109 | 1123 |
//fails to update this document |
1110 | 1124 |
updateDocid(newdocid + ".14", testdocument, FAILURE, true); |
1111 | 1125 |
//fails to update access part |
1112 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1126 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1113 | 1127 |
null, null, null, |
1114 | 1128 |
null, getAccessBlock(anotheruser, true, |
1115 | 1129 |
true, false, false, false), |
... | ... | |
1132 | 1146 |
accessRules.add(accessRule2); |
1133 | 1147 |
access = getAccessBlock(accessRules, DENYFIRST); |
1134 | 1148 |
System.out.println("the access part is "+access); |
1135 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1149 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1136 | 1150 |
null, null, null, |
1137 | 1151 |
null, access , |
1138 | 1152 |
null, null, null, null); |
... | ... | |
1147 | 1161 |
//succeeds to update this document |
1148 | 1162 |
updateDocid(newdocid + ".15", testdocument, SUCCESS, false); |
1149 | 1163 |
//fails to update access part |
1150 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1164 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1151 | 1165 |
null, null, null, |
1152 | 1166 |
null, getAccessBlock(anotheruser, true, |
1153 | 1167 |
true, false, false, false), |
... | ... | |
1170 | 1184 |
accessRules.add(accessRule2); |
1171 | 1185 |
access = getAccessBlock(accessRules, DENYFIRST); |
1172 | 1186 |
System.out.println("the access part is "+access); |
1173 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1187 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1174 | 1188 |
null, null, null, |
1175 | 1189 |
null, access , |
1176 | 1190 |
null, null, null, null); |
... | ... | |
1185 | 1199 |
//succeeds to update this document |
1186 | 1200 |
updateDocid(newdocid + ".17", testdocument, SUCCESS, false); |
1187 | 1201 |
//succeeds to update access part |
1188 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1202 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1189 | 1203 |
null, null, null, |
1190 | 1204 |
null, getAccessBlock(anotheruser, true, |
1191 | 1205 |
true, true, true, true), |
... | ... | |
1211 | 1225 |
accessRules.add(accessRule2); |
1212 | 1226 |
access = getAccessBlock(accessRules, DENYFIRST); |
1213 | 1227 |
System.out.println("the access part is "+access); |
1214 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1228 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1215 | 1229 |
null, null, null, |
1216 | 1230 |
null, access , |
1217 | 1231 |
null, null, null, null); |
... | ... | |
1226 | 1240 |
//succeeds to update this document |
1227 | 1241 |
updateDocid(newdocid + ".20", testdocument, SUCCESS, false); |
1228 | 1242 |
//fails to update access part |
1229 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1243 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1230 | 1244 |
null, null, null, |
1231 | 1245 |
null, getAccessBlock(anotheruser, true, |
1232 | 1246 |
true, false, false, false), |
... | ... | |
1250 | 1264 |
accessRules.add(accessRule2); |
1251 | 1265 |
access = getAccessBlock(accessRules, DENYFIRST); |
1252 | 1266 |
System.out.println("the access part is "+access); |
1253 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1267 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1254 | 1268 |
null, null, null, |
1255 | 1269 |
null, access , |
1256 | 1270 |
null, null, null, null); |
... | ... | |
1265 | 1279 |
//succeeds to update this document |
1266 | 1280 |
updateDocid(newdocid + ".22", testdocument, SUCCESS, false); |
1267 | 1281 |
//fails to update access part |
1268 |
testdocument = getTestEmlDoc("Testing user can't not read, write and delete a document",
|
|
1282 |
testdocument = getTestEmlDoc("Testing user can not read, write and delete a document", |
|
1269 | 1283 |
null, null, null, |
1270 | 1284 |
null, getAccessBlock(anotheruser, true, |
1271 | 1285 |
true, false, false, false), |
... | ... | |
1342 | 1356 |
// update the document |
1343 | 1357 |
testdocument = getTestEmlDoc("Testing update", null, null, null, |
1344 | 1358 |
null, null, null, null, null, null); |
1359 |
Thread.sleep(10000); |
|
1345 | 1360 |
updateDocid(newdocid + ".2", testdocument, SUCCESS, false); |
1346 | 1361 |
readDocidWhichEqualsDoc(newdocid, testdocument, SUCCESS, false); |
1347 | 1362 |
|
... | ... | |
1962 | 1977 |
if (result) { |
1963 | 1978 |
|
1964 | 1979 |
if (!testDoc.equals(doc)) { |
1965 |
System.out.println("doc :" + doc); |
|
1980 |
System.out.println("doc :" + doc);
|
|
1966 | 1981 |
System.out.println("testDoc:" + testDoc); |
1967 | 1982 |
} |
1968 | 1983 |
|
Also available in: Unified diff
Checkinto cvs head.Move the initialize option statement to the begining of class, since user name is using getting option.