def create_conn_settings(dhis2_conn: Dhis2Connection) -> ConnectionSettings: """ Creates and returns a ConnectionSettings instance for ``dhis2_conn``. """ url = strip_api(dhis2_conn.server_url) conn_settings = ConnectionSettings( domain=dhis2_conn.domain, name=url, url=url, auth_type=BASIC_AUTH, username=dhis2_conn.username, skip_cert_verify=dhis2_conn.skip_cert_verify, notify_addresses_str="") conn_settings.plaintext_password = dhis2_conn.plaintext_password conn_settings.save() return conn_settings
def create_connection_settings(self): if self.connection_settings_id: return # Nothing to do conn = ConnectionSettings( domain=self.domain, name=self.url, url=self.url, auth_type=self.auth_type, username=self.username, skip_cert_verify=self.skip_cert_verify, notify_addresses_str=self.notify_addresses_str or '', ) # Allow ConnectionSettings to encrypt old Repeater passwords: conn.plaintext_password = self.plaintext_password conn.save() self.connection_settings_id = conn.id self.save() return conn
def test_connection_settings_auth_manager(self): connx = ConnectionSettings( domain=DOMAIN, name='Mr. Creosote', url=URL, auth_type=BASIC_AUTH, username=USERNAME, password='', notify_addresses_str=ADMIN, ) connx.plaintext_password = PASSWORD connx.save() try: auth_manager = connx.get_auth_manager() self.assertIsInstance(auth_manager, BasicAuthManager) self.assertEqual(auth_manager.username, USERNAME) self.assertEqual(auth_manager.password, PASSWORD) self.assertNotEqual(auth_manager.password, connx.password) self.assertTrue(connx.password.startswith(f'${ALGO_AES}$')) finally: connx.delete()
def test_password_getter_decrypts(self): cs = ConnectionSettings() cs.plaintext_password = '******' self.assertEqual(cs.plaintext_password, 'secret')
def test_password_setter(self): cs = ConnectionSettings() cs.plaintext_password = '******' self.assertTrue(cs.password.startswith(f'${ALGO_AES}$'))
def test_password_placeholder(self): cs = ConnectionSettings() cs.plaintext_password = PASSWORD_PLACEHOLDER self.assertEqual(cs.password, '')