Search in sources :

Example 31 with Database

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
}
Also used : DBBroker(org.exist.storage.DBBroker) Database(org.exist.Database) Test(org.junit.Test)

Example 32 with Database

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
}
Also used : DBBroker(org.exist.storage.DBBroker) Database(org.exist.Database) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 33 with Database

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Database(org.exist.Database) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 34 with Database

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()));
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Database(org.exist.Database) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 35 with Database

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);
}
Also used : DBBroker(org.exist.storage.DBBroker) Database(org.exist.Database) Test(org.junit.Test)

Aggregations

Database (org.exist.Database)42 DBBroker (org.exist.storage.DBBroker)34 Test (org.junit.Test)29 EXistException (org.exist.EXistException)6 SecurityManager (org.exist.security.SecurityManager)5 BrokerPool (org.exist.storage.BrokerPool)4 XmldbURI (org.exist.xmldb.XmldbURI)4 XQuery (org.exist.xquery.XQuery)4 IOException (java.io.IOException)3 Random (java.util.Random)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 CompiledXQuery (org.exist.xquery.CompiledXQuery)3 Ignore (org.junit.Ignore)3 StringWriter (java.io.StringWriter)2 Collection (org.exist.collections.Collection)2 Configuration (org.exist.config.Configuration)2 StreamListener (org.exist.indexing.StreamListener)2 SecurityManagerImpl (org.exist.security.internal.SecurityManagerImpl)2 Serializer (org.exist.storage.serializers.Serializer)2 Configuration (org.exist.util.Configuration)2