From f8b4508ba04e19ae8f7564a819c390fe8a65a588 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Thu, 23 Jan 2020 15:46:29 +0000 Subject: [PATCH 01/11] SDK-1390: Update travis and sonar-project.properties to use Sonarcloud.io --- .travis.yml | 23 +++++++++++++++++++---- sonar-project.properties | 10 ++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index be2362de..5ce9e88e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,8 @@ git: depth: 1 jobs: + allow_failures: + - python: "3.8-dev" include: - &test stage: Test @@ -49,7 +51,20 @@ jobs: if: type = pull_request OR branch = master after_success: - coveralls - -matrix: - allow_failures: - - python: "3.8-dev" + - stage: Analyze + name: Sonarcloud + dist: trusty + python: "3.7" + addons: + sonarcloud: + organization: "getyoti" + token: + secure: "rqiy5kLHuXPRZjWCg/DOt3x81nLvDoVLjtkzrzC7EPYSUiJQ+B/f+dMOLphhapnZ4wEQT1diM7R/XhEhEPRsXxCJuHJC5wERTiURw6jCjIMlfVM1vzq2W45nPKdzEjMDFi1XtaB0rQOP3eB6xAYQ84hJ17i7+fty9tTIembBOIZmJsA69QXODOUPJfUy/TlcS+GHml584xY4VEc2w8+O0sq7NOQoYsScHrwxyR6uQCXaeSgGFz6C6b3URqXe6559P2jttJc4+8JwG/GYRxU/8Gvtoh4DZcRivcWDfjoBirz8Cz95Pl224FxGeyitKuNWPFWQb3o2hgVkR2bOKOasHUvZuT6eOk6i+YnvltZZJimSZ5fX6bvR4t35YXYqXdEDSkOzZmHolGW9bj9LSYJphY+1ODVWjRycRV96nU2x42ueeTG9ZCW9ZnlWGgplo8X6KJDmhs5k6++Y7Q40DuYrmwYWxZXyBOkrMrUHCV7rpreRov+2NoOUuU8Dq4uBdIKn8truxPLAERFWrGIO5ti+TXPQ/ttGL+d47QhDBXhGKa0qUVRFq1W6CY1AgNCtxfG842eQzSNvV5am/4zZVWEwRbuIMDaceNagpLIDy4iEeEdwZXT2B8xZVt2rePWd7Qxk7UDD+s9/RYFLyOSDNcmmmguLej9gyTlBMrLFCvLcsnk=" + install: + - pip install -r requirements.txt + - pip install -e .[dev] + script: + - pytest --cov=yoti_python_sdk yoti_python_sdk/tests + if: type = pull_request OR brnch = master + after_success: + - sonar-scanner diff --git a/sonar-project.properties b/sonar-project.properties index c02c71b4..97648491 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,9 @@ -sonar.projectKey = yoti-web-sdk:python -sonar.projectName = python-sdk +sonar.host.url = https://sonarcloud.io +sonar.organization = getyoti +sonar.projectKey = getyoti:python +sonar.projectName = Python SDK sonar.projectVersion = 2.10.0 -sonar.exclusions=yoti_python_sdk/tests/**,examples/** +sonar.exclusions = yoti_python_sdk/tests/**,examples/** -sonar.python.pylint.reportPath=coverage.out +sonar.python.pylint.reportPath = coverage.out sonar.verbose = true From 4b51c0b164eac908a7193be5dccf725e834366ed Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Thu, 23 Jan 2020 17:42:05 +0000 Subject: [PATCH 02/11] SDK-1390: Pin PyYAML version for support with Python 3.4 --- .travis.yml | 7 ++----- requirements.in | 1 + requirements.txt | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ce9e88e..36ce7cd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,17 +54,14 @@ jobs: - stage: Analyze name: Sonarcloud dist: trusty - python: "3.7" + python: "3.6.1" addons: sonarcloud: organization: "getyoti" - token: - secure: "rqiy5kLHuXPRZjWCg/DOt3x81nLvDoVLjtkzrzC7EPYSUiJQ+B/f+dMOLphhapnZ4wEQT1diM7R/XhEhEPRsXxCJuHJC5wERTiURw6jCjIMlfVM1vzq2W45nPKdzEjMDFi1XtaB0rQOP3eB6xAYQ84hJ17i7+fty9tTIembBOIZmJsA69QXODOUPJfUy/TlcS+GHml584xY4VEc2w8+O0sq7NOQoYsScHrwxyR6uQCXaeSgGFz6C6b3URqXe6559P2jttJc4+8JwG/GYRxU/8Gvtoh4DZcRivcWDfjoBirz8Cz95Pl224FxGeyitKuNWPFWQb3o2hgVkR2bOKOasHUvZuT6eOk6i+YnvltZZJimSZ5fX6bvR4t35YXYqXdEDSkOzZmHolGW9bj9LSYJphY+1ODVWjRycRV96nU2x42ueeTG9ZCW9ZnlWGgplo8X6KJDmhs5k6++Y7Q40DuYrmwYWxZXyBOkrMrUHCV7rpreRov+2NoOUuU8Dq4uBdIKn8truxPLAERFWrGIO5ti+TXPQ/ttGL+d47QhDBXhGKa0qUVRFq1W6CY1AgNCtxfG842eQzSNvV5am/4zZVWEwRbuIMDaceNagpLIDy4iEeEdwZXT2B8xZVt2rePWd7Qxk7UDD+s9/RYFLyOSDNcmmmguLej9gyTlBMrLFCvLcsnk=" install: - pip install -r requirements.txt - pip install -e .[dev] script: - pytest --cov=yoti_python_sdk yoti_python_sdk/tests - if: type = pull_request OR brnch = master - after_success: - sonar-scanner + if: type = pull_request OR branch = master diff --git a/requirements.in b/requirements.in index b4152e92..48eb17ae 100644 --- a/requirements.in +++ b/requirements.in @@ -7,6 +7,7 @@ itsdangerous==0.24 pbr==1.10.0 protobuf==3.7.0 pyopenssl==18.0.0 +PyYAML==5.2 # Support for Python 3.4 pytz==2018.9 requests>=2.20.0 urllib3>=1.24.2 diff --git a/requirements.txt b/requirements.txt index 53658733..32904d2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,6 +20,7 @@ protobuf==3.7.0 pycparser==2.18 # via cffi pyopenssl==18.0.0 pytz==2018.9 +pyyaml==5.2 requests==2.21.0 six==1.10.0 # via cryptography, protobuf, pyopenssl urllib3==1.24.2 @@ -27,4 +28,4 @@ wheel==0.24.0 wrapt==1.11.2 # via deprecated # The following packages are considered to be unsafe in a requirements file: -# setuptools==41.4.0 # via protobuf +# setuptools==43.0.0 # via protobuf From 14eaaec4f35db2a2b246fd93aaa1d90204bc0b78 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Fri, 24 Jan 2020 11:38:19 +0000 Subject: [PATCH 03/11] SDK-1390: Add generation of coverage report --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 36ce7cd9..f24574f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ dist: xenial # Only clone the most recent commit. git: - depth: 1 + depth: false jobs: allow_failures: @@ -62,6 +62,7 @@ jobs: - pip install -r requirements.txt - pip install -e .[dev] script: - - pytest --cov=yoti_python_sdk yoti_python_sdk/tests + - pytest --cov=yoti_python_sdk yoti_python_sdk/tests --cov-report=xml:coverage-reports/coverage-new.xml + - sed -i 's+.*+/home/travis/build/getyoti/yoti-python-sdk/yoti_python_sdk+g' coverage-reports/coverage-new.xml - sonar-scanner if: type = pull_request OR branch = master From dcb1c35a5e1d60470c37a8d367798ebd7eaebc6a Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Fri, 24 Jan 2020 14:20:57 +0000 Subject: [PATCH 04/11] SDK-1390: Pin version of coverage --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 5b209ab8..8d5fe232 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ "pylint==1.9.4", "pylint-exit>=1.1.0", "python-coveralls==2.9.3", + "coverage==4.5.4", "mock==2.0.0", "virtualenv==15.2", ], From 219e83a55dd93d12c17a6759ed33649bda83e8df Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Fri, 7 Feb 2020 10:28:07 +0000 Subject: [PATCH 05/11] SDK-1390: Remove generated protobuf files from analysis --- .coveragerc | 1 + sonar-project.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index bbd92e24..51873f2a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,5 @@ [run] omit = yoti_python_sdk/tests/** + yoti_python_sdk/protobuf/**/* examples/** \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index 97648491..2835c8bc 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.organization = getyoti sonar.projectKey = getyoti:python sonar.projectName = Python SDK sonar.projectVersion = 2.10.0 -sonar.exclusions = yoti_python_sdk/tests/**,examples/** +sonar.exclusions = yoti_python_sdk/tests/**,examples/**,yoti_python_sdk/protobuf/**/* sonar.python.pylint.reportPath = coverage.out sonar.verbose = true From 79e703dda012fea0241977f156c7458f9302a9ec Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 10 Feb 2020 09:47:59 +0000 Subject: [PATCH 06/11] SDK-1390: Update requirements.in with descriptive comment --- requirements.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.in b/requirements.in index 48eb17ae..479122b4 100644 --- a/requirements.in +++ b/requirements.in @@ -7,7 +7,7 @@ itsdangerous==0.24 pbr==1.10.0 protobuf==3.7.0 pyopenssl==18.0.0 -PyYAML==5.2 # Support for Python 3.4 +PyYAML==5.2 # PyYAML 5.3 does not support Python 3.4 pytz==2018.9 requests>=2.20.0 urllib3>=1.24.2 From 872b20503be8ac6de969240490d7b15e7734547c Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Tue, 11 Feb 2020 17:00:38 +0000 Subject: [PATCH 07/11] SDK-1443: Remove regex validation from document details Support for parsing redacted aadhaar numbers --- yoti_python_sdk/document_details.py | 13 +----- .../tests/test_document_details.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/yoti_python_sdk/document_details.py b/yoti_python_sdk/document_details.py index aa637b64..21c3cbd2 100644 --- a/yoti_python_sdk/document_details.py +++ b/yoti_python_sdk/document_details.py @@ -1,14 +1,9 @@ # -*- coding: utf-8 -*- -import re - from . import date_parser class DocumentDetails(object): - VALIDATION_REGEX = re.compile("^[A-Za-z_]* [A-Za-z]{3} [A-Za-z0-9]{1}.*$") - def __init__(self, data): - self.__validate_data(data) self.__parse_data(data) @property @@ -31,14 +26,10 @@ def expiration_date(self): def issuing_authority(self): return self.__dict__.get("_DocumentDetails__issuing_authority", None) - def __validate_data(self, data): - if self.VALIDATION_REGEX.search(data): - return - else: - raise ValueError("Invalid value for DocumentDetails") - def __parse_data(self, data): data = data.split() + if len(data) < 3: + raise ValueError("Invalid value for DocumentDetails") self.__document_type = data[0] self.__issuing_country = data[1] diff --git a/yoti_python_sdk/tests/test_document_details.py b/yoti_python_sdk/tests/test_document_details.py index 20701dd5..1dc6f26b 100644 --- a/yoti_python_sdk/tests/test_document_details.py +++ b/yoti_python_sdk/tests/test_document_details.py @@ -34,6 +34,40 @@ def test_parse_3_words(): assert document.issuing_authority is None +def test_parse_redacted_aadhaar(): + DATA = "AADHAAR IND ****1234" + + document = DocumentDetails(DATA) + + assert document.document_type == "AADHAAR" + assert document.issuing_country == "IND" + assert document.document_number == "****1234" + assert document.expiration_date is None + assert document.issuing_authority is None + + +@pytest.mark.parametrize( + "details, expected_number", + [ + ("type country **** - authority", "****"), + ( + "type country ~!@#$%^&*()-_=+[]{}|;':,./<>? - authority", + "~!@#$%^&*()-_=+[]{}|;':,./<>?", + ), + ('type country "" - authority', '""'), + ("type country \\ - authority", "\\"), + ('type country " - authority', '"'), + ("type country '' - authority", "''"), + ("type country ' - authority", "'"), + ], +) +def test_parse_special_characters(details, expected_number): + document = DocumentDetails(details) + + assert document.document_type == "type" + assert document.document_number == expected_number + + def test_parse_4_words(): DATA = "DRIVING_LICENCE GBR 1234abc 2016-05-01" @@ -88,3 +122,12 @@ def test_invalid_date(): with pytest.raises(ValueError) as exc: DocumentDetails(DATA) assert str(exc.value) == "Invalid value for DocumentDetails" + + +def test_should_parse_with_double_space(): + DATA = "AADHAAR IND ****1234" + + document = DocumentDetails(DATA) + + assert document.document_type == "AADHAAR" + assert document.document_number == "****1234" From 2b588a2d44836b5b3b45ca162a651e8532b4c558 Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Wed, 19 Feb 2020 17:30:42 +0000 Subject: [PATCH 08/11] SDK-1443: Modify empty string test to demonstrate a failure case --- yoti_python_sdk/tests/test_document_details.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/yoti_python_sdk/tests/test_document_details.py b/yoti_python_sdk/tests/test_document_details.py index 1dc6f26b..89695416 100644 --- a/yoti_python_sdk/tests/test_document_details.py +++ b/yoti_python_sdk/tests/test_document_details.py @@ -124,10 +124,9 @@ def test_invalid_date(): assert str(exc.value) == "Invalid value for DocumentDetails" -def test_should_parse_with_double_space(): - DATA = "AADHAAR IND ****1234" +def test_should_fail_with_double_space(): + DATA = " IND ****1234" - document = DocumentDetails(DATA) - - assert document.document_type == "AADHAAR" - assert document.document_number == "****1234" + with pytest.raises(ValueError) as exc: + DocumentDetails(DATA) + assert str(exc.value) == "Invalid value for DocumentDetails" From 34fb258fa92b12eeceed38aa84c3d82dc4b890aa Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Wed, 19 Feb 2020 18:20:35 +0000 Subject: [PATCH 09/11] SDK-1443: Split only on space, not whitespace and check for empty string --- yoti_python_sdk/document_details.py | 4 ++-- yoti_python_sdk/tests/test_document_details.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yoti_python_sdk/document_details.py b/yoti_python_sdk/document_details.py index 21c3cbd2..06de6d22 100644 --- a/yoti_python_sdk/document_details.py +++ b/yoti_python_sdk/document_details.py @@ -27,8 +27,8 @@ def issuing_authority(self): return self.__dict__.get("_DocumentDetails__issuing_authority", None) def __parse_data(self, data): - data = data.split() - if len(data) < 3: + data = data.split(" ") + if len(data) < 3 or "" in data: raise ValueError("Invalid value for DocumentDetails") self.__document_type = data[0] diff --git a/yoti_python_sdk/tests/test_document_details.py b/yoti_python_sdk/tests/test_document_details.py index 89695416..7cbc8a5f 100644 --- a/yoti_python_sdk/tests/test_document_details.py +++ b/yoti_python_sdk/tests/test_document_details.py @@ -125,7 +125,7 @@ def test_invalid_date(): def test_should_fail_with_double_space(): - DATA = " IND ****1234" + DATA = "AADHAAR IND ****1234" with pytest.raises(ValueError) as exc: DocumentDetails(DATA) From 3ad86ec6bdeb617c1eac6101e0c13334658b785b Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Fri, 21 Feb 2020 11:14:59 +0000 Subject: [PATCH 10/11] Update version number to 2.10.1 --- sonar-project.properties | 2 +- yoti_python_sdk/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 2835c8bc..12c5d404 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.host.url = https://sonarcloud.io sonar.organization = getyoti sonar.projectKey = getyoti:python sonar.projectName = Python SDK -sonar.projectVersion = 2.10.0 +sonar.projectVersion = 2.10.1 sonar.exclusions = yoti_python_sdk/tests/**,examples/**,yoti_python_sdk/protobuf/**/* sonar.python.pylint.reportPath = coverage.out diff --git a/yoti_python_sdk/version.py b/yoti_python_sdk/version.py index f86f175b..6f7b7c7d 100644 --- a/yoti_python_sdk/version.py +++ b/yoti_python_sdk/version.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -__version__ = "2.10.0" +__version__ = "2.10.1" From a022515f1b9ce093e7104a48a1f4ab36ececa568 Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Fri, 21 Feb 2020 11:43:24 +0000 Subject: [PATCH 11/11] Remove misleading comment from travis file --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f24574f2..412f3df2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python dist: xenial -# Only clone the most recent commit. git: depth: false