Beispiel #1
0
def get_ldap_sync_operations(conn: Connection) -> List[LDAPOperation]:
    """Compares local and remote data and returns sync operations."""
    # Retrieve local and remote entries
    local_people = LDAPPerson.get_entries()
    local_groups = LDAPGroup.get_entries()
    remote_people = get_ldap_entries(conn, [LDAPPerson.get_search()])
    remote_groups = get_ldap_entries(conn, [LDAPGroup.get_search()])
    # The people and groups need to be synced separately because they
    #  are matched on their primary key, which is only unique within
    #  people and groups, but not unique if you take those together.
    operations = sync(local_people, remote_people)
    operations += sync(local_groups, remote_groups)
    return operations
Beispiel #2
0
 def test_entry_without_matching_attribute(self):
     change_to = {'uid=test': {'uid': ['test'], 'id': [1]}}
     to_change1 = {'uid=test': {'uid': ['test']}}
     to_change2 = {'uid=test': {'uid': ['test'], 'id': []}}
     operations1 = sync(change_to, to_change1, on='id')
     operations2 = sync(change_to, to_change2, on='id')
     expect = [
         DeleteOperation('uid=test'),
         AddOperation('uid=test', {
             'uid': ['test'],
             'id': [1]
         })
     ]
     self.assertEqual(expect, operations1)
     self.assertEqual(expect, operations2)
Beispiel #3
0
 def test_modify_dn_attribute(self):
     change_to = {'uid=test': {'uid': ['test'], 'id': ['4']}}
     to_change = {'uid=test2': {'uid': ['test2'], 'id': ['4']}}
     operations = sync(change_to, to_change, on='id')
     # ModifyDNOperation should be before ModifyOperation
     self.assertEqual([
         ModifyDNOperation('uid=test2', 'uid=test'),
         ModifyOperation('uid=test', 'uid', ['test'])
     ], operations)
Beispiel #4
0
 def test_modify_list2(self):
     source = {
         'uid=test': {
             'uid': ['test'],
             'name': ['Henk', 'Piet'],
             'id': [4]
         }
     }
     target = {
         'uid=test': {
             'uid': ['test'],
             'name': ['Piet', 'Henk'],
             'id': [4]
         }
     }
     operations = sync(source, target, on='id')
     self.assertEqual([], operations)
Beispiel #5
0
 def test_modify(self):
     change_to = {
         'uid=test': {
             'uid': ['test'],
             'name': ['Piet'],
             'id': ['4']
         }
     }
     to_change = {
         'uid=test': {
             'uid': ['test'],
             'name': ['Henk'],
             'id': ['4']
         }
     }
     operations = sync(change_to, to_change, on='id')
     self.assertEqual([ModifyOperation('uid=test', 'name', ['Piet'])],
                      operations)
Beispiel #6
0
 def login_method(self):
     self.username_text = self.login_ui.username.text()
     self.password_text = self.login_ui.password.text()
     print("username :"******"password :"******"Server is Offline!!")
         self.main_app.login.setVisible(True)
         self.main_app.logout.setVisible(False)
         return
     self.authentication_flag = login_response["success"]
     if (self.authentication_flag == 0):
         print("in if")
         self.main_app.message_box("Wrong Username or Password!!", self.auth_fail_msg_btn)
         self.clear_textedit()
         self.main_app.login.setVisible(True)
         self.main_app.logout.setVisible(False)
     else:
         self.token = login_response["token"]
         print("Token " + str(self.token))
         self.main_app.login_credentials.token = self.token
         self.main_app.storage.update_login_token(self.token)
         self.is_new = login_response["is_new"]
         self.main_app.storage.insert_saved_password(self.username_text, self.password_text)
         print("is_new = ", self.is_new)
         if (self.is_new == 1):  # New Client
             try:
                 notes_dict = requests.get(str(self.main_app.notes_retrieve_url),
                                           headers={"Authorization": "JWT " + self.token}).json()['notes']
             except:
                 self.main_app.message_box("Server is Offline!!")
                 print("Hello")
                 return
             for note in notes_dict:
                 note_dict = {"create_time": datetime.datetime.now().time().isoformat(),
                              "note_text": note["note_text"],
                              "process_name": note["process_name"],
                              "window_title": note["window_title"],
                              "note_hash": note["note_hash"]}
                 note_hash = note["note_hash"]
                 window_title = note["window_title"]
                 process_name = note["process_name"]
                 note_text = note["note_text"]
                 old_note = self.main_app.storage.read_note(note_hash)
                 if (old_note == None):  # No note is present for that hash in local db
                     note = Note(**note_dict)
                     self.main_app.storage.insert_note(note)
                 else:  # Note is present for that hash in local db
                     merged_text = self.main_app.merge(note_text, old_note.note_text)
                     old_note.note_text = merged_text
                     self.main_app.storage.update_note(old_note)
                     self.main_app.storage
                     old_log = self.main_app.storage.read_log(note_hash)
                     if (old_log != None):
                         old_log.note_text = merged_text
                         self.main_app.storage.update_log(old_log)
         print("login successful")
         self.main_app.sync = sync(self.main_app)
         self.main_app.login.setVisible(False)
         self.main_app.logout.setVisible(True)
         self.close()
Beispiel #7
0
 def test_modify_dn(self):
     change_to = {'uid=test': {'id': ['4']}}
     to_change = {'uid=test2': {'id': ['4']}}
     operations = sync(change_to, to_change, on='id')
     self.assertEqual([ModifyDNOperation('uid=test2', 'uid=test')],
                      operations)
Beispiel #8
0
 def test_none(self):
     """No operations need to be performed."""
     source = {'uid=peep': {'uid': ['peep'], 'name': ['Henk'], 'id': [4]}}
     target = {'uid=peep': {'uid': ['peep'], 'name': ['Henk'], 'id': [4]}}
     operations = sync(source, target, on='id')
     self.assertEqual([], operations)
Beispiel #9
0
 def test_modify_empty_missing1(self):
     change_to = {'uid=test': {'uid': ['test'], 'name': [], 'id': ['4']}}
     to_change = {'uid=test': {'uid': ['test'], 'id': ['4']}}
     operations = sync(change_to, to_change, on='id')
     self.assertEqual([], operations)
Beispiel #10
0
 def test_delete(self):
     source = {}
     target = {'uid=test': {'uid': ['test'], 'id': ['4']}}
     operations = sync(source, target, on='id')
     self.assertEqual([DeleteOperation('uid=test')], operations)
Beispiel #11
0
 def test_add(self):
     source = {'uid=test': {'uid': ['test'], 'id': ['4']}}
     target = {}
     operations = sync(source, target, on='id')
     expect = [AddOperation('uid=test', {'uid': ['test'], 'id': ['4']})]
     self.assertEqual(expect, operations)