Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_2sa_required(self):
with vcr.use_cassette("tests/vcr_cassettes/auth_requires_2sa.yml"):
with self.assertRaises(TwoStepAuthRequiredError) as context:
# To re-record this HTTP request,
# delete ./tests/vcr_cassettes/auth_requires_2sa.yml,
# put your actual credentials in here, run the test,
# and then replace with dummy credentials.
authenticate(
"jdoe@gmail.com",
"password1",
raise_error_on_2sa=True,
client_id="EC5646DE-9423-11E8-BF21-14109FE0B321",
)
self.assertTrue(
"Two-step/two-factor authentication is required!"
in str(context.exception)
)
logger.setLevel(logging.ERROR)
raise_error_on_2sa = (
smtp_username is not None
or notification_email is not None
or notification_script is not None
)
try:
icloud = authenticate(
username,
password,
cookie_directory,
raise_error_on_2sa,
client_id=os.environ.get("CLIENT_ID"),
)
except TwoStepAuthRequiredError:
if notification_script is not None:
subprocess.call([notification_script])
if smtp_username is not None or notification_email is not None:
send_2sa_notification(
smtp_username,
smtp_password,
smtp_host,
smtp_port,
smtp_no_tls,
notification_email,
)
exit(1)
# Default album is "All Photos", so this is the same as
# calling `icloud.photos.all`.
photos = icloud.photos.albums[album]
# and PyiCloud will attempt to retrieve from it's keyring
icloud = pyicloud_ipd.PyiCloudService(
username, password,
cookie_directory=cookie_directory,
client_id=client_id)
except pyicloud_ipd.exceptions.NoStoredPasswordAvailable:
# Prompt for password if not stored in PyiCloud's keyring
password = click.prompt("iCloud Password", hide_input=True)
icloud = pyicloud_ipd.PyiCloudService(
username, password,
cookie_directory=cookie_directory,
client_id=client_id)
if icloud.requires_2sa:
if raise_error_on_2sa:
raise TwoStepAuthRequiredError(
"Two-step/two-factor authentication is required!"
)
logger.info("Two-step/two-factor authentication is required!")
request_2sa(icloud, logger)
return icloud