From 05f4ae8e585f5d872a1099c6b1c2c588d8b245f7 Mon Sep 17 00:00:00 2001 From: Michael Treacher Date: Fri, 28 Apr 2017 02:13:04 +1000 Subject: [PATCH] Hexify cert serial (#763) * Hexify serial at the serialization layer * Fix for flakey test. Change test to test for uppercased string --- lemur/certificates/schemas.py | 8 +++++++- lemur/tests/test_certificates.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lemur/certificates/schemas.py b/lemur/certificates/schemas.py index 5a5e2985..3c19ea21 100644 --- a/lemur/certificates/schemas.py +++ b/lemur/certificates/schemas.py @@ -6,7 +6,7 @@ .. moduleauthor:: Kevin Glisson """ from flask import current_app -from marshmallow import fields, validate, validates_schema, post_load, pre_load +from marshmallow import fields, validate, validates_schema, post_load, pre_load, post_dump from marshmallow.exceptions import ValidationError from lemur.schemas import AssociatedAuthoritySchema, AssociatedDestinationSchema, AssociatedCertificateSchema, \ @@ -198,6 +198,12 @@ class CertificateOutputSchema(LemurOutputSchema): endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[]) replaced_by = fields.Nested(CertificateNestedOutputSchema, many=True, attribute='replaced') + @post_dump + def convert_serial_to_hex(self, data): + if data: + data['serial'] = hex(int(data['serial']))[2:].upper() + return data + class CertificateUploadInputSchema(CertificateCreationSchema): name = fields.String() diff --git a/lemur/tests/test_certificates.py b/lemur/tests/test_certificates.py index a7471a9e..5842299e 100644 --- a/lemur/tests/test_certificates.py +++ b/lemur/tests/test_certificates.py @@ -73,14 +73,14 @@ def test_authority_key_identifier_schema(): data, errors = AuthorityKeyIdentifierSchema().load(input_data) - assert data == { + assert sorted(data) == sorted({ 'use_key_identifier': True, 'use_authority_cert': True - } + }) assert not errors data, errors = AuthorityKeyIdentifierSchema().dumps(data) - assert data == json.dumps(input_data) + assert sorted(data) == sorted(json.dumps(input_data)) assert not errors @@ -364,6 +364,11 @@ def test_certificate_get(client, token, status): assert client.get(api.url_for(Certificates, certificate_id=1), headers=token).status_code == status +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" + + @pytest.mark.parametrize("token,status", [ (VALID_USER_HEADER_TOKEN, 405), (VALID_ADMIN_HEADER_TOKEN, 405),