Beispiel #1
0
 def setUp(self):
     self.reg = Registry()
     self.__work_zone_dir = tempfile.TemporaryDirectory()
     self.reg.settings = {'extract.work_zone_base_dir': '/tmp/work_zone',
                          'pickup.gatekeeper.t1': '/t/acb',
                          'pickup.gatekeeper.t2': '/a/df',
                          'pickup.gatekeeper.y': '/a/c',
                          'pickup.sftp.hostname': 'hostname.local.net',
                          'pickup.sftp.user': '******',
                          'pickup.sftp.private_key_file': '/home/users/myUser/.ssh/id_rsa',
                          'extract.available_grades': '3,4,5,6,7,8,11'}
     cache_opts = {
         'cache.type': 'memory',
         'cache.regions': 'public.data,public.filtered_data,public.shortlived'
     }
     CacheManager(**parse_cache_config_options(cache_opts))
     # Set up user context
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(registry=self.reg, request=self.__request, hook_zca=False)
     defined_roles = [(Allow, RolesConstants.SAR_EXTRACTS, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS])
     self.__config.testing_securitypolicy(dummy_session.get_user())
 def setUp(self):
     self.reg = Registry()
     self.__work_zone_dir = tempfile.TemporaryDirectory()
     self.reg.settings = {
         'extract.work_zone_base_dir': '/tmp/work_zone',
         'extract.available_grades': '3,4,5,6,7,8,11',
         'hpz.file_upload_base_url': 'http://somehost:82/files'
     }
     settings = {'extract.celery.CELERY_ALWAYS_EAGER': True}
     setup_celery(settings)
     cache_opts = {
         'cache.type': 'memory',
         'cache.regions':
         'public.data,public.filtered_data,public.shortlived'
     }
     CacheManager(**parse_cache_config_options(cache_opts))
     # Set up user context
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(registry=self.reg,
                                   request=self.__request,
                                   hook_zca=False)
     defined_roles = [
         (Allow, RolesConstants.SRS_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.SRC_EXTRACTS, ('view', 'logout'))
     ]
     edauth.set_roles(defined_roles)
     dummy_session = create_test_session(
         [RolesConstants.SRS_EXTRACTS, RolesConstants.SRC_EXTRACTS])
     self.__config.testing_securitypolicy(dummy_session.get_user())
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__tenant_name = get_unittest_tenant_name()
     set_tenant_map({self.__tenant_name: "NC"})
     defined_roles = [
         (Allow, RolesConstants.PII, ('view', 'logout')),
         (Allow, RolesConstants.SRS_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.SRC_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.AUDIT_XML_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout'))
     ]
     edauth.set_roles(defined_roles)
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context([
         RoleRelation(RolesConstants.PII, get_unittest_tenant_name(), "NC",
                      "228", "242"),
         RoleRelation(RolesConstants.PII, get_unittest_tenant_name(), "NC",
                      "228", "245"),
         RoleRelation(RolesConstants.SRS_EXTRACTS,
                      get_unittest_tenant_name(), 'NC', None, None),
         RoleRelation(RolesConstants.SRC_EXTRACTS,
                      get_unittest_tenant_name(), 'NC', None, None),
         RoleRelation(RolesConstants.AUDIT_XML_EXTRACTS,
                      get_unittest_tenant_name(), 'NC', None, None)
     ])
     # For Context Security, we need to save the user object
     self.__config.testing_securitypolicy(dummy_session.get_user())
Beispiel #4
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     reg = Registry()
     reg.settings = {}
     self.__config = testing.setUp(registry=reg,
                                   request=self.__request,
                                   hook_zca=False)
     self.__tenant_name = get_unittest_tenant_name()
     defined_roles = [
         (Allow, RolesConstants.SAR_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout'))
     ]
     edauth.set_roles(defined_roles)
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
     # Set up context security
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS])
     dummy_session.set_user_context([
         RoleRelation(RolesConstants.SAR_EXTRACTS,
                      get_unittest_tenant_name(), "NC", None, None),
         RoleRelation(RolesConstants.AUDIT_XML_EXTRACTS,
                      get_unittest_tenant_name(), "NC", None, None),
         RoleRelation(RolesConstants.ITEM_LEVEL_EXTRACTS,
                      get_unittest_tenant_name(), "NC", None, None)
     ])
     self.__config.testing_securitypolicy(dummy_session.get_user())
 def test_login_redirected_due_to_no_role(self):
     # set up session data
     session = create_test_session(roles=['NONE'], uid='linda.kim', full_name='Linda Kim', idpSessionIndex='123', save_to_backend=True)
     self.__config.testing_securitypolicy(session.get_session_id(), ['NONE'])
     self.__request.url = 'http://example.com/dummy/page'
     http = login(self.__request)
     self.assertIsInstance(http, HTTPForbidden)
Beispiel #6
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     reg = Registry()
     self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
     dummy_session = create_test_session(['SUPER_USER'], uid='272', tenant='cat')
     self.__config.testing_securitypolicy(dummy_session)
Beispiel #7
0
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.data,public.filtered_data,public.shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))
        self.__request = DummyRequest()
        # Must set hook_zca to false to work with uniittest_with_sqlite
        reg = Registry()
        reg.settings = {}
        reg.settings = {'extract.available_grades': '3,4,5,6,7,8,9,11',
                        'hpz.file_upload_base_url': 'http://somehost:82/files',
                        'extract.raw_data_base_dir': '/opt/edware/raw_data'}
        self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
        self.__tenant_name = get_unittest_tenant_name()

        defined_roles = [(Allow, RolesConstants.AUDIT_XML_EXTRACTS, ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        set_tenant_map({get_unittest_tenant_name(): 'NC'})
        # Set up context security
        dummy_session = create_test_session([RolesConstants.AUDIT_XML_EXTRACTS])
        self.__config.testing_securitypolicy(dummy_session.get_user())
        # celery settings for UT
        settings = {'extract.celery.CELERY_ALWAYS_EAGER': True}
        setup_celery(settings)
        # for UT purposes
        smarter.extracts.format.json_column_mapping = {}
        set_tenant_map({'tomcat': 'NC'})
Beispiel #8
0
 def setUp(self):
     self.reg = Registry()
     self.__work_zone_dir = tempfile.TemporaryDirectory()
     self.reg.settings = {
         'extract.work_zone_base_dir': '/tmp/work_zone',
         'pickup.gatekeeper.t1': '/t/acb',
         'pickup.gatekeeper.t2': '/a/df',
         'pickup.gatekeeper.y': '/a/c',
         'pickup.sftp.hostname': 'hostname.local.net',
         'pickup.sftp.user': '******',
         'pickup.sftp.private_key_file': '/home/users/myUser/.ssh/id_rsa',
         'extract.available_grades': '3,4,5,6,7,8,11'
     }
     cache_opts = {
         'cache.type': 'memory',
         'cache.regions':
         'public.data,public.filtered_data,public.shortlived'
     }
     CacheManager(**parse_cache_config_options(cache_opts))
     # Set up user context
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(registry=self.reg,
                                   request=self.__request,
                                   hook_zca=False)
     defined_roles = [(Allow, RolesConstants.SAR_EXTRACTS, ('view',
                                                            'logout'))]
     edauth.set_roles(defined_roles)
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS])
     self.__config.testing_securitypolicy(dummy_session.get_user())
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions':
            'public.data,public.filtered_data,public.shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))
        self.__request = DummyRequest()
        # Must set hook_zca to false to work with uniittest_with_sqlite
        reg = Registry()
        reg.settings = {}
        reg.settings = {
            'extract.available_grades': '3,4,5,6,7,8,9,11',
            'hpz.file_upload_base_url': 'http://somehost:82/files',
            'extract.item_level_base_dir': '/opt/edware/item_level'
        }
        self.__config = testing.setUp(registry=reg,
                                      request=self.__request,
                                      hook_zca=False)
        self.__tenant_name = get_unittest_tenant_name()

        defined_roles = [(Allow, RolesConstants.ITEM_LEVEL_EXTRACTS,
                          ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        set_tenant_map({get_unittest_tenant_name(): 'NC'})
        # Set up context security
        dummy_session = create_test_session(
            [RolesConstants.ITEM_LEVEL_EXTRACTS])
        self.__config.testing_securitypolicy(dummy_session.get_user())
        # celery settings for UT
        settings = {'extract.celery.CELERY_ALWAYS_EAGER': True}
        setup_celery(settings)
        # for UT purposes
        smarter.extracts.format.json_column_mapping = {}
        set_tenant_map({'tomcat': 'NC'})
 def setUp(self):
     self.reg = Registry()
     self.reg.settings = {
         'extract.work_zone_base_dir': '/tmp/work_zone',
         'pickup.gatekeeper.t1': '/t/acb',
         'pickup.gatekeeper.t2': '/a/df',
         'pickup.gatekeeper.y': '/a/c',
         'pickup.sftp.hostname': 'hostname.local.net',
         'pickup.sftp.user': '******',
         'pickup.sftp.private_key_file': '/home/users/myUser/.ssh/id_rsa'
     }
     # Set up user context
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(registry=self.reg,
                                   request=self.__request,
                                   hook_zca=False)
     defined_roles = [(Allow, RolesConstants.SAR_EXTRACTS, ('view',
                                                            'logout'))]
     edauth.set_roles(defined_roles)
     # Set up context security
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS])
     dummy_session.set_user_context([
         RoleRelation(RolesConstants.SAR_EXTRACTS,
                      get_unittest_tenant_name(), "NC", "228", "242")
     ])
     self.__config.testing_securitypolicy(dummy_session)
Beispiel #11
0
 def setUp(self):
     self.reg = Registry()
     self.__temp_dir = tempfile.TemporaryDirectory()
     self.__work_zone_dir = os.path.join(self.__temp_dir.name, 'work_zone')
     self.__raw_data_base_dir = os.path.join(self.__temp_dir.name, 'raw_data')
     self.__item_level_base_dir = os.path.join(self.__temp_dir.name, 'item_level')
     self.reg.settings = {'extract.work_zone_base_dir': self.__work_zone_dir,
                          'hpz.file_upload_base_url': 'http://somehost:82/files',
                          'extract.available_grades': '3,4,5,6,7,8,11',
                          'extract.raw_data_base_dir': self.__raw_data_base_dir,
                          'extract.item_level_base_dir': self.__item_level_base_dir}
     settings = {'extract.celery.CELERY_ALWAYS_EAGER': True}
     setup_celery(settings)
     cache_opts = {
         'cache.type': 'memory',
         'cache.regions': 'public.data,public.filtered_data,public.shortlived'
     }
     CacheManager(**parse_cache_config_options(cache_opts))
     # Set up user context
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(registry=self.reg, request=self.__request, hook_zca=False)
     defined_roles = [(Allow, RolesConstants.SAR_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.AUDIT_XML_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS, RolesConstants.AUDIT_XML_EXTRACTS, RolesConstants.ITEM_LEVEL_EXTRACTS])
     self.__config.testing_securitypolicy(dummy_session.get_user())
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
Beispiel #12
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     reg = Registry()
     self.__request.registry = reg
     self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
     dummy_session = create_test_session(['SUPER_USER'], uid='272', tenant='cat')
     self.__config.testing_securitypolicy(dummy_session)
    def test_expired_session(self):
        # expired sessions return empty roles
        current_datetime = datetime.now() + timedelta(seconds=-30)
        # Prepare session
        session = create_test_session(roles=['TEACHER', 'STAFF'], uid='linda.kim', full_name='Linda Kim', expiration=current_datetime, last_access=current_datetime, save_to_backend=True)

        roles = session_check(session.get_session_id(), None)
        self.assertEquals(roles, [])
 def test_session_with_role_returned(self):
     # Prepare session
     session = create_test_session(roles=['TEACHER', 'STAFF'], uid='linda.kim', full_name='Linda Kim', save_to_backend=True)
     defined_roles = [(Allow, 'TEACHER', ('view', 'logout')), (Allow, 'STAFF', ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     # Set up context security
     session.set_user_context([RoleRelation("TEACHER", get_unittest_tenant_name(), "NC", "228", "242"),
                               RoleRelation("STAFF", get_unittest_tenant_name(), "NC", "228", "242")])
     roles = session_check(session.get_session_id(), None)
     self.assertIn("TEACHER", roles)
     self.assertIn("STAFF", roles)
Beispiel #15
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     defined_roles = [(Allow, 'STATE_EDUCATION_ADMINISTRATOR_1', ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     # Set up context security
     dummy_session = create_test_session(['STATE_EDUCATION_ADMINISTRATOR_1'])
     dummy_session.set_user_context([RoleRelation("STATE_EDUCATION_ADMINISTRATOR_1", get_unittest_tenant_name(), "NC", "228", "242")])
     self.__config.testing_securitypolicy(dummy_session)
     set_default_min_cell_size(0)
Beispiel #16
0
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        # Must set hook_zca to false to work with unittest_with_sqlite
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        dummy_session = create_test_session(['TEACHER'], uid='272')
        self.__config.testing_securitypolicy(dummy_session)
Beispiel #17
0
 def test_login_redirected_due_to_no_role(self):
     # set up session data
     session = create_test_session(roles=['NONE'],
                                   uid='linda.kim',
                                   full_name='Linda Kim',
                                   idpSessionIndex='123',
                                   save_to_backend=True)
     self.__config.testing_securitypolicy(session.get_session_id(),
                                          ['NONE'])
     self.__request.url = 'http://example.com/dummy/page'
     http = login(self.__request)
     self.assertIsInstance(http, HTTPForbidden)
Beispiel #18
0
 def test_login_with_no_existing_session(self):
     session = create_test_session(roles=['TEACHER'],
                                   uid='linda.kim',
                                   full_name='Linda Kim',
                                   idpSessionIndex='123',
                                   name_id='abc',
                                   save_to_backend=True)
     self.__config.testing_securitypolicy(session.get_session_id(),
                                          ['TEACHER'])
     self.__request.url = 'http://example.com/dummy/page'
     http = login(self.__request)
     self.assertIsInstance(http, HTTPForbidden)
Beispiel #19
0
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        # Must set hook_zca to false to work with unittest_with_sqlite
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        dummy_session = create_test_session(['TEACHER'], uid='272')
        self.__config.testing_securitypolicy(dummy_session)
Beispiel #20
0
 def test_state_level(self):
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context([RoleRelation(RolesConstants.PII, get_unittest_tenant_name(), 'NC', None, None),
                                     RoleRelation(RolesConstants.SRS_EXTRACTS, get_unittest_tenant_name(), 'NC', None, None),
                                     RoleRelation(RolesConstants.SRC_EXTRACTS, get_unittest_tenant_name(), 'NC', None, None),
                                     RoleRelation(RolesConstants.AUDIT_XML_EXTRACTS, None, None, None, None)])
     # For Context Security, we need to save the user object
     self.__config.testing_securitypolicy(dummy_session.get_user())
     context = get_current_context({'stateCode': 'NC', 'districtId': '229', 'schoolId': '242'})
     self.assertTrue(context['pii']['all'])
     self.assertTrue(context['srs_extracts']['all'])
     self.assertTrue(context['src_extracts']['all'])
     self.assertTrue(context['audit_xml_extracts']['all'])
Beispiel #21
0
    def setUp(self):
        reg = Registry()
        reg.settings = {EDWARE_PUBLIC_SECRET: SECRET}
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.data,public.filtered_data,public.shortlived,public.very_shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
        dummy_session = create_test_session(['SUPER_USER'], uid='272', tenant='cat')
        self.__config.testing_securitypolicy(dummy_session)
Beispiel #22
0
    def setUp(self):
        cache_opts = {'cache.type': 'memory', 'cache.regions': 'public.data'}
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        # Must set hook_zca to false to work with unittest_with_sqlite
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        set_tenant_map({get_unittest_tenant_name(): 'NC'})
        # Set up context security
        dummy_session = create_test_session([RolesConstants.PII])
        self.__config.testing_securitypolicy(dummy_session.get_user())
Beispiel #23
0
 def setUp(self):
     defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout')),
                      (Allow, RolesConstants.SAR_EXTRACTS, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     self.tenant = get_unittest_tenant_name()
     set_tenant_map({self.tenant: "NC"})
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context([RoleRelation(RolesConstants.PII, get_unittest_tenant_name(), "NC", "228", "242"),
                                     RoleRelation(RolesConstants.SAR_EXTRACTS, get_unittest_tenant_name(), "NC", "228", "242")])
     self.user = dummy_session.get_user()
     self.__request = DummyRequest()
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__config.testing_securitypolicy(self.user)
    def test_expired_session(self):
        # expired sessions return empty roles
        current_datetime = datetime.now() + timedelta(seconds=-30)
        # Prepare session
        session = create_test_session(roles=['TEACHER', 'STAFF'],
                                      uid='linda.kim',
                                      full_name='Linda Kim',
                                      expiration=current_datetime,
                                      last_access=current_datetime,
                                      save_to_backend=True)

        roles = session_check(session.get_session_id(), None)
        self.assertEquals(roles, [])
Beispiel #25
0
 def setUp(self):
     self.__request = DummyRequest()
     reg = Registry()
     reg.settings = {}
     reg.settings['cache.expire'] = 10
     reg.settings['cache.regions'] = 'session'
     reg.settings['cache.type'] = 'memory'
     self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
     defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
     # Set up context security
     dummy_session = create_test_session([RolesConstants.PII])
     self.__config.testing_securitypolicy(dummy_session.get_user())
Beispiel #26
0
    def test_add_context_with_tenant(self):
        dummy_session = create_test_session([RolesConstants.PII])
        dummy_session.set_user_context([RoleRelation(RolesConstants.PII, self.tenant, None, None, None)])
        self.user = dummy_session.get_user()
        self.__request = DummyRequest()
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        self.__config.testing_securitypolicy(self.user)

        with UnittestEdcoreDBConnection() as connection:
            fact = connection.get_table(Constants.FACT_ASMT_OUTCOME_VW)
            query = select([fact.c.state_code], from_obj=[fact])
            pii = PII(connection, RolesConstants.PII)
            query = pii.add_context(get_unittest_tenant_name(), self.user, query)
            result = connection.get_result(query)
            self.assertEqual(1228, len(result))
Beispiel #27
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     defined_roles = [(Allow, 'STATE_EDUCATION_ADMINISTRATOR_1',
                       ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     # Set up context security
     dummy_session = create_test_session(
         ['STATE_EDUCATION_ADMINISTRATOR_1'])
     dummy_session.set_user_context([
         RoleRelation("STATE_EDUCATION_ADMINISTRATOR_1",
                      get_unittest_tenant_name(), "NC", "228", "242")
     ])
     self.__config.testing_securitypolicy(dummy_session)
     set_default_min_cell_size(0)
 def setUp(self):
     self.__request = DummyRequest()
     reg = Registry()
     reg.settings = {}
     reg.settings['cache.expire'] = 10
     reg.settings['cache.regions'] = 'session'
     reg.settings['cache.type'] = 'memory'
     self.__config = testing.setUp(registry=reg,
                                   request=self.__request,
                                   hook_zca=False)
     defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
     # Set up context security
     dummy_session = create_test_session([RolesConstants.PII])
     self.__config.testing_securitypolicy(dummy_session.get_user())
    def test_logout_with_existing_session(self):
        # set up session data
        session = create_test_session(roles=['TEACHER'], uid='linda.kim', full_name='Linda Kim', idpSessionIndex='123', name_id='abc', save_to_backend=True)

        self.__config.testing_securitypolicy(session.get_session_id(), ['TEACHER'])
        http = logout(self.__request)

        actual_url = urlparse(http.location)
        expected_url = urlparse(self.registry.settings['auth.saml.idp_server_logout_url'])

        self.assertEquals(actual_url.scheme, expected_url.scheme)
        self.assertEquals(actual_url.netloc, actual_url.netloc)

        queries = urllib.parse.parse_qs(actual_url.query)
        self.assertTrue(len(queries) == 1)
        self.assertIsNotNone(queries['SAMLRequest'])
    def test_add_context_without_tenant(self):
        dummy_session = create_test_session([RolesConstants.PII])
        dummy_session.set_user_context(
            [RoleRelation(RolesConstants.PII, None, None, None, None)])
        self.user = dummy_session.get_user()
        self.__request = DummyRequest()
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        self.__config.testing_securitypolicy(self.user)

        with UnittestEdcoreDBConnection() as connection:
            fact = connection.get_table(Constants.FACT_ASMT_OUTCOME_VW)
            query = select([fact.c.state_code], from_obj=[fact])
            pii = PII(connection, RolesConstants.PII)
            query = pii.add_context(self.tenant, self.user, query)
            result = connection.get_result(query)
            self.assertEqual(1228, len(result))
Beispiel #31
0
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.data,public.filtered_data,public.shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        # Must set hook_zca to false to work with unittest_with_sqlite
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        set_tenant_map({get_unittest_tenant_name(): 'NC'})
        # Set up context security
        dummy_session = create_test_session([RolesConstants.PII])
        self.__config.testing_securitypolicy(dummy_session.get_user())
Beispiel #32
0
 def test_add_context_with_state_level(self):
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context([RoleRelation(RolesConstants.PII, self.tenant, 'NC', None, None)])
     self.user = dummy_session.get_user()
     self.__request = DummyRequest()
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__config.testing_securitypolicy(self.user)
     # Checks that the query has applied where clause
     with UnittestEdcoreDBConnection() as connection:
         fact = connection.get_table(Constants.FACT_ASMT_OUTCOME_VW)
         query = select([fact.c.student_id], from_obj=[fact])
         pii = PII(connection, RolesConstants.PII)
         query = pii.add_context(get_unittest_tenant_name(), self.user, query)
         self.assertIsNotNone(query._whereclause)
         result = connection.get_result(query)
         self.assertEqual(len(result), 1228)
 def test_add_context_with_district_level(self):
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context(
         [RoleRelation(RolesConstants.PII, self.tenant, 'NC', '228', None)])
     self.user = dummy_session.get_user()
     self.__request = DummyRequest()
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__config.testing_securitypolicy(self.user)
     # Checks that the query has applied where clause
     with UnittestEdcoreDBConnection() as connection:
         fact = connection.get_table(Constants.FACT_ASMT_OUTCOME_VW)
         query = select([fact.c.state_code], from_obj=[fact])
         pii = PII(connection, RolesConstants.PII)
         query = pii.add_context(get_unittest_tenant_name(), self.user,
                                 query)
         result = connection.get_result(query)
         self.assertEqual(344, len(result))
Beispiel #34
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with uniittest_with_sqlite
     reg = Registry()
     reg.settings = {}
     self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
     self.__tenant_name = get_unittest_tenant_name()
     defined_roles = [(Allow, RolesConstants.SAR_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     set_tenant_map({get_unittest_tenant_name(): 'NC'})
     # Set up context security
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS])
     dummy_session.set_user_context([RoleRelation(RolesConstants.SAR_EXTRACTS, get_unittest_tenant_name(), "NC", None, None),
                                     RoleRelation(RolesConstants.AUDIT_XML_EXTRACTS, get_unittest_tenant_name(), "NC", None, None),
                                     RoleRelation(RolesConstants.ITEM_LEVEL_EXTRACTS, get_unittest_tenant_name(), "NC", None, None)])
     self.__config.testing_securitypolicy(dummy_session.get_user())
Beispiel #35
0
    def test_add_context_without_tenant(self):
        dummy_session = create_test_session(
            [RolesConstants.SRS_EXTRACTS, RolesConstants.SRC_EXTRACTS])
        dummy_session.set_user_context([
            RoleRelation(RolesConstants.SRS_EXTRACTS, None, None, None, None),
            RoleRelation(RolesConstants.SRC_EXTRACTS, None, None, None, None)
        ])
        self.user = dummy_session.get_user()
        self.__request = DummyRequest()
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        self.__config.testing_securitypolicy(self.user)

        with UnittestEdcoreDBConnection() as connection:
            dim_student = connection.get_table(Constants.DIM_STUDENT)
            query = select([dim_student.c.student_id], from_obj=[dim_student])
            state_level = StateLevel(connection, RolesConstants.SRS_EXTRACTS)
            query = state_level.add_context(self.tenant, self.user, query)
            self.assertIsNone(query._whereclause)
 def test_session_with_role_returned(self):
     # Prepare session
     session = create_test_session(roles=['TEACHER', 'STAFF'],
                                   uid='linda.kim',
                                   full_name='Linda Kim',
                                   save_to_backend=True)
     defined_roles = [(Allow, 'TEACHER', ('view', 'logout')),
                      (Allow, 'STAFF', ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     # Set up context security
     session.set_user_context([
         RoleRelation("TEACHER", get_unittest_tenant_name(), "NC", "228",
                      "242"),
         RoleRelation("STAFF", get_unittest_tenant_name(), "NC", "228",
                      "242")
     ])
     roles = session_check(session.get_session_id(), None)
     self.assertIn("TEACHER", roles)
     self.assertIn("STAFF", roles)
    def setUp(self):
        reg = Registry()
        reg.settings = {EDWARE_PUBLIC_SECRET: SECRET}
        cache_opts = {
            'cache.type':
            'memory',
            'cache.regions':
            'public.data,public.filtered_data,public.shortlived,public.very_shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        self.__config = testing.setUp(registry=reg,
                                      request=self.__request,
                                      hook_zca=False)
        dummy_session = create_test_session(['SUPER_USER'],
                                            uid='272',
                                            tenant='cat')
        self.__config.testing_securitypolicy(dummy_session)
Beispiel #38
0
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.data,public.filtered_data,public.shortlived,public.very_shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        self.__tenant_name = get_unittest_tenant_name()
        set_tenant_map({self.__tenant_name: "NC"})
        # Must set hook_zca to false to work with unittest_with_sqlite.
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        defined_roles = [(Allow, 'PII', ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        # Set up context security
        dummy_session = create_test_session(['PII'])
        dummy_session.set_user_context([RoleRelation("PII", get_unittest_tenant_name(), "NC", "228", None)])
        self.__config.testing_securitypolicy(dummy_session.get_user())
        set_default_min_cell_size(0)
Beispiel #39
0
 def setUp(self):
     self.reg = Registry()
     self.reg.settings = {'extract.work_zone_base_dir': '/tmp/work_zone',
                          'pickup.gatekeeper.t1': '/t/acb',
                          'pickup.gatekeeper.t2': '/a/df',
                          'pickup.gatekeeper.y': '/a/c',
                          'pickup.sftp.hostname': 'hostname.local.net',
                          'pickup.sftp.user': '******',
                          'pickup.sftp.private_key_file': '/home/users/myUser/.ssh/id_rsa'}
     # Set up user context
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(registry=self.reg, request=self.__request, hook_zca=False)
     defined_roles = [(Allow, RolesConstants.SAR_EXTRACTS, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     # Set up context security
     dummy_session = create_test_session([RolesConstants.SAR_EXTRACTS])
     dummy_session.set_user_context([RoleRelation(RolesConstants.SAR_EXTRACTS, get_unittest_tenant_name(), "NC", "228", "242")])
     self.__config.testing_securitypolicy(dummy_session)
Beispiel #40
0
 def setUp(self):
     self.__request = DummyRequest()
     # Must set hook_zca to false to work with unittest_with_sqlite
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__tenant_name = get_unittest_tenant_name()
     set_tenant_map({self.__tenant_name: "NC"})
     defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout')),
                      (Allow, RolesConstants.SRS_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.SRC_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.AUDIT_XML_EXTRACTS, ('view', 'logout')),
                      (Allow, RolesConstants.ITEM_LEVEL_EXTRACTS, ('view', 'logout'))]
     edauth.set_roles(defined_roles)
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context([RoleRelation(RolesConstants.PII, get_unittest_tenant_name(), "NC", "228", "242"),
                                     RoleRelation(RolesConstants.PII, get_unittest_tenant_name(), "NC", "228", "245"),
                                     RoleRelation(RolesConstants.SRS_EXTRACTS, get_unittest_tenant_name(), 'NC', None, None),
                                     RoleRelation(RolesConstants.SRC_EXTRACTS, get_unittest_tenant_name(), 'NC', None, None),
                                     RoleRelation(RolesConstants.AUDIT_XML_EXTRACTS, get_unittest_tenant_name(), 'NC', None, None)])
     # For Context Security, we need to save the user object
     self.__config.testing_securitypolicy(dummy_session.get_user())
 def test_consortium_level(self):
     dummy_session = create_test_session([RolesConstants.PII])
     dummy_session.set_user_context([
         RoleRelation(RolesConstants.PII, None, None, None, None),
         RoleRelation(RolesConstants.SRS_EXTRACTS, None, None, None, None),
         RoleRelation(RolesConstants.SRC_EXTRACTS, None, None, None, None),
         RoleRelation(RolesConstants.AUDIT_XML_EXTRACTS, None, None, None,
                      None)
     ])
     # For Context Security, we need to save the user object
     self.__config.testing_securitypolicy(dummy_session.get_user())
     context = get_current_context({
         'stateCode': 'NC',
         'districtId': '229',
         'schoolId': '242'
     })
     self.assertTrue(context['pii']['all'])
     self.assertTrue(context['srs_extracts']['all'])
     self.assertTrue(context['src_extracts']['all'])
     self.assertFalse(context['item_extracts']['all'])
     self.assertTrue(context['audit_xml_extracts']['all'])
Beispiel #42
0
 def setUp(self):
     defined_roles = [
         (Allow, RolesConstants.SRS_EXTRACTS, ('view', 'logout')),
         (Allow, RolesConstants.SRC_EXTRACTS, ('view', 'logout'))
     ]
     self.role_constants = [
         RolesConstants.SRS_EXTRACTS, RolesConstants.SRC_EXTRACTS
     ]
     edauth.set_roles(defined_roles)
     self.tenant = get_unittest_tenant_name()
     set_tenant_map({self.tenant: 'ES'})
     dummy_session = create_test_session(
         [RolesConstants.SRS_EXTRACTS, RolesConstants.SRC_EXTRACTS])
     dummy_session.set_user_context([
         RoleRelation(RolesConstants.SRS_EXTRACTS, self.tenant, None, None,
                      None),
         RoleRelation(RolesConstants.SRC_EXTRACTS, self.tenant, None, None,
                      None)
     ])
     self.user = dummy_session.get_user()
     self.__request = DummyRequest()
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__config.testing_securitypolicy(self.user)
Beispiel #43
0
 def test_add_context_with_state_level(self):
     dummy_session = create_test_session(
         [RolesConstants.SRS_EXTRACTS, RolesConstants.SRC_EXTRACTS])
     dummy_session.set_user_context([
         RoleRelation(RolesConstants.SRS_EXTRACTS, self.tenant, 'ZZ', None,
                      None),
         RoleRelation(RolesConstants.SRC_EXTRACTS, self.tenant, 'ZZ', None,
                      None)
     ])
     self.user = dummy_session.get_user()
     self.__request = DummyRequest()
     self.__config = testing.setUp(request=self.__request, hook_zca=False)
     self.__config.testing_securitypolicy(self.user)
     # Checks that the query has applied where clause
     with UnittestEdcoreDBConnection() as connection:
         fact = connection.get_table(Constants.FACT_ASMT_OUTCOME_VW)
         query = select([fact.c.student_id], from_obj=[fact])
         state_level = StateLevel(connection, RolesConstants.SRS_EXTRACTS)
         query = state_level.add_context(get_unittest_tenant_name(),
                                         self.user, query)
         self.assertIsNotNone(query._whereclause)
         result = connection.get_result(query)
         self.assertEqual(len(result), 0)
Beispiel #44
0
    def test_logout_with_existing_session(self):
        # set up session data
        session = create_test_session(roles=['TEACHER'],
                                      uid='linda.kim',
                                      full_name='Linda Kim',
                                      idpSessionIndex='123',
                                      name_id='abc',
                                      save_to_backend=True)

        self.__config.testing_securitypolicy(session.get_session_id(),
                                             ['TEACHER'])
        http = logout(self.__request)

        actual_url = urlparse(http.location)
        expected_url = urlparse(
            self.registry.settings['auth.saml.idp_server_logout_url'])

        self.assertEquals(actual_url.scheme, expected_url.scheme)
        self.assertEquals(actual_url.netloc, actual_url.netloc)

        queries = urllib.parse.parse_qs(actual_url.query)
        self.assertTrue(len(queries) == 1)
        self.assertIsNotNone(queries['SAMLRequest'])
Beispiel #45
0
    def setUp(self):
        cache_opts = {
            'cache.type':
            'memory',
            'cache.regions':
            'public.data,public.filtered_data,public.shortlived,public.very_shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))

        self.__request = DummyRequest()
        self.__tenant_name = get_unittest_tenant_name()
        set_tenant_map({self.__tenant_name: "NC"})
        # Must set hook_zca to false to work with unittest_with_sqlite.
        self.__config = testing.setUp(request=self.__request, hook_zca=False)
        defined_roles = [(Allow, 'PII', ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        # Set up context security
        dummy_session = create_test_session(['PII'])
        dummy_session.set_user_context([
            RoleRelation("PII", get_unittest_tenant_name(), "NC", "228", None)
        ])
        self.__config.testing_securitypolicy(dummy_session.get_user())
        set_default_min_cell_size(0)
    def setUp(self):
        cache_opts = {
            'cache.type': 'memory',
            'cache.regions': 'public.shortlived'
        }
        CacheManager(**parse_cache_config_options(cache_opts))
        self.__request = DummyRequest()
        # Must set hook_zca to false to work with uniittest_with_sqlite
        reg = Registry()
        # Set up defined roles
        self.__tenant_name = get_unittest_tenant_name()
        set_tenant_map({self.__tenant_name: "NC"})
        self.__temp_dir = tempfile.mkdtemp()
        reg.settings = {}
        reg.settings['pdf.report_base_dir'] = self.__temp_dir
        self.__config = testing.setUp(registry=reg,
                                      request=self.__request,
                                      hook_zca=False)

        defined_roles = [(Allow, RolesConstants.PII, ('view', 'logout'))]
        edauth.set_roles(defined_roles)
        # Set up context security
        dummy_session = create_test_session([RolesConstants.PII])
        dummy_session.set_user_context([
            RoleRelation(RolesConstants.PII, self.__tenant_name, 'NC', '228',
                         '242'),
            RoleRelation(RolesConstants.PII, self.__tenant_name, 'NC', '229',
                         '939')
        ])
        self.__config.testing_securitypolicy(dummy_session.get_user())

        # celery settings for UT
        settings = {'services.celery.CELERY_ALWAYS_EAGER': True}
        self.__request.matchdict[Constants.REPORT] = 'indivStudentReport.html'
        self.__request.cookies = {'edware': '123'}
        setup_celery(settings)
    def test_authenticated_userid(self):
        # set up session
        session = create_test_session(roles=["TEACHER"],
                                      full_name='Linda Kim',
                                      uid='linda.kim',
                                      idpSessionIndex='123',
                                      first_name='Linda',
                                      last_name='Kim',
                                      save_to_backend=True)

        self.__config.testing_securitypolicy(session.get_session_id(),
                                             ['TEACHER'])

        user = self.__policy.authenticated_userid(self.__request)

        self.assertIsInstance(user, User)
        self.assertEqual(
            user.get_name(), {
                'name': {
                    'fullName': 'Linda Kim',
                    'firstName': 'Linda',
                    'lastName': 'Kim'
                }
            })
 def test_login_with_no_existing_session(self):
     session = create_test_session(roles=['TEACHER'], uid='linda.kim', full_name='Linda Kim', idpSessionIndex='123', name_id='abc', save_to_backend=True)
     self.__config.testing_securitypolicy(session.get_session_id(), ['TEACHER'])
     self.__request.url = 'http://example.com/dummy/page'
     http = login(self.__request)
     self.assertIsInstance(http, HTTPForbidden)