def test_update_resource_record(self): """ Test update_resource_record functionality """ client = MockRoute53Client() hostname = "www.google.com" value = '127.0.0.1' record = new_resource_record(hostname, value) # Go right case where the value is the same as the in the record updated = update_resource_record(record, value, client=client) self.assertTrue(updated) # Go right case updated = update_resource_record(record, '192.168.1.1', client=client) self.assertTrue(updated) # Test a go wrong case when there's a Route 53 error with patch.object(client, 'change_resource_record_sets') as mocked: mocked.side_effect = RuntimeError("Route 53 Error") with self.assertRaises(Route53Exception): update_resource_record(record, '192.168.1.1', client=client)
def nic_update(): """ Update a dynamic DNS record """ if request.args.get('offline'): return NOT_SUPPORTED # Check for a user agent user_agent = request.user_agent.string if not user_agent: print("WTF") if not user_agent or user_agent in app.config['BAD_USER_AGENTS']: return BAD_USER_AGENT try: hostname = request.args.get('hostname') resource_record = route53.find_resource_record(hostname) except ValueError: return NO_HOST except: return GENERAL_ERROR if not resource_record: return NO_HOST # TODO - A sanity check of the value would be good, but good luck doing it # easily in anything before Python 3.3+ which got 'ipaddress' module # TODO - Comma separated values should be allowed myip = request.args.get('myip', request.remote_addr) if myip == resource_record['ResourceRecords'][0]['Value']: return NO_CHANGE % myip try: if not route53.update_resource_record(resource_record, myip): return GENERAL_ERROR except: return GENERAL_ERROR return IP_CHANGED % myip