From 22c1a298928bcdc70da102c88971fb5ca5657814 Mon Sep 17 00:00:00 2001 From: Antoine Legrand Date: Fri, 24 Mar 2017 19:43:23 +0100 Subject: [PATCH] fix strip_sha256 --- data/interfaces/appr.py | 5 ++++- data/interfaces/test/test_appr.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 data/interfaces/test/test_appr.py diff --git a/data/interfaces/appr.py b/data/interfaces/appr.py index 5d18316ff..dd140a014 100644 --- a/data/interfaces/appr.py +++ b/data/interfaces/appr.py @@ -429,6 +429,9 @@ class OCIAppModel(AppRegistryDataInterface): def _strip_sha256_header(digest): - return digest.lstrip('sha256:') + if digest.startswith('sha256:'): + return digest.split('sha256:')[1] + return digest + oci_app_model = OCIAppModel() diff --git a/data/interfaces/test/test_appr.py b/data/interfaces/test/test_appr.py new file mode 100644 index 000000000..e33db96d5 --- /dev/null +++ b/data/interfaces/test/test_appr.py @@ -0,0 +1,9 @@ +import pytest +from data.interfaces.appr import _strip_sha256_header + + +@pytest.mark.parametrize('digest,expected', [ + ('sha256:251b6897608fb18b8a91ac9abac686e2e95245d5a041f2d1e78fe7a815e6480a', '251b6897608fb18b8a91ac9abac686e2e95245d5a041f2d1e78fe7a815e6480a'), + ('251b6897608fb18b8a91ac9abac686e2e95245d5a041f2d1e78fe7a815e6480a', '251b6897608fb18b8a91ac9abac686e2e95245d5a041f2d1e78fe7a815e6480a'),]) +def test_stip_sha256(digest, expected): + assert _strip_sha256_header(digest) == expected