Revision 8612
Added by Peter Slaughter almost 11 years ago
test/edu/ucsb/nceas/metacat/admin/upgrade/dataone/SyncAccessPolicyTest.java | ||
---|---|---|
70 | 70 |
import edu.ucsb.nceas.metacat.shared.MetacatUtilException; |
71 | 71 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
72 | 72 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
73 |
import edu.ucsb.nceas.utilities.access.AccessControlInterface; |
|
73 | 74 |
import junit.framework.Test; |
74 | 75 |
import junit.framework.TestSuite; |
75 | 76 |
|
... | ... | |
79 | 80 |
*/ |
80 | 81 |
public class SyncAccessPolicyTest extends D1NodeServiceTest { |
81 | 82 |
|
82 |
// private static String username; |
|
83 |
// private static String password; |
|
84 |
// private static String anotheruser; |
|
85 |
// private static String anotherPassword; |
|
86 |
// |
|
87 |
// static { |
|
88 |
// try { |
|
89 |
// |
|
90 |
// username = PropertyService.getProperty("test.mcUser"); |
|
91 |
// password = PropertyService.getProperty("test.mcPassword"); |
|
92 |
// anotheruser = PropertyService.getProperty("test.mcAnotherUser"); |
|
93 |
// anotherpassword = PropertyService |
|
94 |
// .getProperty("test.mcAnotherPassword"); |
|
95 |
// |
|
96 |
// } catch (PropertyNotFoundException pnfe) { |
|
97 |
// System.err.println("Could not get property in static block: " |
|
98 |
// + pnfe.getMessage()); |
|
99 |
// } |
|
100 |
// } |
|
101 |
|
|
102 | 83 |
private Metacat m; |
103 | 84 |
|
104 | 85 |
/** |
... | ... | |
153 | 134 |
} |
154 | 135 |
|
155 | 136 |
/** |
137 |
* constructs a "fake" session with a test subject |
|
138 |
* @return |
|
139 |
*/ |
|
140 |
@Override |
|
141 |
public Session getTestSession() throws Exception { |
|
142 |
Session session = new Session(); |
|
143 |
Subject subject = new Subject(); |
|
144 |
subject.setValue(anotheruser); |
|
145 |
session.setSubject(subject); |
|
146 |
return session; |
|
147 |
} |
|
148 |
/** |
|
156 | 149 |
* Test object creation |
157 | 150 |
*/ |
158 | 151 |
public Identifier createTestPid() { |
... | ... | |
167 | 160 |
SystemMetadata sysmeta = createSystemMetadata(guid, |
168 | 161 |
session.getSubject(), object); |
169 | 162 |
|
170 |
AccessPolicy accessPolicy = sysmeta.getAccessPolicy(); |
|
171 |
AccessRule allow = new AccessRule(); |
|
172 |
allow.addPermission(Permission.CHANGE_PERMISSION); |
|
173 |
Subject publicSubject = new Subject(); |
|
174 |
publicSubject.setValue(Constants.SUBJECT_PUBLIC); |
|
175 |
allow.addSubject(publicSubject); |
|
176 |
accessPolicy.addAllow(allow); |
|
177 |
sysmeta.setAccessPolicy(accessPolicy); |
|
178 |
|
|
179 | 163 |
pid = MNodeService.getInstance(request).create(session, guid, |
180 | 164 |
object, sysmeta); |
181 | 165 |
} catch (Exception e) { |
... | ... | |
194 | 178 |
SystemMetadata mnSysMeta = null; |
195 | 179 |
String resultXML = null; |
196 | 180 |
|
197 |
debug("Logging in with user: " + username); |
|
198 | 181 |
String response = null; |
182 |
debug("Logging in with user: " + anotheruser + ", password: " |
|
183 |
+ anotherpassword); |
|
184 |
try { |
|
185 |
response = m.login(anotheruser, anotherpassword); |
|
186 |
debug("Login response: " + response); |
|
187 |
} catch (Exception e) { |
|
188 |
debug("Unable to login: " + response); |
|
189 |
fail(); |
|
190 |
} |
|
199 | 191 |
|
200 | 192 |
try { |
201 | 193 |
debug("\nStarting sync access policy test"); |
... | ... | |
273 | 265 |
debug("Unable to retrieve localId for pid: " + pid.getValue()); |
274 | 266 |
fail(); |
275 | 267 |
} |
276 |
|
|
277 |
debug("Logging in with user: " + anotheruser + ", password: " + anotherpassword); |
|
278 |
try { |
|
279 |
response = m.login(anotheruser, anotherpassword); |
|
280 |
debug("Login response: " + response); |
|
281 |
} catch (Exception e) { |
|
282 |
debug("Unable to login: " + response); |
|
283 |
fail(); |
|
284 |
} |
|
285 |
|
|
268 |
|
|
286 | 269 |
debug("Updating permissions of localId: " + localId + ", guid: " |
287 |
+ pid.getValue()); |
|
270 |
+ pid.getValue() + ", username: " + username + " read, allow, allowFirst");
|
|
288 | 271 |
|
289 |
// Now update the access policy on the local metacat using the |
|
290 |
// metacat api |
|
291 |
fieldValuePairs = new Hashtable<String, String[]>(); |
|
292 |
fieldValuePairs.put("action", new String[] { "setaccess" }); |
|
293 |
fieldValuePairs.put("docid", new String[] { localId }); |
|
294 |
fieldValuePairs.put("principal", new String[] { username }); |
|
295 |
fieldValuePairs.put("permission", new String[] { "read" }); |
|
296 |
fieldValuePairs.put("permType", new String[] { "allow" }); |
|
297 |
fieldValuePairs.put("permOrder", new String[] { "allowFirst" }); |
|
298 |
debug("Updating access perms for docid: " + localId); |
|
299 | 272 |
try { |
300 |
resultXML = RequestUtil.get(metacatUrl, fieldValuePairs); |
|
273 |
response = m.setAccess(localId, username, |
|
274 |
AccessControlInterface.READSTRING, |
|
275 |
AccessControlInterface.ALLOW, |
|
276 |
AccessControlInterface.ALLOWFIRST); |
|
301 | 277 |
} catch (Exception e) { |
302 |
debug("Error setting permissions on docid: " + localId); |
|
278 |
debug("Response from setaccess: " + response); |
|
279 |
debug("Error setting access for localId: " + e.getMessage()); |
|
303 | 280 |
fail(); |
304 | 281 |
} |
305 |
|
|
306 |
if (!resultXML.contains("success")) { |
|
307 |
debug("Unable to change access policy on MN, response: " + resultXML); |
|
308 |
fail(); |
|
309 |
} |
|
310 |
|
|
282 |
|
|
283 |
debug("Response from setaccess: " + response); |
|
311 | 284 |
debug("Retrieving updated docid from CN to check if perms were updated..."); |
312 | 285 |
|
313 | 286 |
// Get the test document from the CN |
... | ... | |
328 | 301 |
debug("Diffing access policies (MN,CN) for pid: " + pid.getValue()); |
329 | 302 |
SyncAccessPolicy syncAP = new SyncAccessPolicy(); |
330 | 303 |
debug("Comparing access policies..."); |
331 |
assert (syncAP.isEqual(mnAccessPolicy, cnAccessPolicy)); |
|
304 |
|
|
305 |
Boolean apEqual = new Boolean (syncAP.isEqual(mnAccessPolicy, cnAccessPolicy)); |
|
306 |
debug("Access policies are equal is " + apEqual.toString()); |
|
307 |
assert (apEqual == true); |
|
332 | 308 |
|
333 | 309 |
m.logout(); |
334 | 310 |
|
Also available in: Unified diff
Use client.MetacatClient instance for all metacat api calls