Search in sources :

Example 6 with JpaGroupRoleProvider

use of org.opencastproject.userdirectory.JpaGroupRoleProvider in project opencast by opencast.

the class OpencastLdapAuthoritiesPopulatorTest method testWrongOrganization.

@Test
public void testWrongOrganization() {
    OpencastLdapAuthoritiesPopulator populator;
    // Prepare the mappings
    mappings.put("myAttribute", new String[] { " value1 ", " value2 ", " value3 ", " value4 " });
    String attributes = StringUtils.join(mappings.keySet(), ", ");
    // Prepare the alternative organization
    Organization otherOrg = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(otherOrg.getId()).andReturn("other_organization").anyTimes();
    EasyMock.replay(otherOrg);
    // Test several argument combinations
    for (String prefix : PREFIX_TESTS) {
        for (String[] excludePrefixes : EXCLUDE_PREFIXES_TESTS) {
            for (boolean upper : UPPERCASE_TESTS) {
                for (JpaGroupRoleProvider groupRoleProvider : groupRoleProviderTests) {
                    for (String[] extraRoles : EXTRA_ROLES_TESTS) {
                        try {
                            populator = new OpencastLdapAuthoritiesPopulator(attributes, prefix, excludePrefixes, upper, otherOrg, securityService, groupRoleProvider, extraRoles);
                            doTest(populator, mappings, prefix, excludePrefixes, upper, extraRoles, groupRoleProvider);
                            fail(format("Request came from a different organization (\"%s\") as the expected (\"%s\") but no exception was thrown", otherOrg, org));
                        } catch (SecurityException e) {
                        // OK
                        }
                    }
                }
            }
        }
    }
}
Also used : Organization(org.opencastproject.security.api.Organization) JpaGroupRoleProvider(org.opencastproject.userdirectory.JpaGroupRoleProvider) Test(org.junit.Test)

Example 7 with JpaGroupRoleProvider

use of org.opencastproject.userdirectory.JpaGroupRoleProvider in project opencast by opencast.

the class OpencastLdapAuthoritiesPopulatorTest method testEmptySingleAttribute.

@Test
public void testEmptySingleAttribute() {
    OpencastLdapAuthoritiesPopulator populator;
    // Prepare the mappings
    mappings.put("myAttribute", new String[] { "" });
    String attributes = StringUtils.join(mappings.keySet(), ", ");
    // Test several argument combinations
    for (String prefix : PREFIX_TESTS) {
        for (String[] excludePrefixes : EXCLUDE_PREFIXES_TESTS) {
            for (boolean upper : UPPERCASE_TESTS) {
                for (JpaGroupRoleProvider groupRoleProvider : groupRoleProviderTests) {
                    for (String[] extraRoles : EXTRA_ROLES_TESTS) {
                        populator = new OpencastLdapAuthoritiesPopulator(attributes, prefix, excludePrefixes, upper, org, securityService, groupRoleProvider, extraRoles);
                        doTest(populator, mappings, prefix, excludePrefixes, upper, extraRoles, groupRoleProvider);
                    }
                }
            }
        }
    }
}
Also used : JpaGroupRoleProvider(org.opencastproject.userdirectory.JpaGroupRoleProvider) Test(org.junit.Test)

Example 8 with JpaGroupRoleProvider

use of org.opencastproject.userdirectory.JpaGroupRoleProvider in project opencast by opencast.

the class OpencastLdapAuthoritiesPopulatorTest method testEmptyAttributeArray.

@Test
public void testEmptyAttributeArray() {
    OpencastLdapAuthoritiesPopulator populator;
    // Prepare the mappings
    // The attribute returns an empty array
    mappings.put("myAttribute", new String[] {});
    String attributes = StringUtils.join(mappings.keySet(), ", ");
    // Test several argument combinations
    for (String prefix : PREFIX_TESTS) {
        for (String[] excludePrefixes : EXCLUDE_PREFIXES_TESTS) {
            for (boolean upper : UPPERCASE_TESTS) {
                for (JpaGroupRoleProvider groupRoleProvider : groupRoleProviderTests) {
                    for (String[] extraRoles : EXTRA_ROLES_TESTS) {
                        populator = new OpencastLdapAuthoritiesPopulator(attributes, prefix, excludePrefixes, upper, org, securityService, groupRoleProvider, extraRoles);
                        doTest(populator, mappings, prefix, excludePrefixes, upper, extraRoles, groupRoleProvider);
                    }
                }
            }
        }
    }
}
Also used : JpaGroupRoleProvider(org.opencastproject.userdirectory.JpaGroupRoleProvider) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 JpaGroupRoleProvider (org.opencastproject.userdirectory.JpaGroupRoleProvider)8 Organization (org.opencastproject.security.api.Organization)1