def test__add_tenant(self): user = User() user._add_tenant('t') self.assertIn('t', user.get_tenants()) user._add_tenant(None) self.assertEqual(1, len(user.get_tenants())) self.assertIn('t', user.get_tenants())
def test__add_tenant(self): user = User() user._add_tenant('t') self.assertIn('t', user.get_tenants()) user._add_tenant(None) self.assertEqual(1, len(user.get_tenants())) self.assertIn('t', user.get_tenants())
def test_empty_user(self): user = User() data = { 'name': { 'fullName': None, 'firstName': None, 'lastName': None }, 'uid': None, 'roles': [], 'stateCode': [], 'tenant': [], 'displayHome': False, 'guid': None } name = user.get_name() self.assertEqual(name, {'name': data['name']}) uid = user.get_uid() self.assertEqual(uid, data['uid']) context = user.get_user_context() self.assertEqual(context, data) roles = user.get_roles() self.assertEqual(roles, data['roles']) tenant = user.get_tenants() self.assertEqual(0, len(tenant)) guid = user.get_guid() self.assertIsNone(guid)
def test_with_default_permission(self): role_rel = [RoleRelation('DEFAULT', 'tenant', 'NY', 'a', '1'), RoleRelation('PII', 'tenant', 'NY', 'a', '1')] user = User() user.set_context(role_rel) roles = user.get_roles() self.assertEqual(2, len(roles)) self.assertIn('DEFAULT', roles) self.assertIn('PII', roles) self.assertEqual(1, len(user.get_tenants()))
def test_tenantless(self): role_rel = [RoleRelation('badrole', None, None, None, None), RoleRelation('PII', 'tenant1', 'NC', 'a', '2')] user = User() user.set_context(role_rel) roles = user.get_roles() self.assertEqual(2, len(roles)) self.assertIn('DEFAULT', roles) self.assertIn('PII', roles) tenants = user.get_tenants() self.assertEqual(3, len(tenants))
def test_default_permission_gets_added(self): role_rel = [RoleRelation('badrole', 'tenant', 'NY', 'a', '1'), RoleRelation('PII', 'tenant', 'NY', 'a', '2'), RoleRelation('badrole2', 'tenant', 'NY', 'b', None)] user = User() user.set_context(role_rel) roles = user.get_roles() self.assertEqual(2, len(roles)) self.assertIn('DEFAULT', roles) self.assertIn('PII', roles) self.assertEqual(1, len(user.get_tenants()))
def test_with_default_permission(self): role_rel = [ RoleRelation('DEFAULT', 'tenant', 'NY', 'a', '1'), RoleRelation('PII', 'tenant', 'NY', 'a', '1') ] user = User() user.set_context(role_rel) roles = user.get_roles() self.assertEqual(2, len(roles)) self.assertIn('DEFAULT', roles) self.assertIn('PII', roles) self.assertEqual(1, len(user.get_tenants()))
def test_tenantless(self): role_rel = [ RoleRelation('badrole', None, None, None, None), RoleRelation('PII', 'tenant1', 'NC', 'a', '2') ] user = User() user.set_context(role_rel) roles = user.get_roles() self.assertEqual(2, len(roles)) self.assertIn('DEFAULT', roles) self.assertIn('PII', roles) tenants = user.get_tenants() self.assertEqual(3, len(tenants))
def test_default_permission_gets_added(self): role_rel = [ RoleRelation('badrole', 'tenant', 'NY', 'a', '1'), RoleRelation('PII', 'tenant', 'NY', 'a', '2'), RoleRelation('badrole2', 'tenant', 'NY', 'b', None) ] user = User() user.set_context(role_rel) roles = user.get_roles() self.assertEqual(2, len(roles)) self.assertIn('DEFAULT', roles) self.assertIn('PII', roles) self.assertEqual(1, len(user.get_tenants()))
def test_empty_user(self): user = User() data = {'name': {'fullName': None, 'firstName': None, 'lastName': None}, 'uid': None, 'roles': [], 'stateCode': [], 'tenant': [], 'displayHome': False, 'guid': None} name = user.get_name() self.assertEqual(name, {'name': data['name']}) uid = user.get_uid() self.assertEqual(uid, data['uid']) context = user.get_user_context() self.assertEqual(context, data) roles = user.get_roles() self.assertEqual(roles, data['roles']) tenant = user.get_tenants() self.assertEqual(0, len(tenant)) guid = user.get_guid() self.assertIsNone(guid)
class Session: ''' Simple class that holds user session information, such as guid, user id, name, roles, and tenant ''' def __init__(self): self.__initialize_session() # leave datetime only this class, not save in session context self.__expiration = None self.__last_access = None # initialize all session values def __initialize_session(self): self.__session = {} self.__user = User() self.__session_id = None self.__session['idpSessionIndex'] = None self.__session['nameId'] = None # serialize to text def get_session_json_context(self): # Get User Info and combined the dictionary combined_context = self.__user.get_user_context() combined_context.update_session(self.__session) return json.dumps(combined_context) def get_session_id(self): return self.__session_id def get_uid(self): return self.__user.get_uid() def get_email(self): return self.__user.get_email() def get_roles(self): return self.__user.get_roles() def get_tenants(self): return self.__user.get_tenants() def get_guid(self): return self.__user.get_guid() def get_name(self): return self.__user.get_name() def get_idp_session_index(self): return self.__session['idpSessionIndex'] def get_name_id(self): return self.__session['nameId'] def get_last_access(self): return self.__last_access def get_expiration(self): return self.__expiration def get_user(self): return self.__user def set_session_id(self, session_id): ''' @param session_id: the session id ''' self.__session_id = session_id def set_uid(self, uid): ''' @param uid: the uid ''' self.__user.set_uid(uid) def set_email(self, email): ''' @param uid: the uid ''' self.__user.set_email(email) def set_user_context(self, context): self.__user.set_context(context) def set_guid(self, guid): ''' @param guid: the user guid to set ''' self.__user.set_guid(guid) def set_fullName(self, fullName): ''' @param fullName: the full name ''' self.__user.set_full_name(fullName) def set_lastName(self, lastName): ''' @param lastName: the last name ''' self.__user.set_last_name(lastName) def set_firstName(self, firstName): ''' @param firstName: the first name ''' self.__user.set_first_name(firstName) def set_idp_session_index(self, index): ''' @param index: the idp session index ''' self.__session['idpSessionIndex'] = index def set_name_id(self, name_id): ''' @param name_id: the name id ''' self.__session['nameId'] = name_id def set_session(self, session): self.__session = session self.__set_user(session) def set_expiration(self, datetime): self.__expiration = datetime def set_last_access(self, datetime): self.__last_access = datetime def __set_user(self, info): self.__user.set_user_info(info)