本文整理汇总了Python中smtpmock.setdata函数的典型用法代码示例。如果您正苦于以下问题:Python setdata函数的具体用法?Python setdata怎么用?Python setdata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setdata函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_03_set_new_password
def test_03_set_new_password(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")})
# Get the recovery code
recoverycode = "reccode"
new_password = "topsecret"
user = User("corneliusReg", "register")
r = create_recoverycode(user, recoverycode=recoverycode)
self.assertEqual(r, True)
# Use the recoverycode to set a new password
with self.app.test_request_context(
"/recover/reset",
method="POST",
data={"user": "corneliusReg", "realm": "register", "recoverycode": recoverycode, "password": new_password},
):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res.data)
data = json.loads(res.data)
self.assertEqual(data.get("result").get("value"), True)
# send an invalid recoverycode
with self.app.test_request_context(
"/recover/reset",
method="POST",
data={"user": "corneliusReg", "realm": "register", "recoverycode": "asdf", "password": new_password},
):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res.data)
data = json.loads(res.data)
self.assertEqual(data.get("result").get("value"), False)
开发者ID:ask0n,项目名称:privacyidea,代码行数:29,代码来源:test_api_register.py
示例2: test_19_emailtext
def test_19_emailtext(self):
# create a EMAILTEXT policy:
p = set_policy(name="emailtext",
action="%s=%s" % (EMAILACTION.EMAILTEXT, "'Your <otp>'"),
scope=SCOPE.AUTH)
self.assertTrue(p > 0)
g = FakeFlaskG()
P = PolicyClass()
g.policy_object = P
options = {"g": g}
smtpmock.setdata(response={"[email protected]": (200, "OK")})
transactionid = "123456098713"
db_token = Token.query.filter_by(serial=self.serial1).first()
token = EmailTokenClass(db_token)
c = token.create_challenge(transactionid, options=options)
self.assertTrue(c[0], c)
display_message = c[1]
self.assertTrue(c[3].get("state"), transactionid)
self.assertEqual(display_message, "Enter the OTP from the Email:")
# Test AUTOEMAIL
p = set_policy(name="autoemail",
action=EMAILACTION.EMAILAUTO,
scope=SCOPE.AUTH)
self.assertTrue(p > 0)
g = FakeFlaskG()
P = PolicyClass()
g.policy_object = P
options = {"g": g}
r = token.check_otp("287922", options=options)
self.assertTrue(r > 0, r)
开发者ID:Reality9,项目名称:privacyidea,代码行数:34,代码来源:test_lib_tokens_email.py
示例3: test_19_emailtext
def test_19_emailtext(self):
# create a EMAILTEXT policy:
p = set_policy(name="emailtext",
action="{0!s}={1!s}".format(EMAILACTION.EMAILTEXT, "'Your <otp>'"),
scope=SCOPE.AUTH)
self.assertTrue(p > 0)
g = FakeFlaskG()
P = PolicyClass()
g.policy_object = P
options = {"g": g}
smtpmock.setdata(response={"[email protected]": (200, "OK")})
transactionid = "123456098713"
db_token = Token.query.filter_by(serial=self.serial1).first()
token = EmailTokenClass(db_token)
c = token.create_challenge(transactionid, options=options)
self.assertTrue(c[0], c)
display_message = c[1]
self.assertTrue(c[3].get("state"), transactionid)
self.assertEqual(display_message, "Enter the OTP from the Email:")
_, mimetype = token._get_email_text_or_subject(options, EMAILACTION.EMAILTEXT)
self.assertEqual(mimetype, "plain")
# Test AUTOEMAIL
p = set_policy(name="autoemail",
action=EMAILACTION.EMAILAUTO,
scope=SCOPE.AUTH)
self.assertTrue(p > 0)
g = FakeFlaskG()
P = PolicyClass()
g.policy_object = P
options = {"g": g}
r = token.check_otp("287922", options=options)
self.assertTrue(r > 0, r)
# create a EMAILTEXT policy with template
p = set_policy(name="emailtext",
action="{0!s}=file:{1!s}".format(EMAILACTION.EMAILTEXT, TEMPLATE_FILE),
scope=SCOPE.AUTH)
self.assertTrue(p > 0)
g = FakeFlaskG()
P = PolicyClass()
g.policy_object = P
options = {"g": g}
smtpmock.setdata(response={"[email protected]": (200, "OK")})
transactionid = "123456098714"
db_token = Token.query.filter_by(serial=self.serial1).first()
token = EmailTokenClass(db_token)
email_text, mimetype = token._get_email_text_or_subject(options, EMAILACTION.EMAILTEXT)
self.assertTrue("<p>Hello,</p>" in email_text)
self.assertEqual(mimetype, "html")
c = token.create_challenge(transactionid, options=options)
self.assertTrue(c[0], c)
display_message = c[1]
self.assertTrue(c[3].get("state"), transactionid)
self.assertEqual(display_message, "Enter the OTP from the Email:")
开发者ID:hrz-unimr,项目名称:privacyidea,代码行数:59,代码来源:test_lib_tokens_email.py
示例4: test_21_test_email_config
def test_21_test_email_config(self):
from privacyidea.lib.tokens.emailtoken import TEST_SUCCESSFUL
smtpmock.setdata(response={"[email protected]": (200, "OK")})
r = EmailTokenClass.test_config({"email.mailserver": "mail.example.com",
"email.mailfrom": "[email protected]",
"email.recipient": "[email protected]"})
self.assertEqual(r[0], True)
self.assertEqual(r[1], TEST_SUCCESSFUL)
开发者ID:Andrew8305,项目名称:privacyidea,代码行数:8,代码来源:test_lib_tokens_email.py
示例5: test_20_sending_email_exception
def test_20_sending_email_exception(self):
smtpmock.setdata(exception=True)
transactionid = "123456098712"
db_token = Token.query.filter_by(serial=self.serial1).first()
token = EmailTokenClass(db_token)
c = token.create_challenge(transactionid)
self.assertFalse(c[0])
self.assertEqual(c[1], "The PIN was correct, but the EMail could not "
"be sent: SMTPException(u'MOCK TLS ERROR',)")
开发者ID:Reality9,项目名称:privacyidea,代码行数:9,代码来源:test_lib_tokens_email.py
示例6: test_13_challenge_response_email
def test_13_challenge_response_email(self):
smtpmock.setdata(response={})
# set a chalresp policy for Email
with self.app.test_request_context('/policy/pol_chal_resp',
data={'action':
"challenge_response=email",
'scope': "authentication",
'realm': '',
'active': True},
method='POST',
headers={'Authorization': self.at}):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res)
result = json.loads(res.data).get("result")
self.assertTrue(result["status"] is True, result)
self.assertTrue('"setPolicy pol_chal_resp": 1' in res.data,
res.data)
serial = "CHALRESP3"
pin = "chalresp3"
# create a token and assign to the user
init_token({"serial": serial,
"type": "email",
"otpkey": self.otpkey,
"email": "[email protected]",
"pin": pin}, user=User("cornelius", self.realm1))
# create the challenge by authenticating with the OTP PIN
with self.app.test_request_context('/validate/check',
method='POST',
data={"user": "cornelius",
"pass": pin}):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res)
result = json.loads(res.data).get("result")
detail = json.loads(res.data).get("detail")
self.assertFalse(result.get("value"))
self.assertEqual(detail.get("message"), "Enter the OTP from the "
"Email:")
transaction_id = detail.get("transaction_id")
# send the OTP value
# Test with parameter state.
with self.app.test_request_context('/validate/check',
method='POST',
data={"user": "cornelius",
"state":
transaction_id,
"pass": "359152"}):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res)
result = json.loads(res.data).get("result")
detail = json.loads(res.data).get("detail")
self.assertTrue(result.get("value"))
# delete the token
remove_token(serial=serial)
开发者ID:Keithsc,项目名称:privacyidea,代码行数:56,代码来源:test_api_validate.py
示例7: test_02_reset_password
def test_02_reset_password(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")})
set_privacyidea_config("recovery.identifier", "myserver")
with self.app.test_request_context(
"/recover",
method="POST",
data={"user": "corneliusReg", "realm": "register", "email": "[email protected]"},
):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res.data)
data = json.loads(res.data)
self.assertEqual(data.get("result").get("value"), True)
开发者ID:ask0n,项目名称:privacyidea,代码行数:12,代码来源:test_api_register.py
示例8: test_01_create_recovery
def test_01_create_recovery(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")})
# missing configuration
self.assertRaises(privacyIDEAError, create_recoverycode,
user=User("cornelius", self.realm1))
# recover password with "recovery.identifier"
r = add_smtpserver(identifier="myserver", server="1.2.3.4")
self.assertTrue(r > 0)
set_privacyidea_config("recovery.identifier", "myserver")
r = create_recoverycode(User("cornelius", self.realm1))
self.assertEqual(r, True)
开发者ID:STRML,项目名称:privacyidea,代码行数:13,代码来源:test_lib_recovery.py
示例9: test_02_check_recoverycode
def test_02_check_recoverycode(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")})
recoverycode = "reccode"
user = User("cornelius", self.realm1)
r = create_recoverycode(user, recoverycode=recoverycode)
self.assertEqual(r, True)
r = check_recoverycode(user, recoverycode)
self.assertEqual(r, True)
# The recovery code is not valid a second time
r = check_recoverycode(user, recoverycode)
self.assertEqual(r, False)
开发者ID:STRML,项目名称:privacyidea,代码行数:13,代码来源:test_lib_recovery.py
示例10: test_02_send_email
def test_02_send_email(self):
r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=False)
self.assertTrue(r > 0)
server = get_smtpserver("myserver")
smtpmock.setdata(response={"[email protected]": (200, "OK")},
support_tls=False)
r = server.send_email(["[email protected]"], "Hallo", "Body")
self.assertEqual(r, True)
smtpmock.setdata(response={"[email protected]": (550,
"Message rejected")},
support_tls=False)
r = server.send_email(["[email protected]"], "Hallo", "Body")
self.assertEqual(r, False)
# Use TLS
r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=True)
self.assertTrue(r > 0)
server = get_smtpserver("myserver")
smtpmock.setdata(response={"[email protected]": (200, "OK")},
support_tls=True)
r = server.send_email(["[email protected]"], "Hallo", "Body")
self.assertEqual(r, True)
# If we configure TLS but the server does not support this, we raise
# an error
smtpmock.setdata(response={"[email protected]": (200, "OK")},
support_tls=False)
self.assertRaises(SMTPException, server.send_email,
["[email protected]"], "Hallo", "Body")
delete_smtpserver("myserver")
开发者ID:awesome-security,项目名称:privacyidea,代码行数:33,代码来源:test_lib_smtpserver.py
示例11: test_02_send_email
def test_02_send_email(self):
r = add_smtpserver(identifier="myserver", server="1.2.3.4")
self.assertTrue(r > 0)
server = get_smtpserver("myserver")
smtpmock.setdata(response={"[email protected]": (200, "OK")})
r = server.send_email(["[email protected]"], "Hallo", "Body")
self.assertEqual(r, True)
smtpmock.setdata(response={"[email protected]": (550,
"Message rejected")})
r = server.send_email(["[email protected]"], "Hallo", "Body")
self.assertEqual(r, False)
delete_smtpserver("myserver")
开发者ID:rockmansyz,项目名称:privacyidea,代码行数:15,代码来源:test_lib_smtpserver.py
示例12: test_08_smsgateway_success
def test_08_smsgateway_success(self):
r = add_smtpserver("myServer", "1.2.3.4", sender="[email protected]")
self.assertTrue(r > 0)
smtpmock.setdata(response={"[email protected]": (200, "OK")})
identifier = "myMail"
provider_module = "privacyidea.lib.smsprovider.SmtpSMSProvider" \
".SmtpSMSProvider"
id = set_smsgateway(identifier, provider_module, description="test",
options={"SMTPIDENTIFIER": "myServer",
"MAILTO": "[email protected]",
"SUBJECT": "{phone}",
"BODY": "{otp}"})
self.assertTrue(id > 0)
sms = create_sms_instance(identifier)
r = sms.submit_message("123456", "Halo")
self.assertTrue(r)
开发者ID:hrz-unimr,项目名称:privacyidea,代码行数:17,代码来源:test_lib_smsprovider.py
示例13: test_18_challenge_request
def test_18_challenge_request(self):
smtpmock.setdata(response={})
transactionid = "123456098712"
set_privacyidea_config("email.mailserver", "localhost")
set_privacyidea_config("email.username", "user")
set_privacyidea_config("email.username", "password")
set_privacyidea_config("email.tls", True)
db_token = Token.query.filter_by(serial=self.serial1).first()
token = EmailTokenClass(db_token)
self.assertTrue(token.check_otp("123456", 1, 10) == -1)
c = token.create_challenge(transactionid)
self.assertTrue(c[0], c)
otp = c[1]
self.assertTrue(c[3].get("state"), transactionid)
# check for the challenges response
r = token.check_challenge_response(passw=otp)
self.assertTrue(r, r)
开发者ID:Reality9,项目名称:privacyidea,代码行数:18,代码来源:test_lib_tokens_email.py
示例14: test_22_new_email_config
def test_22_new_email_config(self):
smtpmock.setdata(response={"[email protected]": (200, 'OK')})
transactionid = "123456098717"
# send the email with the new configuration
r = add_smtpserver(identifier="myServer", server="1.2.3.4")
set_privacyidea_config("email.identifier", "myServer")
db_token = Token.query.filter_by(serial=self.serial1).first()
token = EmailTokenClass(db_token)
self.assertTrue(token.check_otp("123456", 1, 10) == -1)
c = token.create_challenge(transactionid)
self.assertTrue(c[0], c)
otp = c[1]
self.assertTrue(c[3].get("state"), transactionid)
# check for the challenges response
r = token.check_challenge_response(passw=otp)
self.assertTrue(r, r)
delete_smtpserver("myServer")
delete_privacyidea_config("email.identifier")
开发者ID:hrz-unimr,项目名称:privacyidea,代码行数:19,代码来源:test_lib_tokens_email.py
示例15: test_05_test_email
def test_05_test_email(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")},
support_tls=True)
identifier = "newConfig"
server = "mailsever"
port = 25
username = "mailsender"
password = "secret"
sender = "[email protected]"
tls = True
recipient = "[email protected]"
s = SMTPServerDB(identifier=identifier, server=server, port=port,
username=username, password=password, sender=sender,
tls=tls)
r = SMTPServer.test_email(s, recipient,
"Test Email from privacyIDEA",
"This is a test email from privacyIDEA. "
"The configuration %s is working." % identifier)
开发者ID:Andrew8305,项目名称:privacyidea,代码行数:19,代码来源:test_lib_smtpserver.py
示例16: test_02_send_test_email
def test_02_send_test_email(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")})
with self.app.test_request_context('/smtpserver/send_test_email',
method='POST',
data={"identifier": "someServer",
"username": "cornelius",
"password": "secret",
"port": "123",
"server": "1.2.3.4",
"sender": "[email protected]",
"recipient":
"[email protected]",
"description": "myServer"},
headers={'Authorization': self.at}):
res = self.app.full_dispatch_request()
self.assertTrue(res.status_code == 200, res)
data = json.loads(res.data)
self.assertEqual(data.get("result").get("value"), True)
开发者ID:hrz-unimr,项目名称:privacyidea,代码行数:19,代码来源:test_api_smtpserver.py
示例17: test_03_sendsms
def test_03_sendsms(self):
# setup realms
self.setUp_user_realms()
r = set_smsgateway(identifier="myGW",
providermodule="privacyidea.lib.smsprovider."
"SmtpSMSProvider.SmtpSMSProvider",
options={"SMTPIDENTIFIER": "myserver",
"MAILTO": "[email protected]"})
self.assertTrue(r > 0)
smtpmock.setdata(response={"[email protected]": (200, "OK")},
support_tls=False)
g = FakeFlaskG()
audit_object = FakeAudit()
audit_object.audit_data["serial"] = "123456"
g.logged_in_user = {"user": "admin",
"role": "admin",
"realm": ""}
g.audit_object = audit_object
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
req.all_data = {"serial": "SomeSerial",
"user": "cornelius"}
options = {"g": g,
"request": req,
"smsconfig": "myGW"}
un_handler = UserNotificationEventHandler()
res = un_handler.do("sendsms", options=options)
self.assertTrue(res)
开发者ID:MWelp,项目名称:privacyidea,代码行数:42,代码来源:test_lib_events.py
示例18: test_02_sendmail
def test_02_sendmail(self):
# setup realms
self.setUp_user_realms()
r = add_smtpserver(identifier="myserver", server="1.2.3.4", tls=False)
self.assertTrue(r > 0)
smtpmock.setdata(response={"[email protected]": (200, "OK")},
support_tls=False)
g = FakeFlaskG()
audit_object = FakeAudit()
audit_object.audit_data["serial"] = "123456"
g.logged_in_user = {"user": "admin",
"role": "admin",
"realm": ""}
g.audit_object = audit_object
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
req.all_data = {"serial": "SomeSerial",
"user": "cornelius"}
options = {"g": g,
"request": req,
"emailconfig": "myserver"}
un_handler = UserNotificationEventHandler()
res = un_handler.do("sendmail", options=options)
self.assertTrue(res)
开发者ID:Andrew8305,项目名称:privacyidea,代码行数:38,代码来源:test_lib_events.py
示例19: test_04_create_recovery_nonascii
def test_04_create_recovery_nonascii(self):
smtpmock.setdata(response={"[email protected]": (200, "OK")})
recoverycode = "reccode"
# create resolver and realm
param = self.parameters
param["resolver"] = "register"
param["type"] = "sqlresolver"
r = save_resolver(param)
self. assertTrue(r > 0)
# recover password with "recovery.identifier"
r = add_smtpserver(identifier="myserver", server="1.2.3.4")
self.assertTrue(r > 0)
set_privacyidea_config("recovery.identifier", "myserver")
r = create_recoverycode(User(u"nönäscii", "register"), recoverycode=recoverycode)
self.assertEqual(r, True)
user = User(u"nönäscii", "register")
r = check_recoverycode(user, recoverycode)
self.assertEqual(r, True)
# The recovery code is not valid a second time
r = check_recoverycode(user, recoverycode)
self.assertEqual(r, False)
开发者ID:STRML,项目名称:privacyidea,代码行数:24,代码来源:test_lib_recovery.py
示例20: test_05_auth_config_success
def test_05_auth_config_success(self):
smtpmock.setdata(response={})
r = self.auth_provider.submit_message("123456", "Hello")
开发者ID:tcole-cbso,项目名称:privacyidea,代码行数:3,代码来源:test_lib_smsprovider.py
注:本文中的smtpmock.setdata函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论