Skip to content

Commit c6556a0

Browse files
authored
Fix icon validation when base64data contains whitespace (#638)
Signed-off-by: Maurizio Porrato <[email protected]>
1 parent a76552b commit c6556a0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

operator-pipeline-images/operatorcert/static_tests/community/validations.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import binascii
66
import datetime
77
from base64 import b64decode
8+
import string
89
from typing import Any
910

1011
from dateutil.parser import isoparse
@@ -109,11 +110,13 @@ def validate_icon(value: Any) -> bool:
109110
if len(value) < 1:
110111
return False
111112
for icon in value:
112-
# base64data must contain valid base64 data
113-
if len(icon["base64data"]) < 4:
113+
# remove all whitespace from the base64 payload
114+
data = icon["base64data"].translate({ord(c): None for c in string.whitespace})
115+
# check that the content is valid base64 encoded data
116+
if len(data) < 4:
114117
return False
115118
try:
116-
_ = b64decode(icon["base64data"], validate=True)
119+
_ = b64decode(data, validate=True)
117120
except binascii.Error:
118121
return False
119122
# mediatype must be a supported image format

operator-pipeline-images/tests/static_tests/community/test_validations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def test_validate_list_of_dicts(
127127
([{"base64data": "", "mediatype": "image/png"}], False),
128128
([{"base64data": "foobar", "mediatype": "image/png"}], False),
129129
([{"base64data": "Zm9v", "mediatype": "text/plain"}], False),
130+
([{"base64data": "Zm^v", "mediatype": "image/png"}], False),
131+
([{"base64data": " Zm\n9v\n", "mediatype": "image/png"}], True),
130132
],
131133
indirect=False,
132134
ids=[
@@ -135,6 +137,8 @@ def test_validate_list_of_dicts(
135137
"Empty base64data",
136138
"Invalid base64data",
137139
"Invalid mediatype",
140+
"Invalid characters in base64data",
141+
"Whitespace in base64data",
138142
],
139143
)
140144
def test_validate_icon(value: Any, expected: bool) -> None:

0 commit comments

Comments
 (0)