From 4e3736b6667e94f14f360a4edeaacb477877efb1 Mon Sep 17 00:00:00 2001 From: Expl0dingBanana Date: Sat, 19 Sep 2020 08:15:50 -0400 Subject: [PATCH] Fix PD Case Sensitivity * Remove converting PD login to lowercase * Update PogoAuth for google to convert to lowercase --- mapadroid/data_manager/modules/pogoauth.py | 6 ++++++ mapadroid/tests/api/test_pogoauth.py | 13 +++++++++++++ mapadroid/tests/test_autoconfig.py | 7 ++++--- mapadroid/utils/autoconfig.py | 4 ---- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/mapadroid/data_manager/modules/pogoauth.py b/mapadroid/data_manager/modules/pogoauth.py index 77064ae89..ef0e5644c 100644 --- a/mapadroid/data_manager/modules/pogoauth.py +++ b/mapadroid/data_manager/modules/pogoauth.py @@ -102,6 +102,12 @@ def get_dependencies(self) -> List[Tuple[str, int]]: dependencies[ind] = ('device', device_id) return dependencies + def save(self, core_data=None, force_insert=False, ignore_issues=[], **kwargs): + self.presave_validation(ignore_issues=ignore_issues) + if self["login_type"] == "google": + self["username"] = self["username"].lower() + return super().save(force_insert=force_insert, ignore_issues=ignore_issues) + def validate_custom(self): issues = [] if 'device_id' in self and self['device_id'] is not None: diff --git a/mapadroid/tests/api/test_pogoauth.py b/mapadroid/tests/api/test_pogoauth.py index 80db16a2e..1b33c64c6 100644 --- a/mapadroid/tests/api/test_pogoauth.py +++ b/mapadroid/tests/api/test_pogoauth.py @@ -73,3 +73,16 @@ def test_device_dependency(self): response = self.api.delete(pogoauth_obj['uri']) self.assertEqual(response.status_code, 412) self.remove_resources() + + def test_case_sensitivity_google(self): + payload = copy.copy(APIPogoAuth.base_payload) + payload["username"] = "POGOAUTH@gmail.com" + elem, response = self.creator.create_valid_resource("pogoauth", payload=payload) + self.assertTrue(response.json()["username"] == payload["username"].lower()) + + def test_case_sensitivity_ptc(self): + payload = copy.copy(APIPogoAuth.base_payload) + payload["username"] = "POGOAUTH" + payload["login_type"] = "ptc" + elem, response = self.creator.create_valid_resource("pogoauth", payload=payload) + self.assertTrue(response.json()["username"] == payload["username"]) diff --git a/mapadroid/tests/test_autoconfig.py b/mapadroid/tests/test_autoconfig.py index 49aa26e66..5ffd5eb70 100644 --- a/mapadroid/tests/test_autoconfig.py +++ b/mapadroid/tests/test_autoconfig.py @@ -2,7 +2,7 @@ from functools import wraps import json from typing import Any -from unittest import TestCase +import unittest from mapadroid.tests.test_utils import get_connection_api, get_connection_mitm, ResourceCreator, GetStorage from mapadroid.utils.walkerArgs import parse_args from mapadroid.utils.autoconfig import AutoConfIssues @@ -86,7 +86,7 @@ def decorated(self, *args, **kwargs): return decorated -class MITMAutoConf(TestCase): +class MITMAutoConf(unittest.TestCase): def setUp(self): self.api = get_connection_api() self.mitm = get_connection_mitm(self.api) @@ -262,10 +262,11 @@ def test_workflow_assigned_device(self, session_id, dev_info, ss_info, api_creat self.assertTrue(res.status_code == 200) res = self.mitm.get('/autoconfig/{}/google'.format(session_id)) self.assertTrue(res.status_code == 200) - self.assertTrue(res.content == b'Unit\nTest') + self.assertTrue(res.content == b'unit\nTest') res = self.mitm.delete('/autoconfig/{}/complete'.format(session_id)) self.assertTrue(res.status_code == 200) + @unittest.skip("PD emails are case sensitive") def test_lower_case(self): api_creator = ResourceCreator(self.api) with GetStorage(self.api): diff --git a/mapadroid/utils/autoconfig.py b/mapadroid/utils/autoconfig.py index 3ad5929e5..4bbae8100 100644 --- a/mapadroid/utils/autoconfig.py +++ b/mapadroid/utils/autoconfig.py @@ -264,10 +264,6 @@ def validate(self, user_vals: dict) -> bool: invalid.append((self.host_field, "Routable address from outside the server")) except KeyError: pass - try: - self.contents['user_id'] = self.contents['user_id'].lower() - except KeyError: - pass issues = {} if missing: issues['missing'] = missing