本文整理汇总了Python中twisted.cred.checkers.AllowAnonymousAccess方法的典型用法代码示例。如果您正苦于以下问题:Python checkers.AllowAnonymousAccess方法的具体用法?Python checkers.AllowAnonymousAccess怎么用?Python checkers.AllowAnonymousAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.cred.checkers
的用法示例。
在下文中一共展示了checkers.AllowAnonymousAccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_anonymousAccess
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_anonymousAccess(self):
"""
Anonymous requests are allowed if a L{Portal} has an anonymous checker
registered.
"""
unprotectedContents = b"contents of the unprotected child resource"
self.avatars[ANONYMOUS] = Resource()
self.avatars[ANONYMOUS].putChild(
self.childName, Data(unprotectedContents, 'text/plain'))
self.portal.registerChecker(AllowAnonymousAccess())
self.credentialFactories.append(BasicCredentialFactory('example.com'))
request = self.makeRequest([self.childName])
child = getChildForRequest(self.wrapper, request)
d = request.notifyFinish()
def cbFinished(ignored):
self.assertEqual(request.written, [unprotectedContents])
d.addCallback(cbFinished)
request.render(child)
return d
示例2: test_anonymousLogin
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_anonymousLogin(self):
"""
Verify that a PB server using a portal configured with a checker which
allows IAnonymous credentials can be logged into using IAnonymous
credentials.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
d = self.clientFactory.login(credentials.Anonymous(), "BRAINS!")
def cbLoggedIn(perspective):
return perspective.callRemote('echo', 123)
d.addCallback(cbLoggedIn)
d.addCallback(self.assertEqual, 123)
self.establishClientAndServer()
self.pump.flush()
return d
示例3: test_anonymousLoginWithMultipleCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_anonymousLoginWithMultipleCheckers(self):
"""
Like L{test_anonymousLogin} but against a portal with a checker for
both IAnonymous and IUsernamePassword.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
self.portal.registerChecker(
checkers.InMemoryUsernamePasswordDatabaseDontUse(user=b'pass'))
d = self.clientFactory.login(credentials.Anonymous(), "BRAINS!")
def cbLogin(perspective):
return perspective.callRemote('echo', 123)
d.addCallback(cbLogin)
d.addCallback(self.assertEqual, 123)
self.establishClientAndServer()
self.pump.flush()
return d
示例4: test_authenticatedLoginWithMultipleCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_authenticatedLoginWithMultipleCheckers(self):
"""
Like L{test_anonymousLoginWithMultipleCheckers} but check that
username/password authentication works.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
self.portal.registerChecker(
checkers.InMemoryUsernamePasswordDatabaseDontUse(user=b'pass'))
d = self.clientFactory.login(
credentials.UsernamePassword(b'user', b'pass'), "BRAINS!")
def cbLogin(perspective):
return perspective.callRemote('add', 100, 23)
d.addCallback(cbLogin)
d.addCallback(self.assertEqual, 123)
self.establishClientAndServer()
self.pump.flush()
return d
示例5: test_responseFilterDoesntClobberHeaders
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_responseFilterDoesntClobberHeaders(self):
"""
Test that if an UNAUTHORIZED response is returned and
already has 'WWW-Authenticate' headers we don't add them.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
nonAnonResource = NonAnonymousResource()
nonAnonResource.responseText = "We don't like anonymous users"
nonAnonResource.sendOwnHeaders = True
root = wrapper.HTTPAuthResource(nonAnonResource,
[self.credFactory],
self.portal,
interfaces=(IHTTPUser,))
d = self.assertResponse(
(root, 'http://localhost/',
{}),
(401,
{'WWW-Authenticate': [('basic',
{'realm': "foo"})]},
None))
return d
示例6: test_anonymousAccess
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_anonymousAccess(self):
"""
Anonymous requests are allowed if a L{Portal} has an anonymous checker
registered.
"""
unprotectedContents = "contents of the unprotected child resource"
self.avatars[ANONYMOUS] = Resource()
self.avatars[ANONYMOUS].putChild(
self.childName, Data(unprotectedContents, 'text/plain'))
self.portal.registerChecker(AllowAnonymousAccess())
self.credentialFactories.append(BasicCredentialFactory('example.com'))
request = self.makeRequest([self.childName])
child = getChildForRequest(self.wrapper, request)
d = request.notifyFinish()
def cbFinished(ignored):
self.assertEquals(request.written, [unprotectedContents])
d.addCallback(cbFinished)
request.render(child)
return d
示例7: makeService
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def makeService(config):
f = ftp.FTPFactory()
r = ftp.FTPRealm(config['root'])
p = portal.Portal(r)
p.registerChecker(checkers.AllowAnonymousAccess(), credentials.IAnonymous)
if config['password-file'] is not None:
p.registerChecker(checkers.FilePasswordDB(config['password-file'], cache=True))
f.tld = config['root']
f.userAnonymous = config['userAnonymous']
f.portal = p
f.protocol = ftp.FTP
try:
portno = int(config['port'])
except KeyError:
portno = 2121
return internet.TCPServer(portno, f)
示例8: test_anonymousLogin
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_anonymousLogin(self):
"""
Verify that a PB server using a portal configured with an checker which
allows IAnonymous credentials can be logged into using IAnonymous
credentials.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
factory = pb.PBClientFactory()
d = factory.login(credentials.Anonymous(), "BRAINS!")
def cbLoggedIn(perspective):
return perspective.callRemote('echo', 123)
d.addCallback(cbLoggedIn)
d.addCallback(self.assertEqual, 123)
d.addCallback(self._disconnect, factory)
connector = reactor.connectTCP("127.0.0.1", self.portno, factory)
self.addCleanup(connector.disconnect)
return d
示例9: test_anonymousLoginWithMultipleCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_anonymousLoginWithMultipleCheckers(self):
"""
Like L{test_anonymousLogin} but against a portal with a checker for
both IAnonymous and IUsernamePassword.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
self.portal.registerChecker(
checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
factory = pb.PBClientFactory()
d = factory.login(credentials.Anonymous(), "BRAINS!")
def cbLogin(perspective):
return perspective.callRemote('echo', 123)
d.addCallback(cbLogin)
d.addCallback(self.assertEqual, 123)
d.addCallback(self._disconnect, factory)
connector = reactor.connectTCP('127.0.0.1', self.portno, factory)
self.addCleanup(connector.disconnect)
return d
示例10: test_authenticatedLoginWithMultipleCheckers
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_authenticatedLoginWithMultipleCheckers(self):
"""
Like L{test_anonymousLoginWithMultipleCheckers} but check that
username/password authentication works.
"""
self.portal.registerChecker(checkers.AllowAnonymousAccess())
self.portal.registerChecker(
checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
factory = pb.PBClientFactory()
d = factory.login(
credentials.UsernamePassword('user', 'pass'), "BRAINS!")
def cbLogin(perspective):
return perspective.callRemote('add', 100, 23)
d.addCallback(cbLogin)
d.addCallback(self.assertEqual, 123)
d.addCallback(self._disconnect, factory)
connector = reactor.connectTCP('127.0.0.1', self.portno, factory)
self.addCleanup(connector.disconnect)
return d
示例11: postOptions
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def postOptions(self):
for f in ('pop3', 'smtp', 'pop3s'):
try:
self[f] = int(self[f])
if not (0 <= self[f] < 2 ** 16):
raise ValueError
except ValueError:
raise usage.UsageError(
'Invalid port specified to --%s: %s' % (f, self[f])
)
if self['pop3s']:
if not self['certificate']:
raise usage.UsageError("Cannot specify --pop3s without "
"--certificate")
elif not os.path.exists(self['certificate']):
raise usage.UsageError("Certificate file %r does not exist."
% self['certificate'])
if not self['disable-anonymous']:
self.service.smtpPortal.registerChecker(checkers.AllowAnonymousAccess())
if not (self['pop3'] or self['smtp'] or self['pop3s']):
raise usage.UsageError("You cannot disable all protocols")
示例12: setUp
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def setUp(self):
self.filename = self.mktemp()
with open(self.filename, 'wb') as f:
f.write(b'admin:asdf\nalice:foo\n')
self.goodChecker = checkers.FilePasswordDB(self.filename)
self.badChecker = checkers.FilePasswordDB(
self.filename, hash=self._hash)
self.anonChecker = checkers.AllowAnonymousAccess()
示例13: postOptions
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def postOptions(self):
"""
Check the validity of the specified set of options and
configure authentication.
@raise UsageError: When the set of options is invalid.
"""
from twisted.internet import reactor
if self['esmtp'] and self['hostname'] is None:
raise usage.UsageError("--esmtp requires --hostname")
# If the --auth option was passed, this will be present -- otherwise,
# it won't be, which is also a perfectly valid state.
if 'credCheckers' in self:
for ch in self['credCheckers']:
self.service.smtpPortal.registerChecker(ch)
if not self['disable-anonymous']:
self.service.smtpPortal.registerChecker(checkers.AllowAnonymousAccess())
anything = False
for service in self._protoDefaults:
self[service] = self._getEndpoints(reactor, service)
if self[service]:
anything = True
if not anything:
raise usage.UsageError("You cannot disable all protocols")
示例14: test_acceptSenderAddress
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_acceptSenderAddress(self):
"""
Test that a C{MAIL FROM} command with an acceptable address is
responded to with the correct success code.
"""
class AcceptanceDelivery(NotImplementedDelivery):
"""
Delivery object which accepts all senders as valid.
"""
def validateFrom(self, helo, origin):
return origin
realm = SingletonRealm(smtp.IMessageDelivery, AcceptanceDelivery())
portal = Portal(realm, [AllowAnonymousAccess()])
proto = smtp.SMTP()
proto.portal = portal
trans = StringTransport()
proto.makeConnection(trans)
# Deal with the necessary preliminaries
proto.dataReceived('HELO example.com\r\n')
trans.clear()
# Try to specify our sender address
proto.dataReceived('MAIL FROM:<alice@example.com>\r\n')
# Clean up the protocol before doing anything that might raise an
# exception.
proto.connectionLost(error.ConnectionLost())
# Make sure that we received exactly the correct response
self.assertEqual(
trans.value(),
'250 Sender address accepted\r\n')
示例15: test_deliveryRejectedSenderAddress
# 需要导入模块: from twisted.cred import checkers [as 别名]
# 或者: from twisted.cred.checkers import AllowAnonymousAccess [as 别名]
def test_deliveryRejectedSenderAddress(self):
"""
Test that a C{MAIL FROM} command with an address rejected by a
L{smtp.IMessageDelivery} instance is responded to with the correct
error code.
"""
class RejectionDelivery(NotImplementedDelivery):
"""
Delivery object which rejects all senders as invalid.
"""
def validateFrom(self, helo, origin):
raise smtp.SMTPBadSender(origin)
realm = SingletonRealm(smtp.IMessageDelivery, RejectionDelivery())
portal = Portal(realm, [AllowAnonymousAccess()])
proto = smtp.SMTP()
proto.portal = portal
trans = StringTransport()
proto.makeConnection(trans)
# Deal with the necessary preliminaries
proto.dataReceived('HELO example.com\r\n')
trans.clear()
# Try to specify our sender address
proto.dataReceived('MAIL FROM:<alice@example.com>\r\n')
# Clean up the protocol before doing anything that might raise an
# exception.
proto.connectionLost(error.ConnectionLost())
# Make sure that we received exactly the correct response
self.assertEqual(
trans.value(),
'550 Cannot receive from specified address '
'<alice@example.com>: Sender not acceptable\r\n')