2020-03-23 19:31:56 +01:00
|
|
|
"""Library tests."""
|
2020-03-24 12:08:27 +01:00
|
|
|
|
|
|
|
from pyicloud import base
|
|
|
|
from pyicloud.exceptions import PyiCloudFailedLoginException
|
|
|
|
from pyicloud.services.findmyiphone import FindMyiPhoneServiceManager, AppleDevice
|
|
|
|
|
|
|
|
|
|
|
|
AUTHENTICATED_USER = "authenticated_user"
|
|
|
|
REQUIRES_2SA_USER = "requires_2sa_user"
|
|
|
|
VALID_USERS = [AUTHENTICATED_USER, REQUIRES_2SA_USER]
|
|
|
|
|
|
|
|
|
|
|
|
class PyiCloudServiceMock(base.PyiCloudService):
|
|
|
|
"""Mocked PyiCloudService."""
|
2020-03-24 14:54:43 +01:00
|
|
|
|
2020-03-24 12:08:27 +01:00
|
|
|
def __init__(
|
2020-03-24 14:54:43 +01:00
|
|
|
self,
|
|
|
|
apple_id,
|
|
|
|
password=None,
|
|
|
|
cookie_directory=None,
|
|
|
|
verify=True,
|
|
|
|
client_id=None,
|
|
|
|
with_family=True,
|
|
|
|
):
|
|
|
|
base.PyiCloudService.__init__(
|
|
|
|
self, apple_id, password, cookie_directory, verify, client_id, with_family
|
|
|
|
)
|
2020-03-24 12:08:27 +01:00
|
|
|
base.FindMyiPhoneServiceManager = FindMyiPhoneServiceManagerMock
|
|
|
|
|
|
|
|
def authenticate(self):
|
2020-03-24 14:54:43 +01:00
|
|
|
if (
|
|
|
|
not self.user.get("apple_id")
|
|
|
|
or self.user.get("apple_id") not in VALID_USERS
|
|
|
|
):
|
|
|
|
raise PyiCloudFailedLoginException(
|
|
|
|
"Invalid email/password combination.", None
|
|
|
|
)
|
2020-03-24 12:08:27 +01:00
|
|
|
if not self.user.get("password") or self.user.get("password") != "valid_pass":
|
2020-03-24 14:54:43 +01:00
|
|
|
raise PyiCloudFailedLoginException(
|
|
|
|
"Invalid email/password combination.", None
|
|
|
|
)
|
|
|
|
|
|
|
|
self.params.update({"dsid": "ID"})
|
2020-03-24 12:08:27 +01:00
|
|
|
self._webservices = {
|
2020-03-24 14:54:43 +01:00
|
|
|
"account": {"url": "account_url",},
|
|
|
|
"findme": {"url": "findme_url",},
|
|
|
|
"calendar": {"url": "calendar_url",},
|
|
|
|
"contacts": {"url": "contacts_url",},
|
|
|
|
"reminders": {"url": "reminders_url",},
|
2020-03-24 12:08:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def requires_2sa(self):
|
|
|
|
return self.user["apple_id"] is REQUIRES_2SA_USER
|
|
|
|
|
|
|
|
@property
|
|
|
|
def trusted_devices(self):
|
2020-03-24 14:54:43 +01:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
"deviceType": "SMS",
|
|
|
|
"areaCode": "",
|
|
|
|
"phoneNumber": "*******58",
|
|
|
|
"deviceId": "1",
|
|
|
|
}
|
2020-03-24 12:08:27 +01:00
|
|
|
]
|
2020-03-24 14:54:43 +01:00
|
|
|
|
2020-03-24 12:08:27 +01:00
|
|
|
def send_verification_code(self, device):
|
|
|
|
return device
|
2020-03-24 14:54:43 +01:00
|
|
|
|
2020-03-24 12:08:27 +01:00
|
|
|
def validate_verification_code(self, device, code):
|
|
|
|
if not device or code != 0:
|
|
|
|
self.user["apple_id"] = AUTHENTICATED_USER
|
|
|
|
self.authenticate()
|
|
|
|
return not self.requires_2sa
|
|
|
|
|
|
|
|
|
|
|
|
IPHONE_DEVICE_ID = "X1x/X&x="
|
|
|
|
IPHONE_DEVICE = AppleDevice(
|
|
|
|
{
|
|
|
|
"msg": {
|
|
|
|
"strobe": False,
|
|
|
|
"userText": False,
|
|
|
|
"playSound": True,
|
|
|
|
"vibrate": True,
|
|
|
|
"createTimestamp": 1568031021347,
|
2020-03-24 14:54:43 +01:00
|
|
|
"statusCode": "200",
|
2020-03-24 12:08:27 +01:00
|
|
|
},
|
|
|
|
"canWipeAfterLock": True,
|
|
|
|
"baUUID": "",
|
|
|
|
"wipeInProgress": False,
|
|
|
|
"lostModeEnabled": False,
|
|
|
|
"activationLocked": True,
|
|
|
|
"passcodeLength": 6,
|
|
|
|
"deviceStatus": "200",
|
|
|
|
"deviceColor": "1-6-0",
|
|
|
|
"features": {
|
|
|
|
"MSG": True,
|
|
|
|
"LOC": True,
|
|
|
|
"LLC": False,
|
|
|
|
"CLK": False,
|
|
|
|
"TEU": True,
|
|
|
|
"LMG": False,
|
|
|
|
"SND": True,
|
|
|
|
"CLT": False,
|
|
|
|
"LKL": False,
|
|
|
|
"SVP": False,
|
|
|
|
"LST": True,
|
|
|
|
"LKM": False,
|
|
|
|
"WMG": True,
|
|
|
|
"SPN": False,
|
|
|
|
"XRM": False,
|
|
|
|
"PIN": False,
|
|
|
|
"LCK": True,
|
|
|
|
"REM": False,
|
|
|
|
"MCS": False,
|
|
|
|
"CWP": False,
|
|
|
|
"KEY": False,
|
|
|
|
"KPD": False,
|
2020-03-24 14:54:43 +01:00
|
|
|
"WIP": True,
|
2020-03-24 12:08:27 +01:00
|
|
|
},
|
|
|
|
"lowPowerMode": True,
|
|
|
|
"rawDeviceModel": "iPhone11,8",
|
|
|
|
"id": IPHONE_DEVICE_ID,
|
|
|
|
"remoteLock": None,
|
|
|
|
"isLocating": True,
|
|
|
|
"modelDisplayName": "iPhone",
|
|
|
|
"lostTimestamp": "",
|
|
|
|
"batteryLevel": 0.47999998927116394,
|
|
|
|
"mesg": None,
|
|
|
|
"locationEnabled": True,
|
|
|
|
"lockedTimestamp": None,
|
|
|
|
"locFoundEnabled": False,
|
2020-03-24 14:54:43 +01:00
|
|
|
"snd": {"createTimestamp": 1568031021347, "statusCode": "200"},
|
2020-03-24 12:08:27 +01:00
|
|
|
"fmlyShare": False,
|
|
|
|
"lostDevice": {
|
|
|
|
"stopLostMode": False,
|
|
|
|
"emailUpdates": False,
|
|
|
|
"userText": True,
|
|
|
|
"sound": False,
|
|
|
|
"ownerNbr": "",
|
|
|
|
"text": "",
|
|
|
|
"createTimestamp": 1558383841233,
|
2020-03-24 14:54:43 +01:00
|
|
|
"statusCode": "2204",
|
2020-03-24 12:08:27 +01:00
|
|
|
},
|
|
|
|
"lostModeCapable": True,
|
|
|
|
"wipedTimestamp": None,
|
|
|
|
"deviceDisplayName": "iPhone XR",
|
|
|
|
"prsId": None,
|
|
|
|
"audioChannels": [],
|
|
|
|
"locationCapable": True,
|
|
|
|
"batteryStatus": "NotCharging",
|
|
|
|
"trackingInfo": None,
|
|
|
|
"name": "Quentin's iPhone",
|
|
|
|
"isMac": False,
|
|
|
|
"thisDevice": False,
|
|
|
|
"deviceClass": "iPhone",
|
|
|
|
"location": {
|
|
|
|
"isOld": False,
|
|
|
|
"isInaccurate": False,
|
|
|
|
"altitude": 0.0,
|
|
|
|
"positionType": "GPS",
|
|
|
|
"latitude": 46.012345678,
|
|
|
|
"floorLevel": 0,
|
|
|
|
"horizontalAccuracy": 12.012345678,
|
|
|
|
"locationType": "",
|
|
|
|
"timeStamp": 1568827039692,
|
|
|
|
"locationFinished": False,
|
|
|
|
"verticalAccuracy": 0.0,
|
2020-03-24 14:54:43 +01:00
|
|
|
"longitude": 5.012345678,
|
2020-03-24 12:08:27 +01:00
|
|
|
},
|
|
|
|
"deviceModel": "iphoneXR-1-6-0",
|
|
|
|
"maxMsgChar": 160,
|
|
|
|
"darkWake": False,
|
2020-03-24 14:54:43 +01:00
|
|
|
"remoteWipe": None,
|
2020-03-24 12:08:27 +01:00
|
|
|
},
|
|
|
|
None,
|
|
|
|
None,
|
2020-03-24 14:54:43 +01:00
|
|
|
None,
|
2020-03-24 12:08:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
DEVICES = {
|
|
|
|
IPHONE_DEVICE_ID: IPHONE_DEVICE,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class FindMyiPhoneServiceManagerMock(FindMyiPhoneServiceManager):
|
|
|
|
"""Mocked FindMyiPhoneServiceManager."""
|
2020-03-24 14:54:43 +01:00
|
|
|
|
2020-03-24 12:08:27 +01:00
|
|
|
def __init__(self, service_root, session, params, with_family=False):
|
2020-03-24 14:54:43 +01:00
|
|
|
FindMyiPhoneServiceManager.__init__(
|
|
|
|
self, service_root, session, params, with_family
|
|
|
|
)
|
2020-03-24 12:08:27 +01:00
|
|
|
|
|
|
|
def refresh_client(self):
|
|
|
|
self._devices = DEVICES
|