Revision 10181
Added by Jing Tao over 7 years ago
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java | ||
---|---|---|
1591 | 1591 |
} |
1592 | 1592 |
|
1593 | 1593 |
try { |
1594 |
|
|
1595 |
Session session = getTestSession(); |
|
1596 |
Identifier guid = new Identifier(); |
|
1597 |
guid.setValue("testArchive." + System.currentTimeMillis()); |
|
1598 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
1599 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
1600 |
NodeReference nr = new NodeReference(); |
|
1601 |
nr.setValue(MockCNode.V1MNNODEID); |
|
1602 |
sysmeta.setOriginMemberNode(nr); |
|
1603 |
sysmeta.setAuthoritativeMemberNode(nr); |
|
1604 |
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
|
1605 |
//another session without any permission shouldn't archive the object |
|
1606 |
try { |
|
1607 |
Session session2 = getAnotherSession(); |
|
1608 |
CNodeService.getInstance(request).archive(session2, guid); |
|
1609 |
fail("Another session shouldn't archive the object"); |
|
1610 |
} catch (NotAuthorized ee){ |
|
1611 |
|
|
1612 |
} |
|
1613 |
//rights holder should archive objects whose authoritative mn is a v1 node |
|
1614 |
CNodeService.getInstance(request).archive(session, guid); |
|
1615 |
} catch (Exception e) { |
|
1616 |
e.printStackTrace(); |
|
1617 |
fail("Unexpected error: " + e.getMessage()); |
|
1618 |
} |
|
1619 |
|
|
1620 |
try { |
|
1621 |
//a session has the change permission should archive objects whose authoritative mn is a v1 node |
|
1622 |
String user1 = "test12"; |
|
1623 |
String user2 = "test34"; |
|
1624 |
Session session = getTestSession(); |
|
1625 |
Identifier guid = new Identifier(); |
|
1626 |
guid.setValue("testArchive." + System.currentTimeMillis()); |
|
1627 |
InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8")); |
|
1628 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object); |
|
1629 |
NodeReference nr = new NodeReference(); |
|
1630 |
nr.setValue(MockCNode.V1MNNODEID); |
|
1631 |
sysmeta.setOriginMemberNode(nr); |
|
1632 |
sysmeta.setAuthoritativeMemberNode(nr); |
|
1633 |
Subject sub1 = new Subject(); |
|
1634 |
sub1.setValue(user1); |
|
1635 |
AccessRule rule1 = new AccessRule(); |
|
1636 |
rule1.addSubject(sub1); |
|
1637 |
rule1.addPermission(Permission.CHANGE_PERMISSION); |
|
1638 |
Subject sub2 = new Subject(); |
|
1639 |
sub2.setValue(user2); |
|
1640 |
AccessRule rule2 = new AccessRule(); |
|
1641 |
rule2.addSubject(sub2); |
|
1642 |
rule2.addPermission(Permission.READ); |
|
1643 |
AccessPolicy policy = new AccessPolicy(); |
|
1644 |
policy.addAllow(rule1); |
|
1645 |
policy.addAllow(rule2); |
|
1646 |
sysmeta.setAccessPolicy(policy); |
|
1647 |
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta); |
|
1648 |
//read permission can't archive the object |
|
1649 |
try { |
|
1650 |
Session session2 = new Session(); |
|
1651 |
session2.setSubject(sub2); |
|
1652 |
CNodeService.getInstance(request).archive(session2, guid); |
|
1653 |
fail("READ permision session shouldn't archive the object"); |
|
1654 |
} catch (NotAuthorized ee){ |
|
1655 |
ee.printStackTrace(); |
|
1656 |
} |
|
1657 |
Session session3 = new Session(); |
|
1658 |
session3.setSubject(sub1); |
|
1659 |
CNodeService.getInstance(request).archive(session, guid); |
|
1660 |
} catch (Exception e) { |
|
1661 |
e.printStackTrace(); |
|
1662 |
fail("Unexpected error: " + e.getMessage()); |
|
1663 |
} |
|
1664 |
|
|
1665 |
try { |
|
1594 | 1666 |
//v2 mn should faile |
1595 | 1667 |
Session session = getCNSession(); |
1596 | 1668 |
Identifier guid = new Identifier(); |
Also available in: Unified diff
Add more permission tests on the archive method.