|
@@ -214,6 +214,18 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
self.assertEqual(response.data['records'][0], '1.2.3.4')
|
|
self.assertEqual(response.data['records'][0], '1.2.3.4')
|
|
self.assertEqual(response.data['ttl'], 60)
|
|
self.assertEqual(response.data['ttl'], 60)
|
|
|
|
|
|
|
|
+ def testCanGetOwnRRsetApex(self):
|
|
|
|
+ url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
|
|
+ data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A'}
|
|
|
|
+ response = self.client.post(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
+
|
|
|
|
+ url = reverse('rrset@', args=(self.ownedDomains[1].name, '@', 'A',))
|
|
|
|
+ response = self.client.get(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '1.2.3.4')
|
|
|
|
+ self.assertEqual(response.data['ttl'], 60)
|
|
|
|
+
|
|
def testCantGetRestrictedTypes(self):
|
|
def testCantGetRestrictedTypes(self):
|
|
for type_ in self.restricted_types:
|
|
for type_ in self.restricted_types:
|
|
url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
@@ -287,6 +299,32 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
|
|
url = reverse('rrset', args=(self.ownedDomains[1].name, '', 'A',))
|
|
url = reverse('rrset', args=(self.ownedDomains[1].name, '', 'A',))
|
|
|
|
+
|
|
|
|
+ data = {'records': ['2.2.3.4'], 'ttl': 30}
|
|
|
|
+ response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+
|
|
|
|
+ response = self.client.get(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '2.2.3.4')
|
|
|
|
+ self.assertEqual(response.data['ttl'], 30)
|
|
|
|
+
|
|
|
|
+ data = {'records': ['3.2.3.4']}
|
|
|
|
+ response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
+
|
|
|
|
+ data = {'ttl': 37}
|
|
|
|
+ response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
+
|
|
|
|
+ def testCanPutOwnRRsetApex(self):
|
|
|
|
+ url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
|
|
+ data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A'}
|
|
|
|
+ response = self.client.post(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
+
|
|
|
|
+ url = reverse('rrset@', args=(self.ownedDomains[1].name, '@', 'A',))
|
|
|
|
+
|
|
data = {'records': ['2.2.3.4'], 'ttl': 30}
|
|
data = {'records': ['2.2.3.4'], 'ttl': 30}
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
@@ -296,12 +334,10 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
self.assertEqual(response.data['records'][0], '2.2.3.4')
|
|
self.assertEqual(response.data['records'][0], '2.2.3.4')
|
|
self.assertEqual(response.data['ttl'], 30)
|
|
self.assertEqual(response.data['ttl'], 30)
|
|
|
|
|
|
- url = reverse('rrset', args=(self.ownedDomains[1].name, '', 'A',))
|
|
|
|
data = {'records': ['3.2.3.4']}
|
|
data = {'records': ['3.2.3.4']}
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
- url = reverse('rrset', args=(self.ownedDomains[1].name, '', 'A',))
|
|
|
|
data = {'ttl': 37}
|
|
data = {'ttl': 37}
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
@@ -344,6 +380,44 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
self.assertEqual(response.data['records'][0], '5.2.3.4')
|
|
self.assertEqual(response.data['records'][0], '5.2.3.4')
|
|
self.assertEqual(response.data['ttl'], 37)
|
|
self.assertEqual(response.data['ttl'], 37)
|
|
|
|
|
|
|
|
+ def testCanPatchOwnRRsetApex(self):
|
|
|
|
+ url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
|
|
+ data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A'}
|
|
|
|
+ response = self.client.post(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
+
|
|
|
|
+ # Change records and TTL
|
|
|
|
+ url = reverse('rrset@', args=(self.ownedDomains[1].name, '@', 'A',))
|
|
|
|
+ data = {'records': ['3.2.3.4'], 'ttl': 32}
|
|
|
|
+ response = self.client.patch(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+
|
|
|
|
+ response = self.client.get(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '3.2.3.4')
|
|
|
|
+ self.assertEqual(response.data['ttl'], 32)
|
|
|
|
+
|
|
|
|
+ # Change records alone
|
|
|
|
+ data = {'records': ['5.2.3.4']}
|
|
|
|
+ response = self.client.patch(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '5.2.3.4')
|
|
|
|
+ self.assertEqual(response.data['ttl'], 32)
|
|
|
|
+
|
|
|
|
+ # Change TTL alone
|
|
|
|
+ data = {'ttl': 37}
|
|
|
|
+ response = self.client.patch(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '5.2.3.4')
|
|
|
|
+ self.assertEqual(response.data['ttl'], 37)
|
|
|
|
+
|
|
|
|
+ # Change nothing
|
|
|
|
+ data = {}
|
|
|
|
+ response = self.client.patch(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '5.2.3.4')
|
|
|
|
+ self.assertEqual(response.data['ttl'], 37)
|
|
|
|
+
|
|
def testCantChangeForeignRRset(self):
|
|
def testCantChangeForeignRRset(self):
|
|
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.otherToken)
|
|
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.otherToken)
|
|
url = reverse('rrsets', args=(self.otherDomains[0].name,))
|
|
url = reverse('rrsets', args=(self.otherDomains[0].name,))
|
|
@@ -361,6 +435,23 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
|
|
|
|
+ def testCantChangeForeignRRsetApex(self):
|
|
|
|
+ self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.otherToken)
|
|
|
|
+ url = reverse('rrsets', args=(self.otherDomains[0].name,))
|
|
|
|
+ data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A'}
|
|
|
|
+ response = self.client.post(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
+
|
|
|
|
+ self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
|
|
|
|
+ url = reverse('rrset@', args=(self.otherDomains[0].name, '@', 'A',))
|
|
|
|
+ data = {'records': ['3.2.3.4'], 'ttl': 30, 'type': 'A'}
|
|
|
|
+
|
|
|
|
+ response = self.client.patch(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
+
|
|
|
|
+ response = self.client.put(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
+
|
|
def testCantChangeEssentialProperties(self):
|
|
def testCantChangeEssentialProperties(self):
|
|
url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A', 'subname': 'test1'}
|
|
data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A', 'subname': 'test1'}
|
|
@@ -430,6 +521,34 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
response = self.client.get(url)
|
|
response = self.client.get(url)
|
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
|
|
|
|
+ def testCanDeleteOwnRRsetApex(self):
|
|
|
|
+ # Try PATCH with empty records
|
|
|
|
+ url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
|
|
+ data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A'}
|
|
|
|
+ response = self.client.post(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
+
|
|
|
|
+ url = reverse('rrset@', args=(self.ownedDomains[1].name, '@', 'A',))
|
|
|
|
+ data = {'records': []}
|
|
|
|
+ response = self.client.patch(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
+
|
|
|
|
+ response = self.client.get(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
+
|
|
|
|
+ # Try DELETE
|
|
|
|
+ url = reverse('rrsets', args=(self.ownedDomains[1].name,))
|
|
|
|
+ data = {'records': ['1.2.3.4'], 'ttl': 60, 'type': 'A'}
|
|
|
|
+ response = self.client.post(url, json.dumps(data), content_type='application/json')
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
+
|
|
|
|
+ url = reverse('rrset@', args=(self.ownedDomains[1].name, '@', 'A',))
|
|
|
|
+ response = self.client.delete(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
+
|
|
|
|
+ response = self.client.get(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
|
|
+
|
|
def testCantDeleteForeignRRset(self):
|
|
def testCantDeleteForeignRRset(self):
|
|
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.otherToken)
|
|
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.otherToken)
|
|
url = reverse('rrsets', args=(self.otherDomains[0].name,))
|
|
url = reverse('rrsets', args=(self.otherDomains[0].name,))
|
|
@@ -449,6 +568,13 @@ class AuthenticatedRRsetTests(APITestCase):
|
|
response = self.client.delete(url)
|
|
response = self.client.delete(url)
|
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
|
|
|
|
|
|
|
+ # Make sure it actually is still there
|
|
|
|
+ self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.otherToken)
|
|
|
|
+ url = reverse('rrset@', args=(self.otherDomains[0].name, '@', 'A',))
|
|
|
|
+ response = self.client.get(url)
|
|
|
|
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
+ self.assertEqual(response.data['records'][0], '1.2.3.4')
|
|
|
|
+
|
|
def testCantDeleteOwnRRsetWhileAccountIsLocked(self):
|
|
def testCantDeleteOwnRRsetWhileAccountIsLocked(self):
|
|
self.owner.locked = timezone.now()
|
|
self.owner.locked = timezone.now()
|
|
self.owner.save()
|
|
self.owner.save()
|