2020-02-21 15:33:37 +00:00
|
|
|
from django.test import TestCase
|
2020-05-20 19:00:08 +00:00
|
|
|
from rest_framework.test import APIRequestFactory, force_authenticate
|
2020-02-21 15:33:37 +00:00
|
|
|
|
2020-05-20 19:00:08 +00:00
|
|
|
from rest_framework.reverse import reverse
|
|
|
|
from django.contrib.auth import get_user_model
|
2020-10-11 20:32:08 +00:00
|
|
|
from django.core.exceptions import ValidationError, FieldError
|
2020-05-20 19:00:08 +00:00
|
|
|
|
|
|
|
from .views import *
|
|
|
|
from .models import *
|
|
|
|
|
2020-05-23 19:32:56 +00:00
|
|
|
from uncloud_pay.models import BillingAddress, Order
|
2020-11-15 14:43:11 +00:00
|
|
|
from uncloud.models import UncloudNetwork
|
2020-10-11 20:32:08 +00:00
|
|
|
|
|
|
|
class UncloudNetworkTests(TestCase):
|
|
|
|
def test_invalid_IPv4_network(self):
|
|
|
|
with self.assertRaises(FieldError):
|
|
|
|
UncloudNetwork.objects.create(network_address="192.168.1.0",
|
|
|
|
network_mask=33)
|
|
|
|
|
2020-05-20 19:00:08 +00:00
|
|
|
class VPNTests(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.user = get_user_model().objects.create_user('django-test-user', 'noreply@ungleich.ch')
|
2020-08-04 10:41:15 +00:00
|
|
|
self.admin_user = get_user_model().objects.create_user('django-test-adminuser',
|
|
|
|
'noreply-admin@ungleich.ch')
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-20 19:00:08 +00:00
|
|
|
self.admin_user.is_staff = True
|
|
|
|
self.admin_user.save()
|
|
|
|
|
|
|
|
self.pool_network = '2001:db8::'
|
|
|
|
self.pool_network2 = '2001:db8:1::'
|
|
|
|
self.pool_network_size = '48'
|
|
|
|
self.pool_subnetwork_size = '64'
|
|
|
|
self.pool_vpn_hostname = 'vpn.example.org'
|
|
|
|
self.pool_wireguard_private_key = 'MOz8kk0m4jhNtAXlge0qzexZh1MipIhu4HJwtdvZ2EY='
|
|
|
|
|
|
|
|
self.vpn_wireguard_public_key = 'B2b78eWBIXPMM1x4DDjkCDZepS0qDgcLN3T3PjcgXkY='
|
|
|
|
|
2021-07-19 14:36:10 +00:00
|
|
|
self.vpnpool = WireGuardVPNPool.objects.get_or_create(network=self.pool_network,
|
2020-05-20 19:00:08 +00:00
|
|
|
network_size=self.pool_network_size,
|
|
|
|
subnetwork_size=self.pool_subnetwork_size,
|
|
|
|
vpn_hostname=self.pool_vpn_hostname,
|
|
|
|
wireguard_private_key=self.pool_wireguard_private_key
|
|
|
|
)
|
|
|
|
|
|
|
|
self.factory = APIRequestFactory()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.user.delete()
|
|
|
|
self.admin_user.delete()
|