Skip to content

Commit 97d0125

Browse files
committed
SDK-1229: Base64 encode issuance token as part of decoding from protobuffer
1 parent 1967a61 commit 97d0125

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

yoti_python_sdk/issuance_details.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22

33
from yoti_python_sdk import date_parser
4+
import base64
45

56

67
class IssuanceDetails(object):
78
def __init__(self, data_entry):
8-
self.__token = data_entry.issuance_token.decode()
9+
self.__token = base64.b64encode(data_entry.issuance_token)
910
self.__expiry_date = date_parser.datetime_with_microsecond(
1011
data_entry.issuing_attributes.expiry_date
1112
)

yoti_python_sdk/tests/share/test_extra_data.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from datetime import datetime
44
import os.path
5+
import base64
56

67
from yoti_python_sdk.share.extra_data import ExtraData
78
from yoti_python_sdk.tests import file_helper
@@ -24,7 +25,7 @@ def create_third_party_test_data(token_value, expiry_date, *definitions):
2425
issuing_attributes.definitions.extend([name])
2526

2627
attribute = ThirdPartyAttribute_pb2.ThirdPartyAttribute()
27-
attribute.issuance_token = str(token_value).encode("utf-8")
28+
attribute.issuance_token = token_value.encode("utf-8")
2829
attribute.issuing_attributes.MergeFrom(issuing_attributes)
2930

3031
data_entry = DataEntry_pb2.DataEntry()
@@ -66,7 +67,9 @@ def test_should_return_first_matching_third_party_attribute():
6667
create_extra_data([thirdparty_attribute1, thirdparty_attribute2])
6768
)
6869

69-
assert parsed_extra_data.attribute_issuance_details.token == "tokenValue1"
70+
assert parsed_extra_data.attribute_issuance_details.token == base64.b64encode(
71+
"tokenValue1".encode("utf-8")
72+
)
7073
assert (
7174
parsed_extra_data.attribute_issuance_details.attributes[0].name
7275
== "attributeName1"
@@ -79,7 +82,7 @@ def test_should_parse_multiple_issuing_attributes():
7982

8083
result = extra_data.attribute_issuance_details
8184
assert result is not None
82-
assert result.token == "someIssuanceToken"
85+
assert result.token == base64.b64encode("someIssuanceToken".encode("utf-8"))
8386
assert result.expiry_date == datetime(2019, 10, 15, 22, 4, 5, 123000)
8487
assert result.attributes[0].name == "com.thirdparty.id"
8588
assert result.attributes[1].name == "com.thirdparty.other_id"
@@ -103,7 +106,7 @@ def test_should_handle_no_issuing_attributes():
103106
extra_data = ExtraData(create_extra_data([thirdparty_attribute]))
104107

105108
result = extra_data.attribute_issuance_details
106-
assert result.token == "tokenValue"
109+
assert result.token == base64.b64encode(tokenValue.encode("utf-8"))
107110
assert len(result.attributes) == 0
108111

109112

@@ -116,6 +119,6 @@ def test_should_handle_no_issuing_attribute_definitions():
116119
extra_data = ExtraData(create_extra_data([thirdparty_attribute]))
117120

118121
result = extra_data.attribute_issuance_details
119-
assert result.token == tokenValue
122+
assert result.token == base64.b64encode(tokenValue.encode("utf-8"))
120123
assert result.expiry_date == expiry_date
121124
assert len(result.attributes) == 0

yoti_python_sdk/tests/test_issuance_details.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from yoti_python_sdk.protobuf.share_public_api import ThirdPartyAttribute_pb2
77
from yoti_python_sdk.protobuf.share_public_api import IssuingAttributes_pb2
88
from datetime import datetime
9+
import base64
910
import pytest
1011

1112
FIXTURES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures")
@@ -35,7 +36,9 @@ def test_should_parse_third_party_attribute_correctly():
3536
issuance_details = IssuanceDetails(proto)
3637

3738
assert issuance_details.attributes[0].name == "com.thirdparty.id"
38-
assert issuance_details.token == "someIssuanceToken"
39+
assert issuance_details.token == base64.b64encode(
40+
"someIssuanceToken".encode("utf-8")
41+
)
3942
assert issuance_details.expiry_date == datetime(2019, 10, 15, 22, 4, 5, 123000)
4043

4144

0 commit comments

Comments
 (0)