2015-08-04 06:07:28 +02:00
|
|
|
from __future__ import unicode_literals # at top of module
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
import json
|
2016-10-31 19:00:15 +01:00
|
|
|
import pytest
|
|
|
|
import datetime
|
2016-11-09 19:56:22 +01:00
|
|
|
import arrow
|
2016-10-31 19:00:15 +01:00
|
|
|
|
|
|
|
from freezegun import freeze_time
|
2017-01-27 21:31:29 +01:00
|
|
|
from cryptography import x509
|
2016-05-09 20:00:16 +02:00
|
|
|
|
2015-07-21 22:06:13 +02:00
|
|
|
from lemur.certificates.views import * # noqa
|
|
|
|
|
2016-10-15 09:04:35 +02:00
|
|
|
from lemur.tests.vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN, CSR_STR, \
|
2016-05-20 18:03:34 +02:00
|
|
|
INTERNAL_VALID_LONG_STR, INTERNAL_VALID_SAN_STR, PRIVATE_KEY_STR
|
2015-06-25 01:48:40 +02:00
|
|
|
|
2015-06-27 01:16:13 +02:00
|
|
|
|
2017-01-06 01:06:34 +01:00
|
|
|
def test_get_or_increase_name(session, certificate):
|
|
|
|
from lemur.certificates.models import get_or_increase_name
|
|
|
|
|
|
|
|
assert get_or_increase_name('test name') == 'test-name'
|
|
|
|
assert get_or_increase_name(certificate.name) == '{0}-1'.format(certificate.name)
|
|
|
|
|
|
|
|
certificate.name = 'test-cert-11111111'
|
|
|
|
assert get_or_increase_name(certificate.name) == 'test-cert-11111111-1'
|
|
|
|
|
|
|
|
certificate.name = 'test-cert-11111111-1'
|
|
|
|
assert get_or_increase_name('test-cert-11111111-1') == 'test-cert-11111111-2'
|
|
|
|
|
|
|
|
|
2016-10-31 19:00:15 +01:00
|
|
|
def test_get_certificate_primitives(certificate):
|
|
|
|
from lemur.certificates.service import get_certificate_primitives
|
|
|
|
|
2017-01-27 21:31:29 +01:00
|
|
|
names = [x509.DNSName(x.name) for x in certificate.domains]
|
2016-10-31 19:00:15 +01:00
|
|
|
|
|
|
|
data = {
|
|
|
|
'common_name': certificate.cn,
|
|
|
|
'owner': certificate.owner,
|
|
|
|
'authority': certificate.authority,
|
|
|
|
'description': certificate.description,
|
|
|
|
'extensions': {
|
2017-01-27 21:31:29 +01:00
|
|
|
'sub_alt_names': x509.SubjectAlternativeName(names)
|
2016-10-31 19:00:15 +01:00
|
|
|
},
|
|
|
|
'destinations': [],
|
|
|
|
'roles': [],
|
2016-11-18 20:27:46 +01:00
|
|
|
'validity_end': arrow.get(2021, 5, 7),
|
|
|
|
'validity_start': arrow.get(2016, 10, 30),
|
|
|
|
'country': 'US',
|
|
|
|
'location': 'A place',
|
|
|
|
'organization': 'Example',
|
|
|
|
'organizational_unit': 'Operations',
|
|
|
|
'state': 'CA'
|
2016-10-31 19:00:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
with freeze_time(datetime.date(year=2016, month=10, day=30)):
|
|
|
|
primitives = get_certificate_primitives(certificate)
|
2017-03-09 22:09:20 +01:00
|
|
|
assert len(primitives) == 20
|
2016-10-31 19:00:15 +01:00
|
|
|
|
|
|
|
|
2016-10-18 08:23:14 +02:00
|
|
|
def test_certificate_edit_schema(session):
|
|
|
|
from lemur.certificates.schemas import CertificateEditInputSchema
|
|
|
|
|
|
|
|
input_data = {'owner': 'bob@example.com'}
|
|
|
|
data, errors = CertificateEditInputSchema().load(input_data)
|
|
|
|
assert len(data['notifications']) == 3
|
|
|
|
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
def test_authority_key_identifier_schema():
|
2016-05-09 20:00:16 +02:00
|
|
|
from lemur.schemas import AuthorityKeyIdentifierSchema
|
2017-01-18 23:16:19 +01:00
|
|
|
input_data = {
|
|
|
|
'useKeyIdentifier': True,
|
|
|
|
'useAuthorityCert': True
|
|
|
|
}
|
2016-05-05 21:52:08 +02:00
|
|
|
|
|
|
|
data, errors = AuthorityKeyIdentifierSchema().load(input_data)
|
|
|
|
|
2017-04-27 18:13:04 +02:00
|
|
|
assert sorted(data) == sorted({
|
2017-01-18 23:16:19 +01:00
|
|
|
'use_key_identifier': True,
|
|
|
|
'use_authority_cert': True
|
2017-04-27 18:13:04 +02:00
|
|
|
})
|
2016-05-05 21:52:08 +02:00
|
|
|
assert not errors
|
|
|
|
|
|
|
|
data, errors = AuthorityKeyIdentifierSchema().dumps(data)
|
2017-04-27 18:13:04 +02:00
|
|
|
assert sorted(data) == sorted(json.dumps(input_data))
|
2016-05-05 21:52:08 +02:00
|
|
|
assert not errors
|
|
|
|
|
|
|
|
|
|
|
|
def test_certificate_info_access_schema():
|
2016-05-09 20:00:16 +02:00
|
|
|
from lemur.schemas import CertificateInfoAccessSchema
|
2016-05-05 21:52:08 +02:00
|
|
|
input_data = {'includeAIA': True}
|
|
|
|
|
|
|
|
data, errors = CertificateInfoAccessSchema().load(input_data)
|
|
|
|
assert not errors
|
|
|
|
assert data == {'include_aia': True}
|
|
|
|
|
|
|
|
data, errors = CertificateInfoAccessSchema().dump(data)
|
|
|
|
assert not errors
|
|
|
|
assert data == input_data
|
|
|
|
|
|
|
|
|
|
|
|
def test_subject_key_identifier_schema():
|
2016-05-09 20:00:16 +02:00
|
|
|
from lemur.schemas import SubjectKeyIdentifierSchema
|
2016-05-05 21:52:08 +02:00
|
|
|
|
|
|
|
input_data = {'includeSKI': True}
|
|
|
|
|
|
|
|
data, errors = SubjectKeyIdentifierSchema().load(input_data)
|
|
|
|
assert not errors
|
|
|
|
assert data == {'include_ski': True}
|
|
|
|
data, errors = SubjectKeyIdentifierSchema().dump(data)
|
|
|
|
assert not errors
|
|
|
|
assert data == input_data
|
|
|
|
|
|
|
|
|
2016-05-09 20:00:16 +02:00
|
|
|
def test_extension_schema(client):
|
2016-05-05 21:52:08 +02:00
|
|
|
from lemur.certificates.schemas import ExtensionSchema
|
|
|
|
|
|
|
|
input_data = {
|
|
|
|
'keyUsage': {
|
|
|
|
'useKeyEncipherment': True,
|
|
|
|
'useDigitalSignature': True
|
|
|
|
},
|
|
|
|
'extendedKeyUsage': {
|
|
|
|
'useServerAuthentication': True
|
|
|
|
},
|
|
|
|
'subjectKeyIdentifier': {
|
|
|
|
'includeSKI': True
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data, errors = ExtensionSchema().load(input_data)
|
|
|
|
assert not errors
|
|
|
|
|
2017-01-29 01:40:37 +01:00
|
|
|
data, errors = ExtensionSchema().dump(data)
|
|
|
|
assert not errors
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
|
|
|
|
def test_certificate_input_schema(client, authority):
|
|
|
|
from lemur.certificates.schemas import CertificateInputSchema
|
|
|
|
|
|
|
|
input_data = {
|
|
|
|
'commonName': 'test.example.com',
|
|
|
|
'owner': 'jim@example.com',
|
|
|
|
'authority': {'id': authority.id},
|
|
|
|
'description': 'testtestest',
|
2016-11-09 19:56:22 +01:00
|
|
|
'validityEnd': arrow.get(2016, 11, 9).isoformat(),
|
|
|
|
'validityStart': arrow.get(2015, 11, 9).isoformat()
|
2016-05-05 21:52:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
|
|
|
|
assert not errors
|
|
|
|
assert data['authority'].id == authority.id
|
|
|
|
|
|
|
|
# make sure the defaults got set
|
|
|
|
assert data['common_name'] == 'test.example.com'
|
|
|
|
assert data['country'] == 'US'
|
|
|
|
assert data['location'] == 'Los Gatos'
|
|
|
|
|
2016-12-26 20:09:50 +01:00
|
|
|
assert len(data.keys()) == 17
|
2016-05-05 21:52:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_certificate_input_with_extensions(client, authority):
|
|
|
|
from lemur.certificates.schemas import CertificateInputSchema
|
|
|
|
|
|
|
|
input_data = {
|
|
|
|
'commonName': 'test.example.com',
|
|
|
|
'owner': 'jim@example.com',
|
|
|
|
'authority': {'id': authority.id},
|
|
|
|
'description': 'testtestest',
|
|
|
|
'extensions': {
|
|
|
|
'keyUsage': {
|
2017-01-27 21:31:29 +01:00
|
|
|
'digital_signature': True
|
2016-05-05 21:52:08 +02:00
|
|
|
},
|
|
|
|
'extendedKeyUsage': {
|
2017-01-27 21:31:29 +01:00
|
|
|
'useClientAuthentication': True,
|
2016-05-05 21:52:08 +02:00
|
|
|
'useServerAuthentication': True
|
|
|
|
},
|
|
|
|
'subjectKeyIdentifier': {
|
|
|
|
'includeSKI': True
|
|
|
|
},
|
|
|
|
'subAltNames': {
|
|
|
|
'names': [
|
|
|
|
{'nameType': 'DNSName', 'value': 'test.example.com'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
assert not errors
|
|
|
|
|
|
|
|
|
|
|
|
def test_certificate_out_of_range_date(client, authority):
|
|
|
|
from lemur.certificates.schemas import CertificateInputSchema
|
|
|
|
input_data = {
|
|
|
|
'commonName': 'test.example.com',
|
|
|
|
'owner': 'jim@example.com',
|
|
|
|
'authority': {'id': authority.id},
|
|
|
|
'description': 'testtestest',
|
|
|
|
'validityYears': 100
|
|
|
|
}
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
assert errors
|
|
|
|
|
|
|
|
input_data['validityStart'] = '2017-04-30T00:12:34.513631'
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
assert errors
|
|
|
|
|
|
|
|
input_data['validityEnd'] = '2018-04-30T00:12:34.513631'
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
assert errors
|
|
|
|
|
|
|
|
|
|
|
|
def test_certificate_valid_years(client, authority):
|
|
|
|
from lemur.certificates.schemas import CertificateInputSchema
|
|
|
|
input_data = {
|
|
|
|
'commonName': 'test.example.com',
|
|
|
|
'owner': 'jim@example.com',
|
|
|
|
'authority': {'id': authority.id},
|
|
|
|
'description': 'testtestest',
|
2017-01-05 02:46:47 +01:00
|
|
|
'validityYears': 2
|
2016-05-05 21:52:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
assert not errors
|
|
|
|
|
|
|
|
|
|
|
|
def test_certificate_valid_dates(client, authority):
|
|
|
|
from lemur.certificates.schemas import CertificateInputSchema
|
|
|
|
input_data = {
|
|
|
|
'commonName': 'test.example.com',
|
|
|
|
'owner': 'jim@example.com',
|
|
|
|
'authority': {'id': authority.id},
|
|
|
|
'description': 'testtestest',
|
2016-06-01 20:18:00 +02:00
|
|
|
'validityStart': '2020-01-01T00:00:00',
|
|
|
|
'validityEnd': '2020-01-01T00:00:01'
|
2016-05-05 21:52:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data, errors = CertificateInputSchema().load(input_data)
|
|
|
|
assert not errors
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_basic_csr(client):
|
|
|
|
from cryptography import x509
|
|
|
|
from cryptography.hazmat.backends import default_backend
|
2015-06-29 22:51:52 +02:00
|
|
|
from lemur.certificates.service import create_csr
|
2015-07-03 19:30:17 +02:00
|
|
|
csr_config = dict(
|
2016-05-05 21:52:08 +02:00
|
|
|
common_name='example.com',
|
2015-08-04 06:07:28 +02:00
|
|
|
organization='Example, Inc.',
|
2016-05-05 21:52:08 +02:00
|
|
|
organizational_unit='Operations',
|
2015-08-04 06:07:28 +02:00
|
|
|
country='US',
|
|
|
|
state='CA',
|
|
|
|
location='A place',
|
2016-08-25 19:09:46 +02:00
|
|
|
owner='joe@example.com',
|
2016-12-02 00:41:53 +01:00
|
|
|
key_type='RSA2048',
|
2017-01-27 21:31:29 +01:00
|
|
|
extensions=dict(names=dict(sub_alt_names=x509.SubjectAlternativeName([x509.DNSName('test.example.com'), x509.DNSName('test2.example.com')])))
|
2015-07-03 19:30:17 +02:00
|
|
|
)
|
2016-05-20 18:03:34 +02:00
|
|
|
csr, pem = create_csr(**csr_config)
|
2015-07-03 19:30:17 +02:00
|
|
|
|
2016-11-30 02:15:39 +01:00
|
|
|
csr = x509.load_pem_x509_csr(csr.encode('utf-8'), default_backend())
|
2015-07-03 19:30:17 +02:00
|
|
|
for name in csr.subject:
|
|
|
|
assert name.value in csr_config.values()
|
2015-06-27 01:16:13 +02:00
|
|
|
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
def test_get_name_from_arn(client):
|
2016-05-19 22:37:05 +02:00
|
|
|
from lemur.certificates.service import get_name_from_arn
|
2015-06-27 01:16:13 +02:00
|
|
|
arn = 'arn:aws:iam::11111111:server-certificate/mycertificate'
|
|
|
|
assert get_name_from_arn(arn) == 'mycertificate'
|
|
|
|
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
def test_get_account_number(client):
|
2016-05-19 22:37:05 +02:00
|
|
|
from lemur.certificates.service import get_account_number
|
2015-06-27 01:16:13 +02:00
|
|
|
arn = 'arn:aws:iam::11111111:server-certificate/mycertificate'
|
|
|
|
assert get_account_number(arn) == '11111111'
|
|
|
|
|
|
|
|
|
2016-12-08 20:33:40 +01:00
|
|
|
def test_mint_certificate(issuer_plugin, authority):
|
2016-05-20 18:03:34 +02:00
|
|
|
from lemur.certificates.service import mint
|
|
|
|
cert_body, private_key, chain = mint(authority=authority, csr=CSR_STR)
|
|
|
|
assert cert_body == INTERNAL_VALID_LONG_STR, INTERNAL_VALID_SAN_STR
|
|
|
|
|
|
|
|
|
2016-11-18 20:27:46 +01:00
|
|
|
def test_create_certificate(issuer_plugin, authority, user):
|
2016-05-20 18:03:34 +02:00
|
|
|
from lemur.certificates.service import create
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = create(authority=authority, csr=CSR_STR, owner='joe@example.com', creator=user['user'])
|
|
|
|
assert str(cert.not_after) == '2040-01-01T20:30:52+00:00'
|
|
|
|
assert str(cert.not_before) == '2015-06-26T20:30:52+00:00'
|
2016-05-20 18:03:34 +02:00
|
|
|
assert cert.issuer == 'Example'
|
|
|
|
assert cert.name == 'long.lived.com-Example-20150626-20400101'
|
|
|
|
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = create(authority=authority, csr=CSR_STR, owner='joe@example.com', name='ACustomName1', creator=user['user'])
|
2016-05-20 18:03:34 +02:00
|
|
|
assert cert.name == 'ACustomName1'
|
|
|
|
|
|
|
|
|
2016-12-08 20:33:40 +01:00
|
|
|
def test_reissue_certificate(issuer_plugin, authority, certificate):
|
2016-11-18 20:27:46 +01:00
|
|
|
from lemur.certificates.service import reissue_certificate
|
|
|
|
new_cert = reissue_certificate(certificate)
|
|
|
|
assert new_cert
|
|
|
|
|
|
|
|
|
2016-05-20 18:03:34 +02:00
|
|
|
def test_create_csr():
|
|
|
|
from lemur.certificates.service import create_csr
|
|
|
|
|
2016-08-27 01:02:23 +02:00
|
|
|
csr, private_key = create_csr(owner='joe@example.com', common_name='ACommonName', organization='test', organizational_unit='Meters', country='US',
|
2016-12-02 00:41:53 +01:00
|
|
|
state='CA', location='Here', key_type='RSA2048')
|
2016-05-20 18:03:34 +02:00
|
|
|
assert csr
|
|
|
|
assert private_key
|
|
|
|
|
2017-01-28 06:05:25 +01:00
|
|
|
extensions = {'sub_alt_names': {'names': x509.SubjectAlternativeName([x509.DNSName('AnotherCommonName')])}}
|
2016-08-25 19:09:46 +02:00
|
|
|
csr, private_key = create_csr(owner='joe@example.com', common_name='ACommonName', organization='test', organizational_unit='Meters', country='US',
|
2016-12-02 00:41:53 +01:00
|
|
|
state='CA', location='Here', extensions=extensions, key_type='RSA2048')
|
2016-05-20 18:03:34 +02:00
|
|
|
assert csr
|
|
|
|
assert private_key
|
|
|
|
|
|
|
|
|
2016-11-18 20:27:46 +01:00
|
|
|
def test_import(user):
|
2016-05-20 18:03:34 +02:00
|
|
|
from lemur.certificates.service import import_certificate
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = import_certificate(body=INTERNAL_VALID_LONG_STR, chain=INTERNAL_VALID_SAN_STR, private_key=PRIVATE_KEY_STR, creator=user['user'])
|
|
|
|
assert str(cert.not_after) == '2040-01-01T20:30:52+00:00'
|
|
|
|
assert str(cert.not_before) == '2015-06-26T20:30:52+00:00'
|
2016-05-20 18:03:34 +02:00
|
|
|
assert cert.issuer == 'Example'
|
2017-03-09 22:09:20 +01:00
|
|
|
assert cert.name == 'long.lived.com-Example-20150626-20400101-2'
|
2016-05-20 18:03:34 +02:00
|
|
|
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = import_certificate(body=INTERNAL_VALID_LONG_STR, chain=INTERNAL_VALID_SAN_STR, private_key=PRIVATE_KEY_STR, owner='joe@example.com', name='ACustomName2', creator=user['user'])
|
2016-05-20 18:03:34 +02:00
|
|
|
assert cert.name == 'ACustomName2'
|
|
|
|
|
|
|
|
|
2016-11-18 20:27:46 +01:00
|
|
|
def test_upload(user):
|
2016-05-20 18:03:34 +02:00
|
|
|
from lemur.certificates.service import upload
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = upload(body=INTERNAL_VALID_LONG_STR, chain=INTERNAL_VALID_SAN_STR, private_key=PRIVATE_KEY_STR, owner='joe@example.com', creator=user['user'])
|
|
|
|
assert str(cert.not_after) == '2040-01-01T20:30:52+00:00'
|
|
|
|
assert str(cert.not_before) == '2015-06-26T20:30:52+00:00'
|
2016-05-20 18:03:34 +02:00
|
|
|
assert cert.issuer == 'Example'
|
2017-03-09 22:09:20 +01:00
|
|
|
assert cert.name == 'long.lived.com-Example-20150626-20400101-3'
|
2016-05-20 18:03:34 +02:00
|
|
|
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = upload(body=INTERNAL_VALID_LONG_STR, chain=INTERNAL_VALID_SAN_STR, private_key=PRIVATE_KEY_STR, owner='joe@example.com', name='ACustomName', creator=user['user'])
|
2016-07-28 22:08:24 +02:00
|
|
|
assert 'ACustomName' in cert.name
|
2016-05-20 18:03:34 +02:00
|
|
|
|
|
|
|
|
2016-10-09 02:04:54 +02:00
|
|
|
# verify upload with a private key as a str
|
2016-11-18 20:27:46 +01:00
|
|
|
def test_upload_private_key_str(user):
|
2016-10-09 02:04:54 +02:00
|
|
|
from lemur.certificates.service import upload
|
2016-11-18 20:27:46 +01:00
|
|
|
cert = upload(body=INTERNAL_VALID_LONG_STR, chain=INTERNAL_VALID_SAN_STR, private_key=PRIVATE_KEY_STR, owner='joe@example.com', name='ACustomName', creator=user['user'])
|
2016-10-09 02:04:54 +02:00
|
|
|
assert cert
|
|
|
|
|
|
|
|
|
2016-11-21 18:19:14 +01:00
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 200),
|
|
|
|
('', 401)
|
|
|
|
])
|
|
|
|
def test_certificate_get_private_key(client, token, status):
|
|
|
|
assert client.get(api.url_for(Certificates, certificate_id=1), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
@pytest.mark.parametrize("token,status", [
|
2016-05-20 18:03:34 +02:00
|
|
|
(VALID_USER_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 200),
|
2016-05-05 21:52:08 +02:00
|
|
|
('', 401)
|
|
|
|
])
|
|
|
|
def test_certificate_get(client, token, status):
|
|
|
|
assert client.get(api.url_for(Certificates, certificate_id=1), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
2017-04-27 18:13:04 +02:00
|
|
|
def test_certificate_get_body(client):
|
|
|
|
response_body = client.get(api.url_for(Certificates, certificate_id=1), headers=VALID_USER_HEADER_TOKEN).json
|
|
|
|
assert response_body['serial'] == "3E9"
|
|
|
|
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_post(client, token, status):
|
|
|
|
assert client.post(api.url_for(Certificates, certificate_id=1), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 400),
|
|
|
|
('', 401)
|
|
|
|
])
|
|
|
|
def test_certificate_put(client, token, status):
|
|
|
|
assert client.put(api.url_for(Certificates, certificate_id=1), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
2016-11-26 05:35:07 +01:00
|
|
|
def test_certificate_put_with_data(client, certificate, issuer_plugin):
|
|
|
|
resp = client.put(api.url_for(Certificates, certificate_id=certificate.id), data=json.dumps({'owner': 'bob@example.com', 'description': 'test', 'notify': True}), headers=VALID_ADMIN_HEADER_TOKEN)
|
|
|
|
assert resp.status_code == 200
|
|
|
|
|
|
|
|
|
2016-05-05 21:52:08 +02:00
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_delete(client, token, status):
|
|
|
|
assert client.delete(api.url_for(Certificates, certificate_id=1), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_patch(client, token, status):
|
|
|
|
assert client.patch(api.url_for(Certificates, certificate_id=1), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 200),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 200),
|
|
|
|
('', 401)
|
|
|
|
])
|
|
|
|
def test_certificates_get(client, token, status):
|
|
|
|
assert client.get(api.url_for(CertificatesList), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 400),
|
|
|
|
('', 401)
|
|
|
|
])
|
|
|
|
def test_certificates_post(client, token, status):
|
|
|
|
assert client.post(api.url_for(CertificatesList), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_put(client, token, status):
|
|
|
|
assert client.put(api.url_for(CertificatesList), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_delete(client, token, status):
|
|
|
|
assert client.delete(api.url_for(CertificatesList), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_patch(client, token, status):
|
|
|
|
assert client.patch(api.url_for(CertificatesList), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_credentials_post(client, token, status):
|
|
|
|
assert client.post(api.url_for(CertificatePrivateKey, certificate_id=1), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_credentials_put(client, token, status):
|
|
|
|
assert client.put(api.url_for(CertificatePrivateKey, certificate_id=1), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_credentials_delete(client, token, status):
|
|
|
|
assert client.delete(api.url_for(CertificatePrivateKey, certificate_id=1), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificate_credentials_patch(client, token, status):
|
|
|
|
assert client.patch(api.url_for(CertificatePrivateKey, certificate_id=1), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_upload_get(client, token, status):
|
|
|
|
assert client.get(api.url_for(CertificatesUpload), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 400),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 400),
|
|
|
|
('', 401)
|
|
|
|
])
|
|
|
|
def test_certificates_upload_post(client, token, status):
|
|
|
|
assert client.post(api.url_for(CertificatesUpload), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_upload_put(client, token, status):
|
|
|
|
assert client.put(api.url_for(CertificatesUpload), data={}, headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_upload_delete(client, token, status):
|
|
|
|
assert client.delete(api.url_for(CertificatesUpload), headers=token).status_code == status
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("token,status", [
|
|
|
|
(VALID_USER_HEADER_TOKEN, 405),
|
|
|
|
(VALID_ADMIN_HEADER_TOKEN, 405),
|
|
|
|
('', 405)
|
|
|
|
])
|
|
|
|
def test_certificates_upload_patch(client, token, status):
|
|
|
|
assert client.patch(api.url_for(CertificatesUpload), data={}, headers=token).status_code == status
|