def test_store_token_from_stdin_input(self): cmd_args = ["--store", "--provider", "duck", "-c", self.test_dir] # monkey patch for testing utils.read_input = lambda _: "1234567890ABC" # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") self.assertEqual(result.get('process_message'), "Auth info stored.", "Status message should be an 'Auth info stored.'") # load cmd_args = [ "--provider", "duck", "-n", "noipy.duckdns.org", "-c", self.test_dir, self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error loading auth info")
def test_store_pass_from_stdin_input(self): cmd_args = [ "-u", "username", "--store", "--provider", "noip", "-c", self.test_dir ] # monkey patch for testing getpass.getpass = lambda _: "password" # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") self.assertEqual(result.get('process_message'), "Auth info stored.", "Status message should be an 'Auth info stored.'") # load cmd_args = [ "--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error loading auth info")
def test_store_pass_from_stdin_input(self): cmd_args = ["-u", "username", "--store", "--provider", "noip", "-c", self.test_dir] # monkey patch for testing getpass.getpass = lambda _: "password" # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") self.assertEqual(result.get('process_message'), "Auth info stored.", "Status message should be an 'Auth info stored.'") # load cmd_args = ["--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error loading auth info")
def test_store_token_from_stdin_input(self): cmd_args = ["--store", "--provider", "duck", "-c", self.test_dir] # monkey patch for testing utils.get_input = lambda _: "1234567890ABC" # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") self.assertEqual(result.get('process_message'), "Auth info stored.", "Status message should be an 'Auth info stored.'") # load cmd_args = ["--provider", "duck", "-n", "noipy.duckdns.org", "-c", self.test_dir, self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error loading auth info")
def test_generic_plugin(self): cmd_args = ['--provider', 'generic'] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_NOK, "An error should be flagged when --provider is " "'generic' and --url is not specified") cmd_args = ['-u', 'username', '-p', 'password', '--url', 'https://dynupdate.no-ip.com/nic/update', '--provider', 'generic', '-n', 'noipy.no-ip.org', self.test_ip] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Update with 'No-IP' using generic provider failed.") self.assertTrue(status_message.startswith("ERROR:"), "Status message should be an 'ERROR'")
def test_changed_ip(self): cmd_args = ['-u', 'username', '-p', 'password', '--url', 'https://dynupdate.no-ip.com/nic/update', '--provider', 'generic', '-n', 'localhost', '127.0.0.2'] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Update with changed IP failed.") self.assertTrue(status_message.startswith("ERROR:"), "Status message should be an 'ERROR'")
def test_store_and_load_auth_info(self): cmd_args = ['--store', '-u', 'username', '-p', 'password', '--provider', 'noip', '-c', self.test_dir, self.test_ip] # store args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Error storing auth info") self.assertTrue(status_message == "Auth info stored.", "Status message should be an 'Auth info stored.'") # load cmd_args = ['--provider', 'noip', '-n', 'noipy.no-ip.org', '-c', self.test_dir, self.test_ip] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Error loading auth info")
def test_duckdns_plugin(self): cmd_args = ['-u', '1234567890ABC', '--provider', 'duck', '-n', 'noipy.duckdns.org', self.test_ip] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Update with 'DuckDNS' provider failed.") self.assertTrue(status_message.startswith("ERROR:"), "Status message should be an 'ERROR'")
def test_dyndns_plugin(self): cmd_args = ['-u', 'test', '-p', 'test', '--provider', 'dyn', '-n', 'test.dyndns.org', self.test_ip] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Update with 'DynDNS' provider failed.") self.assertTrue(status_message.startswith("SUCCESS:"), "Status message should be 'SUCCESS'")
def test_cmd_line_no_args(self): cmd_args = [] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "Execution without args failed.") self.assertTrue(result.get('process_message').startswith( "Warning: The hostname to be updated must be provided."), "Status message should start with 'Warning: " "The hostname to be updated must be provided.'")
def test_noip_plugin(self): cmd_args = ['-u', 'username', '-p', 'password', '--provider', 'noip', '-n', 'noipy.no-ip.org', self.test_ip] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_OK, "Update with 'No-IP' provider failed.") self.assertTrue(status_message.startswith("ERROR:"), "Status message should be an 'ERROR'")
def test_update_without_authinfo(self): cmd_args = ["--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "Update without auth info failed.") self.assertTrue(result.get('process_message').startswith( "No stored auth information found for provider:"), "Status message should be 'No stored auth information found " "for provider: ...'")
def test_unchanged_ip(self): cmd_args = ["-u", "username", "-p", "password", "--url", "https://dynupdate.no-ip.com/nic/update", "--provider", "generic", "-n", "localhost", "127.0.0.1"] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with unchanged IP failed.") self.assertEqual(result.get('process_message'), "No update required.", "Status message should be 'No update required'.")
def test_generic_plugin_malformed_url(self): cmd_args = ['-u', 'username', '-p', 'password', '--url', 'abced', '--provider', 'generic', '-n', 'noipy.no-ip.org', self.test_ip] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_NOK, "An error should be flagged when --provider is " "'generic' and URL is malformed.") self.assertTrue(status_message == "Malformed URL.", "Status message should be an 'Malformed URL.'")
def test_noip_plugin(self): cmd_args = ["-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org", self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with 'No-IP' provider failed.") self.assertEqual(result.get('response_code'), 200, "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_duckdns_plugin(self): cmd_args = ["-u", "1234567890ABC", "--provider", "duck", "-n", "noipy.duckdns.org", self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with 'DuckDNS' provider failed.") self.assertEqual(result.get('response_code'), 200, "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_cmd_line_no_args(self): cmd_args = [] args = self.parser.parse_args(cmd_args) result, status_message = main.execute_update(args) self.assertTrue(result == main.EXECUTION_RESULT_NOK, "Execution without args failed.") self.assertTrue( status_message.startswith("Warning: The hostname to be updated " "must be provided."), "Status message should start with 'Warning: The hostname to be " "updated must be provided.'")
def test_cmd_line_no_args(self): cmd_args = [] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "Execution without args failed.") self.assertTrue( result.get('process_message').startswith( "Warning: The hostname to be updated must be provided."), "Status message should start with 'Warning: " "The hostname to be updated must be provided.'")
def test_store_and_perform_update(self): cmd_args = ["--store", "-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip] # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") self.assertEqual(result.get('response_code'), 200, "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_generic_plugin_malformed_url(self): cmd_args = ["-u", "username", "-p", "password", "--url", "abced", "--provider", "generic", "-n", "noipy.no-ip.org", self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "An error should be flagged when --provider is " "'generic' and URL is malformed.") self.assertEqual(result.get('process_message'), "Malformed URL.", "Status message should be an 'Malformed URL.'")
def test_unchanged_ip(self): cmd_args = [ "-u", "username", "-p", "password", "--url", "https://dynupdate.no-ip.com/nic/update", "--provider", "generic", "-n", "localhost", "127.0.0.1" ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with unchanged IP failed.") self.assertEqual(result.get('process_message'), "No update required.", "Status message should be 'No update required'.")
def test_generic_plugin_without_url(self): cmd_args = ["-u", "username", "-p", "password", "--provider", "generic", "-n", "noipy.no-ip.org", self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "An error should be flagged when --provider is " "'generic' and no URL is provided.") self.assertTrue(result.get('process_message') .startswith("Must use --url"), "Status message should start with 'Must use --url'.")
def test_dyndns_plugin(self): cmd_args = [ "-u", "test", "-p", "test", "--provider", "dyn", "-n", "test.dyndns.org", self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with 'DynDNS' provider failed.") self.assertEqual( result.get('response_code'), 200, "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_generic_plugin_malformed_url(self): cmd_args = [ "-u", "username", "-p", "password", "--url", "abced", "--provider", "generic", "-n", "noipy.no-ip.org", self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual( result.get('exec_result'), main.EXECUTION_RESULT_NOK, "An error should be flagged when --provider is " "'generic' and URL is malformed.") self.assertEqual(result.get('process_message'), "Malformed URL.", "Status message should be an 'Malformed URL.'")
def test_noip_plugin(self): cmd_args = ["-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org", self.test_ip] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with 'No-IP' provider failed.") # noip.com returns either HTTP 200 or 401, # depending on which way the window is blowing self.assertTrue(result.get('response_code') in (200, 401), "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_update_without_authinfo(self): cmd_args = [ "--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "Update without auth info failed.") self.assertTrue( result.get('process_message').startswith( "No stored auth information found for provider:"), "Status message should be 'No stored auth information found " "for provider: ...'")
def test_store_and_perform_update(self): cmd_args = ["--store", "-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip] # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") # noip.com returns either HTTP 200 or 401, # depending on which way the window is blowing self.assertTrue(result.get('response_code') in (200, 401), "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_without_ip(self): cmd_args = ["-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org"] # monkey patch for testing utils.get_ip = lambda: None args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "Update without IP failed.") self.assertTrue(result.get('process_message') .startswith("Unable to get IP address"), "Status message should be 'Unable to get IP address'.")
def test_generic_plugin_without_url(self): cmd_args = [ "-u", "username", "-p", "password", "--provider", "generic", "-n", "noipy.no-ip.org", self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual( result.get('exec_result'), main.EXECUTION_RESULT_NOK, "An error should be flagged when --provider is " "'generic' and no URL is provided.") self.assertTrue( result.get('process_message').startswith("Must use --url"), "Status message should start with 'Must use --url'.")
def test_noip_plugin(self): cmd_args = [ "-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org", self.test_ip ] args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Update with 'No-IP' provider failed.") # noip.com returns either HTTP 200 or 401, # depending on which way the window is blowing self.assertTrue( result.get('response_code') in (200, 401), "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_store_and_perform_update(self): cmd_args = [ "--store", "-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org", "-c", self.test_dir, self.test_ip ] # store args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_OK, "Error storing auth info") # noip.com returns either HTTP 200 or 401, # depending on which way the window is blowing self.assertTrue( result.get('response_code') in (200, 401), "Invalid response code: %s. Should be 200." % result.get('response_code'))
def test_without_ip(self): cmd_args = [ "-u", "username", "-p", "password", "--provider", "noip", "-n", "noipy.no-ip.org" ] # monkey patch for testing utils.get_ip = lambda: None args = self.parser.parse_args(cmd_args) result = main.execute_update(args) self.assertEqual(result.get('exec_result'), main.EXECUTION_RESULT_NOK, "Update without IP failed.") self.assertTrue( result.get('process_message').startswith( "Unable to get IP address"), "Status message should be 'Unable to get IP address'.")
def save_ip(self, noip_config): """ Save IP to the DNS provider :param noip_config: dictonary of settings (provider, username, password, hostname, ip) """ class Arguments: pass args = Arguments() args.store = False try: args.provider = noip_config["provider"] args.usertoken = noip_config["username"] args.password = noip_config["password"] args.hostname = noip_config["hostname"] args.ip = noip_config["ip"] return execute_update(args) except KeyError as error: self._logger.error("Failed to update NOIP provider! (%s)", error) self._logger.debug("NOIP settings: %s", noip_config) return {}