mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
Dotf fixes 2 (#797)
* [beta] IX-F importer: Adding entry results in 'The server rejected your data' #789 * [beta] IX-F importer: tooltip remains visible after clicking "Auto-resolve", also misspelling #788 * fix protocol-conflict notifications not going out if there are no other conflicts (#771) * fix messy white-space in ix-f notificaiton emails (#790) * add link to python regex documentation (#768) * IX-F import preview when authenticating via basic auth broken #791 Re-add preview tests * [beta] IX-F importer: Lack of "routeserver" status in IX-F JSON should imply "undefined" rather than "false" and result in no action #792 * speed not being present in the ix-f data should be ignored (#792) * [beta] IX-F importer: ignore speed and is_rs_peer differences for now, but retain code #793 * do a simple dedupe of ip addresses before processing the ix-f export remove email debug spam * normalize ip addresses bug fixes for protocol conflict * fix typo and remove debug output * bail if unable to reasonably dedupe duplicate ips in ix-f export data * sanitization fixes * reset ix error notification timer on successful import Co-authored-by: Stefan Pratter <stefan@20c.com> Co-authored-by: Elliot Frank <elliot@20c.com>
This commit is contained in:
158
tests/test_ixf_import_tools.py
Normal file
158
tests/test_ixf_import_tools.py
Normal file
@@ -0,0 +1,158 @@
|
||||
import os
|
||||
import json
|
||||
import reversion
|
||||
import requests
|
||||
import jsonschema
|
||||
import time
|
||||
import io
|
||||
import base64
|
||||
|
||||
from django.db import transaction
|
||||
from django.core.cache import cache
|
||||
from django.test import TestCase, Client, RequestFactory
|
||||
from django.core.management import call_command
|
||||
|
||||
from peeringdb_server.models import (
|
||||
Organization,
|
||||
Network,
|
||||
NetworkIXLan,
|
||||
IXLan,
|
||||
IXLanPrefix,
|
||||
InternetExchange,
|
||||
IXLanIXFMemberImportAttempt,
|
||||
IXLanIXFMemberImportLog,
|
||||
IXLanIXFMemberImportLogEntry,
|
||||
User,
|
||||
)
|
||||
|
||||
from peeringdb_server.import_views import (
|
||||
view_import_ixlan_ixf_preview,
|
||||
view_import_net_ixf_preview,
|
||||
view_import_net_ixf_postmortem,
|
||||
)
|
||||
|
||||
from .util import ClientCase
|
||||
|
||||
|
||||
class TestImportPreview(ClientCase):
|
||||
|
||||
"""
|
||||
Test the ixf import preview
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
super(TestImportPreview, cls).setUpTestData()
|
||||
cls.org = Organization.objects.create(name="Test Org", status="ok")
|
||||
cls.ix = InternetExchange.objects.create(
|
||||
name="Test IX", status="ok", org=cls.org
|
||||
)
|
||||
|
||||
cls.ixlan = cls.ix.ixlan
|
||||
|
||||
IXLanPrefix.objects.create(
|
||||
ixlan=cls.ixlan, status="ok", prefix="195.69.144.0/22", protocol="IPv4"
|
||||
)
|
||||
IXLanPrefix.objects.create(
|
||||
ixlan=cls.ixlan, status="ok", prefix="2001:7f8:1::/64", protocol="IPv6"
|
||||
)
|
||||
|
||||
cls.net = Network.objects.create(
|
||||
org=cls.org, status="ok", asn=1000, name="net01"
|
||||
)
|
||||
cls.net_2 = Network.objects.create(
|
||||
org=cls.org, status="ok", asn=1001, name="net02"
|
||||
)
|
||||
|
||||
cls.admin_user = User.objects.create_user("admin", "admin@localhost", "admin")
|
||||
|
||||
cls.org.admin_usergroup.user_set.add(cls.admin_user)
|
||||
|
||||
def test_import_preview(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/ixlan/{}/ixf/preview/".format(self.ixlan.id)
|
||||
)
|
||||
request.user = self.admin_user
|
||||
|
||||
response = view_import_ixlan_ixf_preview(request, self.ixlan.id)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.content)["errors"] == [
|
||||
"IXF import url not specified"
|
||||
]
|
||||
|
||||
def test_import_preview_basic_auth(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/ixlan/{}/ixf/preview/".format(self.ixlan.id)
|
||||
)
|
||||
auth = base64.b64encode("admin:admin".encode("utf-8")).decode("utf-8")
|
||||
request.META["HTTP_AUTHORIZATION"] = f"Basic {auth}"
|
||||
|
||||
response = view_import_ixlan_ixf_preview(request, self.ixlan.id)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert json.loads(response.content)["errors"] == [
|
||||
"IXF import url not specified"
|
||||
]
|
||||
|
||||
def test_import_preview_fail_ratelimit(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/ixlan/{}/ixf/preview/".format(self.ixlan.id)
|
||||
)
|
||||
request.user = self.admin_user
|
||||
|
||||
response = view_import_ixlan_ixf_preview(request, self.ixlan.id)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = view_import_ixlan_ixf_preview(request, self.ixlan.id)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_import_preview_fail_permission(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/ixlan/{}/ixf/preview/".format(self.ixlan.id)
|
||||
)
|
||||
request.user = self.guest_user
|
||||
|
||||
response = view_import_ixlan_ixf_preview(request, self.ixlan.id)
|
||||
assert response.status_code == 403
|
||||
|
||||
def test_import_net_preview(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/net/{}/ixf/preview/".format(self.net.id)
|
||||
)
|
||||
request.user = self.admin_user
|
||||
|
||||
response = view_import_net_ixf_preview(request, self.net.id)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_import_net_preview_basic_auth(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/net/{}/ixf/preview/".format(self.net.id)
|
||||
)
|
||||
auth = base64.b64encode("admin:admin".encode("utf-8")).decode("utf-8")
|
||||
request.META["HTTP_AUTHORIZATION"] = f"Basic {auth}"
|
||||
response = view_import_net_ixf_preview(request, self.net.id)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_import_net_preview_fail_ratelimit(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/net/{}/ixf/preview/".format(self.net.id)
|
||||
)
|
||||
request.user = self.admin_user
|
||||
|
||||
response = view_import_net_ixf_preview(request, self.net.id)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = view_import_net_ixf_preview(request, self.net.id)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_import_net_preview_fail_permission(self):
|
||||
request = RequestFactory().get(
|
||||
"/import/net/{}/ixf/preview/".format(self.net.id)
|
||||
)
|
||||
request.user = self.guest_user
|
||||
|
||||
response = view_import_net_ixf_preview(request, self.net.id)
|
||||
assert response.status_code == 403
|
Reference in New Issue
Block a user