26 |
26 |
package edu.ucsb.nceas.metacat.admin.upgrade.dataone;
|
27 |
27 |
|
28 |
28 |
import java.io.ByteArrayInputStream;
|
29 |
|
import java.io.File;
|
30 |
29 |
import java.io.InputStream;
|
31 |
|
import java.io.StringReader;
|
32 |
|
import java.io.UnsupportedEncodingException;
|
33 |
30 |
import java.util.Hashtable;
|
34 |
31 |
|
35 |
|
import org.apache.http.client.HttpClient;
|
36 |
|
import org.apache.http.impl.client.DefaultHttpClient;
|
|
32 |
import junit.framework.Test;
|
|
33 |
import junit.framework.TestSuite;
|
|
34 |
|
37 |
35 |
import org.dataone.client.CNode;
|
38 |
36 |
import org.dataone.client.D1Client;
|
39 |
|
import org.dataone.service.exceptions.IdentifierNotUnique;
|
40 |
|
import org.dataone.service.exceptions.InsufficientResources;
|
41 |
|
import org.dataone.service.exceptions.InvalidRequest;
|
42 |
|
import org.dataone.service.exceptions.InvalidSystemMetadata;
|
43 |
|
import org.dataone.service.exceptions.InvalidToken;
|
44 |
|
import org.dataone.service.exceptions.NotAuthorized;
|
45 |
|
import org.dataone.service.exceptions.NotImplemented;
|
46 |
37 |
import org.dataone.service.exceptions.ServiceFailure;
|
47 |
|
import org.dataone.service.exceptions.UnsupportedType;
|
48 |
38 |
import org.dataone.service.types.v1.AccessPolicy;
|
49 |
39 |
import org.dataone.service.types.v1.AccessRule;
|
50 |
40 |
import org.dataone.service.types.v1.Identifier;
|
... | ... | |
52 |
42 |
import org.dataone.service.types.v1.Session;
|
53 |
43 |
import org.dataone.service.types.v1.Subject;
|
54 |
44 |
import org.dataone.service.types.v1.SystemMetadata;
|
55 |
|
import org.dataone.service.util.Constants;
|
56 |
45 |
import org.junit.Before;
|
57 |
46 |
|
58 |
|
import edu.ucsb.nceas.MCTestCase;
|
59 |
47 |
import edu.ucsb.nceas.metacat.IdentifierManager;
|
60 |
|
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
|
61 |
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
|
62 |
48 |
import edu.ucsb.nceas.metacat.client.Metacat;
|
63 |
49 |
import edu.ucsb.nceas.metacat.client.MetacatFactory;
|
64 |
50 |
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
65 |
|
import edu.ucsb.nceas.metacat.dataone.CNodeServiceTest;
|
|
51 |
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
|
66 |
52 |
import edu.ucsb.nceas.metacat.dataone.MNodeService;
|
67 |
|
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
|
68 |
53 |
import edu.ucsb.nceas.metacat.dataone.SyncAccessPolicy;
|
69 |
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
70 |
|
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
|
71 |
|
import edu.ucsb.nceas.metacat.util.RequestUtil;
|
72 |
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
73 |
54 |
import edu.ucsb.nceas.utilities.access.AccessControlInterface;
|
74 |
|
import junit.framework.Test;
|
75 |
|
import junit.framework.TestSuite;
|
76 |
55 |
|
77 |
56 |
/**
|
78 |
57 |
* A JUnit test for testing syncing access policies between MN -> CN after local
|
... | ... | |
120 |
99 |
public static Test suite() {
|
121 |
100 |
TestSuite suite = new TestSuite();
|
122 |
101 |
suite.addTest(new SyncAccessPolicyTest("initialize"));
|
|
102 |
suite.addTest(new SyncAccessPolicyTest("testIsEqual"));
|
123 |
103 |
suite.addTest(new SyncAccessPolicyTest("testSyncAccessPolicy"));
|
124 |
104 |
|
125 |
105 |
return suite;
|
... | ... | |
315 |
295 |
|
316 |
296 |
debug("Done running testSyncAccessPolicy");
|
317 |
297 |
}
|
|
298 |
|
|
299 |
public void testIsEqual() {
|
|
300 |
AccessPolicy ap1 = new AccessPolicy();
|
|
301 |
AccessRule ar1 = new AccessRule();
|
|
302 |
ar1.addPermission(Permission.READ);
|
|
303 |
Subject subject1 = new Subject();
|
|
304 |
subject1.setValue(username);
|
|
305 |
ar1.addSubject(subject1);
|
|
306 |
ap1.addAllow(ar1);
|
|
307 |
|
|
308 |
AccessPolicy ap2 = new AccessPolicy();
|
|
309 |
AccessRule ar2 = new AccessRule();
|
|
310 |
ar2.addPermission(Permission.READ);
|
|
311 |
Subject subject2 = new Subject();
|
|
312 |
subject2.setValue(username);
|
|
313 |
ar2.addSubject(subject2);
|
|
314 |
ap2.addAllow(ar2);
|
|
315 |
|
|
316 |
boolean isEqual = false;
|
|
317 |
SyncAccessPolicy syncAP = new SyncAccessPolicy();
|
|
318 |
|
|
319 |
// try something that should be true
|
|
320 |
isEqual = syncAP.isEqual(ap1, ap2);
|
|
321 |
assertTrue(isEqual);
|
|
322 |
|
|
323 |
// try something that makes them not equal
|
|
324 |
Subject subject3 = new Subject();
|
|
325 |
subject3.setValue(anotheruser);
|
|
326 |
ar2.addSubject(subject3);
|
|
327 |
|
|
328 |
isEqual = syncAP.isEqual(ap1, ap2);
|
|
329 |
assertFalse(isEqual);
|
|
330 |
|
|
331 |
isEqual = syncAP.isEqual(ap1, null);
|
|
332 |
assertFalse(isEqual);
|
|
333 |
}
|
318 |
334 |
}
|
include a few tests for isEqual method. https://projects.ecoinformatics.org/ecoinfo/issues/6407