Пример #1
0
def require_basic_auth(resource):
    p = portal.Portal(TestAuthRealm())
    c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
    c.addUser("john", "john")
    p.registerChecker(c)
    cred_factory = basic.BasicCredentialFactory("Basic Auth protected area")
    return wrapper.HTTPAuthResource(resource, [cred_factory],
                                    p,
                                    interfaces=(IHTTPUser, ))
Пример #2
0
    def setUp(self):
        """
        Create a portal and add an in memory checker to it.

        Then set up a protectedResource that will be wrapped in each test.
        """
        self.portal = portal.Portal(TestAuthRealm())
        c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
        c.addUser('username', 'password')

        self.portal.registerChecker(c)

        self.credFactory = basic.BasicCredentialFactory('test realm')

        self.protectedResource = ProtectedResource()
        self.protectedResource.responseText = "You shouldn't see me."
Пример #3
0
    def test_multipleWWWAuthenticateSchemes(self):
        """
        Test that our unauthorized response can contain challenges for
        multiple authentication schemes.
        """
        root = wrapper.HTTPAuthResource(
            self.protectedResource,
            (basic.BasicCredentialFactory('test realm'),
             FakeDigestCredentialFactory('md5', 'test realm')),
            self.portal,
            interfaces=(IHTTPUser, ))

        d = self.assertResponse((root, 'http://localhost/', {}), (401, {
            'www-authenticate':
            [challengeResponse, ('basic', {
                'realm': 'test realm'
            })]
        }, None))

        return d
Пример #4
0
    def __init__(self):
        portal = Portal(authentication.XCAPAuthRealm())
        if AuthenticationConfig.cleartext_passwords:
            http_checker = ServerConfig.backend.PlainPasswordChecker()
        else:
            http_checker = ServerConfig.backend.HashPasswordChecker()
        portal.registerChecker(http_checker)
        trusted_peers = AuthenticationConfig.trusted_peers
        portal.registerChecker(authentication.TrustedPeerChecker(trusted_peers))
        portal.registerChecker(authentication.PublicGetApplicationChecker())

        auth_type = AuthenticationConfig.type
        if auth_type == 'basic':
            credential_factory = basic.BasicCredentialFactory(auth_type)
        elif auth_type == 'digest':
            credential_factory = tweak_DigestCredentialFactory('MD5', auth_type)
        else:
            raise ValueError("Invalid authentication type: '%s'. Please check the configuration." % auth_type)

        root = authentication.XCAPAuthResource(XCAPRoot(),
                                               (credential_factory,),
                                               portal, (authentication.IAuthUser,))
        self.site = XCAPSite(root)
Пример #5
0
    def test_authorizationAgainstMultipleSchemes(self):
        """
        Test that we can successfully authenticate when presented
        with multiple WWW-Authenticate headers
        """

        root = wrapper.HTTPAuthResource(
            self.protectedResource,
            (basic.BasicCredentialFactory('test realm'),
             FakeDigestCredentialFactory('md5', 'test realm')),
            self.portal,
            interfaces=(IHTTPUser, ))

        def respondBasic(ign):
            credentials = base64.encodestring('username:password')

            d = self.assertResponse((root, 'http://localhost/', {
                'authorization': ('basic', credentials)
            }), (200, {}, None))

            return d

        def respond(ign):
            d = self.assertResponse((root, 'http://localhost/', {
                'authorization': authRequest1
            }), (200, {}, None))
            return d.addCallback(respondBasic)

        d = self.assertResponse((root, 'http://localhost/', {}), (401, {
            'www-authenticate':
            [challengeResponse, ('basic', {
                'realm': 'test realm'
            })]
        }, None))

        return d
Пример #6
0
 def setUp(self):
     self.credentialFactory = basic.BasicCredentialFactory('foo')
     self.username = '******'
     self.password = '******'