def test_dns_rv(): test = Validate(test_csv_fname) test.read_csv() assert test.dns_rv() == ([{ '10.10.in-addr.arpa': ('42.11', 'computer1.stesworld.com.') }, { '8.in-addr.arpa': ('8.8.8', 'computer2.stesworld.com.') }, { '16.172.in-addr.arpa': ('5.48', 'computer3.stesworld.org.') }, { '16.172.in-addr.arpa': ('30.48', 'computer3.stesworld.org.') }, { '1.168.192.in-addr.arpa': ('42', 'computer3.stesworld.org.') }]), 'Error with DNS reverse zone formatting'
def post(self): t_template_vaules = { 'message_class': 'no_message', 'message_text': ' ', 'logout_btn_class' : 'show', 'logout_url' : users.create_logout_url('/'), 'admin' : True, } error = False campaign = AdCampaign() #get variables from POST and validate if needed if Validate(self.request.get('name'), ValidationTypes.String, True) is True: campaign.name = self.request.get('name') else: error = True t_template_vaules['message_text'] = 'Name required to start a campaign' campaign.details = self.request.get('details') #check if name is already in use if campaign.name_exist(campaign.name) is True: error = True t_template_vaules['message_text'] = 'Name: %s, is already in use.' %campaign.name #check for errors if error is False: #create link campaign.link = hashlib.md5(campaign.name).hexdigest() campaign.put() t_template_vaules['ad_campaign_url'] = "campaign link is: dryve.io/ad/%s" %campaign.link else: t_template_vaules['message_class'] = 'bad_message' #save and returns results t_template_vaules['campaigns'] = (AdCampaign().query().order(-AdCampaign.start_date)).iter() path = os.path.join(os.path.dirname(__file__), 'templates/ad_campaign.html') self.response.out.write(template.render(path, t_template_vaules))
def validate_cep(): cep = str(request.args.get('cep')) try: res = Validate(cep) error = None except Exception as e: res = False error = str(e) return jsonify({'cep': cep, 'result': res, 'error': error})
def test_verify_dom_mac_ipin(capsys): test = Validate(test_other_fname) test.read_csv() try: test.verify() except SystemExit: pass assert capsys.readouterr().out == ( '!!!ERROR - Invalid Domain names entered !!!\n' "{'10.10.10.0/24': ('10.10.20.1', 'computer7.stesworld.org', " "'1a-1z-1c-1f-1e-1f')}\n" '!!!ERROR - Invalid MAC addresses entered !!!\n' "{'10.10.10.0/24': ('10.10.20.1', 'computer7.stesworld.org', " "'1a-1z-1c-1f-1e-1f')}\n" '!!!ERROR - IP address not a valid IP address in DHCP scope !!!\n' '10.10.20.1 not in 10.10.10.0/24\n' '!!!ERROR - The TTL is not in a valid format, must be hh:mm:ss upto a maximum ' 'of 23:59:59 !!!\n' "{'stesworld.org': ('10.10.20.1', 'computer7', '24:61:71')}\n" '!!!ERROR - The following IP addresses have duplicate entries in the CSV !!!\n' '10.10.10.10\n' '!!!ERROR - The following MAC addresses have duplicate entries in the CSV ' '!!!\n' '1a-1b-1c-1f-1e-1f\n' ), 'Error detecting badly formated MAC address, TTL domain name, IP not in scope or duplicate MAC or IP adddresses'
def test_csv_format(): test = Validate(test_csv_fname) output = test.read_csv() assert output[0] == [{ '10.10.10.0/23': ('10.10.11.42', 'computer1.stesworld.com', '1e-1b-1c-1d-1e-1f') }, { '8.0.0.0/8': ('8.8.8.8', 'computer2.stesworld.com', '1d-1b-1c-1d-1e-1f') }, { '172.16.32.0/19': ('172.16.48.5', 'computer3.stesworld.org', '1c-1b-1c-1d-1e-1f') }, { '172.16.32.0/19': ('172.16.48.30', 'computer3.stesworld.org', '1b-1b-1c-1d-1e-1f') }, { '192.168.1.0/24': ('192.168.1.42', 'computer3.stesworld.org', '1a-1b-1c-1d-1e-1f') }] assert output[1] == [{ 'stesworld.com': ('10.10.11.42', 'computer1', '01:00:00') }, { 'stesworld.com': ('8.8.8.8', 'computer2', '00:20:00') }, { 'stesworld.org': ('172.16.48.5', 'computer3', '01:00:00') }, { 'stesworld.org': ('172.16.48.30', 'computer3', '01:00:00') }, { 'stesworld.org': ('192.168.1.42', 'computer3', '01:00:00') }] assert output[2] == [ ['10.10.11.42/23', 'computer1.stesworld.com.', '01:00:00'], ['8.8.8.8/8', 'computer2.stesworld.com.', '00:20:00'], ['172.16.48.5/19', 'computer3.stesworld.org.', '01:00:00'], ['172.16.48.30/19', 'computer3.stesworld.org.', '01:00:00'], ['192.168.1.42/24', 'computer3.stesworld.org.', '01:00:00'] ]
def test_verify_scope_ip(capsys): test = Validate(test_addr_fname) test.read_csv() try: test.verify() except SystemExit: pass assert capsys.readouterr().out == ( '!!!ERROR - Invalid scope addresses entered !!!\n' "'10.10.999.0/24' does not appear to be an IPv4 or IPv6 network\n" '!!!ERROR - Invalid IP addresses entered !!!\n' "'10.999.20.1' does not appear to be an IPv4 or IPv6 address\n" ), 'Error detecting badly formated IP address or scope network address'
def test_data_model(): test = Validate(test_csv_fname) output = test.read_csv() assert test.make_data_model(output[0]) == [{ '10.10.10.0': [('10.10.11.42', 'computer1.stesworld.com', '1e-1b-1c-1d-1e-1f')] }, { '8.0.0.0': [('8.8.8.8', 'computer2.stesworld.com', '1d-1b-1c-1d-1e-1f')] }, { '172.16.32.0': [('172.16.48.5', 'computer3.stesworld.org', '1c-1b-1c-1d-1e-1f'), ('172.16.48.30', 'computer3.stesworld.org', '1b-1b-1c-1d-1e-1f')] }, { '192.168.1.0': [('192.168.1.42', 'computer3.stesworld.org', '1a-1b-1c-1d-1e-1f')] }], 'Error with DHCP DM formatting' assert test.make_data_model(output[1]) == [{ 'stesworld.com': [('10.10.11.42', 'computer1', '01:00:00'), ('8.8.8.8', 'computer2', '00:20:00')] }, { 'stesworld.org': [('172.16.48.5', 'computer3', '01:00:00'), ('172.16.48.30', 'computer3', '01:00:00'), ('192.168.1.42', 'computer3', '01:00:00')] }], 'Error with DNS, FW DM formatting' assert test.make_data_model(csv_dns_rv_output) == [{ '10.10.in-addr.arpa': [('1.42', 'computer1.stesworld.com.')] }, { '8.in-addr.arpa': [('8.8.8', 'computer2.stesworld.com.')] }, { '16.172.in-addr.arpa': [('16.30', 'computer3.stesworld.org.')] }, { '10.10.10.in-addr.arpa': [('45', 'computer45.stesworld.com.')] }, { '1.168.192.in-addr.arpa': [('42', 'computer3.stesworld.org.')] }]
def test_false_codes(self): self.assertFalse(Validate('121426')) self.assertFalse(Validate('552523'))
def test_right_codes(self): self.assertTrue(Validate('523563')) self.assertTrue(Validate('112233'))