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_successful_auth(self):
with vcr.use_cassette("tests/vcr_cassettes/successful_auth.yml"):
authenticate(
"jdoe@gmail.com",
"password1",
client_id="EC5646DE-9423-11E8-BF21-14109FE0B321",
)
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)
)
def test_failed_auth(self):
with vcr.use_cassette("tests/vcr_cassettes/failed_auth.yml"):
with self.assertRaises(
pyicloud_ipd.exceptions.PyiCloudFailedLoginException
) as context:
authenticate(
"bad_username",
"bad_password",
client_id="EC5646DE-9423-11E8-BF21-14109FE0B321",
)
self.assertTrue("Invalid email/password combination." in str(context.exception))
# because the logger instance is shared between tests.
logger.disabled = False
if log_level == "debug":
logger.setLevel(logging.DEBUG)
elif log_level == "info":
logger.setLevel(logging.INFO)
elif log_level == "error":
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,