Skip to content

Commit 1364cd5

Browse files
committed
chore(tests): increase coverage of certs, test bad keys
1 parent b8c2d90 commit 1364cd5

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

rootfs/api/tests/test_certificate.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.cache import cache
55
from rest_framework.test import APITestCase
66
from rest_framework.authtoken.models import Token
7+
from django.core.exceptions import SuspiciousOperation
78

89
from api.models import App, Certificate
910

@@ -120,3 +121,28 @@ def test_delete_certificate(self):
120121
url = '/v2/certs/random-test-cert'
121122
response = self.client.delete(url)
122123
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

Comments
 (0)