use of org.exist.Database in project exist by eXist-db.
the class AbstractAccountTest method addGroup_calls_assertCanModifyGroup.
@Test
public void addGroup_calls_assertCanModifyGroup() throws PermissionDeniedException, NoSuchMethodException {
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
AbstractRealm mockRealm = EasyMock.createMock(AbstractRealm.class);
Database mockDatabase = EasyMock.createMock(Database.class);
Subject mockSubject = EasyMock.createMock(Subject.class);
Group mockGroup = EasyMock.createMock(Group.class);
Account partialMockAccount = EasyMock.createMockBuilder(AbstractAccount.class).withConstructor(DBBroker.class, AbstractRealm.class, int.class, String.class).withArgs(mockBroker, mockRealm, 1, "testAccount").addMockedMethod(AbstractGroup.class.getDeclaredMethod("_addManager", Account.class)).createMock();
// expectations
expect(mockRealm.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockSubject);
mockGroup.assertCanModifyGroup(mockSubject);
expect(mockGroup.getName()).andReturn("testGroup");
replay(mockRealm, mockDatabase, mockBroker, mockGroup, partialMockAccount);
// test
partialMockAccount.addGroup(mockGroup);
verify(mockRealm, mockDatabase, mockBroker, mockGroup, partialMockAccount);
// TODO calls on assert from AbstractAccountXQuery
}
use of org.exist.Database in project exist by eXist-db.
the class AbstractAccountTest method remGroup_calls_assertCanModifyGroupForEachGroup.
@Test
public void remGroup_calls_assertCanModifyGroupForEachGroup() throws PermissionDeniedException, ConfigurationException {
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
AbstractRealm mockRealm = EasyMock.createMock(AbstractRealm.class);
Database mockDatabase = EasyMock.createMock(Database.class);
Subject mockSubject = EasyMock.createMock(Subject.class);
Group mockGroup = EasyMock.createMock(Group.class);
final String groupName = "testGroup";
TestableAbstractAccount partialMockAccount = new TestableAbstractAccount(mockBroker, mockRealm, 1, "testGroup");
List<Group> groups = new ArrayList<Group>();
groups.add(mockGroup);
partialMockAccount.setInternalGroups(groups);
// expectations
expect(mockRealm.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockSubject);
expect(mockGroup.getName()).andReturn(groupName);
mockGroup.assertCanModifyGroup(mockSubject);
replay(mockRealm, mockDatabase, mockBroker, mockGroup);
// test
try {
partialMockAccount.remGroup(groupName);
} catch (final PermissionDeniedException e) {
assertEquals("You cannot remove the primary group of an account.", e.getMessage());
}
verify(mockRealm, mockDatabase, mockBroker, mockGroup);
// TODO calls on assert from AbstractAccountXQuery
}
use of org.exist.Database in project exist by eXist-db.
the class DocumentImplTest method isSameNode_sameDoc.
@Test
public void isSameNode_sameDoc() {
final BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
final Group mockCurrentSubjectGroup = EasyMock.createMock(Group.class);
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
// expectations
expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject);
expect(mockCurrentSubject.getUserMask()).andReturn(Permission.DEFAULT_UMASK);
expect(mockCurrentSubject.getId()).andReturn(RealmImpl.SYSTEM_ACCOUNT_ID);
expect(mockCurrentSubject.getDefaultGroup()).andReturn(mockCurrentSubjectGroup);
expect(mockCurrentSubjectGroup.getId()).andReturn(RealmImpl.DBA_GROUP_ID);
replay(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
// test setup
final DocumentImpl doc = new DocumentImpl(mockBrokerPool, 99);
assertTrue(doc.isSameNode(doc));
verify(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
}
use of org.exist.Database in project exist by eXist-db.
the class DocumentImplTest method copyOf_updates_metadata_created_and_lastModified.
@Test
public void copyOf_updates_metadata_created_and_lastModified() throws PermissionDeniedException {
BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
Database mockDatabase = EasyMock.createMock(Database.class);
DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
Group mockCurrentSubjectGroup = EasyMock.createMock(Group.class);
SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
// test values
final long otherCreated = System.currentTimeMillis() - 2000;
final long otherLastModified = System.currentTimeMillis() - 1000;
// expectations
expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager).times(2);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase).times(2);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker).times(2);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject).times(2);
expect(mockCurrentSubject.getUserMask()).andReturn(Permission.DEFAULT_UMASK).times(2);
expect(mockCurrentSubject.getId()).andReturn(RealmImpl.SYSTEM_ACCOUNT_ID).times(2);
expect(mockCurrentSubject.getDefaultGroup()).andReturn(mockCurrentSubjectGroup).times(2);
expect(mockCurrentSubjectGroup.getId()).andReturn(RealmImpl.DBA_GROUP_ID).times(2);
replay(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
// test setup
DocumentImpl doc = new DocumentImpl(mockBrokerPool, 888);
DocumentImpl other = new DocumentImpl(mockBrokerPool, 999);
// actions
doc.copyOf(mockBroker, other, (DocumentImpl) null);
verify(mockBrokerPool, mockDatabase, mockBroker, mockCurrentSubject, mockCurrentSubjectGroup, mockSecurityManager);
// assertions
assertThat(otherCreated, new LessThan(doc.getCreated()));
assertThat(otherLastModified, new LessThan(doc.getLastModified()));
}
use of org.exist.Database in project exist by eXist-db.
the class SimpleACLPermissionTest method insert_atFront.
@Test
public void insert_atFront() throws PermissionDeniedException {
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final Database mockDatabase = EasyMock.createMock(Database.class);
final DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase).times(2);
expect(mockDatabase.getActiveBroker()).andReturn(mockBroker).times(2);
expect(mockBroker.getCurrentSubject()).andReturn(mockCurrentSubject).times(2);
expect(mockCurrentSubject.hasDbaRole()).andReturn(true).times(2);
replay(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
assertEquals(0, permission.getACECount());
final int userId = 1112;
final int mode = ALL;
permission.addUserACE(ACE_ACCESS_TYPE.ALLOWED, userId, mode);
assertEquals(1, permission.getACECount());
assertEquals(userId, permission.getACEId(0));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
assertEquals(ALL, permission.getACEMode(0));
final int secondUserId = 1113;
final int secondMode = 04;
permission.insertUserACE(0, ACE_ACCESS_TYPE.ALLOWED, secondUserId, secondMode);
assertEquals(2, permission.getACECount());
assertEquals(secondUserId, permission.getACEId(0));
assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
assertEquals(secondMode, permission.getACEMode(0));
verify(mockSecurityManager, mockDatabase, mockBroker, mockCurrentSubject);
}
Aggregations