|
4 | 4 | from django.core.cache import cache |
5 | 5 | from rest_framework.test import APITestCase |
6 | 6 | from rest_framework.authtoken.models import Token |
| 7 | +from django.core.exceptions import SuspiciousOperation |
7 | 8 |
|
8 | 9 | from api.models import App, Certificate |
9 | 10 |
|
@@ -120,3 +121,28 @@ def test_delete_certificate(self): |
120 | 121 | url = '/v2/certs/random-test-cert' |
121 | 122 | response = self.client.delete(url) |
122 | 123 | self.assertEqual(response.status_code, 204) |
| 124 | + |
| 125 | + def test_create_invalid_cert(self): |
| 126 | + """Upload a cert that can't be loaded by pyopenssl""" |
| 127 | + response = self.client.post( |
| 128 | + self.url, |
| 129 | + { |
| 130 | + 'name': 'random-test-cert', |
| 131 | + 'certificate': 'i am bad data', |
| 132 | + 'key': 'i am bad data as well' |
| 133 | + } |
| 134 | + ) |
| 135 | + self.assertEqual(response.status_code, 400) |
| 136 | + # match partial since right now the rest is pyopenssl errors |
| 137 | + self.assertIn('Could not load certificate', response.data['certificate'][0]) |
| 138 | + |
| 139 | + def test_load_invalid_cert(self): |
| 140 | + """Inject a cert that can't be loaded by pyopenssl""" |
| 141 | + |
| 142 | + with self.assertRaises(SuspiciousOperation): |
| 143 | + Certificate.objects.create( |
| 144 | + owner=self.user, |
| 145 | + name='random-test-cert', |
| 146 | + certificate='i am bad data', |
| 147 | + key='i am bad data as well' |
| 148 | + ) |
0 commit comments