Esempio n. 1
0
    def test_get_cred_bad(self):
        from cheeseprism.auth import BasicAuthenticationPolicy as policy

        self.req.environ['HTTP_AUTHORIZATION'] = 'bleh'
        assert policy._get_credentials(self.req) is None

        self.req.environ['HTTP_AUTHORIZATION'] = 'Basic 123'
        assert policy._get_credentials(self.req) is None

        self.req.environ['HTTP_AUTHORIZATION'] = 'Basic d2hpdCtzZWNyZXQ=\n'
        assert policy._get_credentials(self.req) is None

        self.req.environ['HTTP_AUTHORIZATION'] = 'fah nah'
        assert policy._get_credentials(self.req) is None
Esempio n. 2
0
    def test_get_cred_bad(self):
        from cheeseprism.auth import BasicAuthenticationPolicy as policy

        self.req.environ['HTTP_AUTHORIZATION'] = 'bleh'
        assert policy._get_credentials(self.req) is None

        self.req.environ['HTTP_AUTHORIZATION'] = 'Basic 123'
        assert policy._get_credentials(self.req) is None

        self.req.environ['HTTP_AUTHORIZATION'] = 'Basic d2hpdCtzZWNyZXQ=\n'
        assert policy._get_credentials(self.req) is None

        self.req.environ['HTTP_AUTHORIZATION'] = 'fah nah'
        assert policy._get_credentials(self.req) is None
Esempio n. 3
0
def main(global_config, **settings):
    settings = dict(global_config, **settings)
    settings.setdefault('jinja2.i18n.domain', 'CheesePrism')

    session_factory = UnencryptedCookieSessionFactoryConfig('cheeseprism')
    config = Configurator(root_factory=App, settings=settings,
                          session_factory=session_factory,
                          authentication_policy=\
                          BasicAuthenticationPolicy(BasicAuthenticationPolicy.noop_check))

    setup_workers(config.registry)

    config.add_translation_dirs('locale/')

    config.include('.request')
    config.include('.views')
    config.include('.index')

    tempspec = settings.get('cheeseprism.index_templates', '')
    config.registry['cp.index_templates'] = EnvFactory.from_str(tempspec)

    if asbool(settings.get('cheeseprism.pipcache_mirror', False)):
        config.include('.sync.pip')

    if asbool(settings.get('cheeseprism.auto_sync', False)):
        config.include('.sync.auto')

    tempfile_limit = int(settings.get('cheeseprism.temp_file_limit', 10*1024))
    config.add_request_method(lambda req: tempfile_limit,
                              name='request_body_tempfile_limit', reify=True)

    config.add_request_method(lambda req: asbool(settings.get('cheeseprism.disable.regenerate', False)),
                              name='disable_regen', reify=True)

    return config.make_wsgi_app()
Esempio n. 4
0
def main(global_config, **settings):
    settings.setdefault('jinja2.i18n.domain', 'CheesePrism')
    session_factory = UnencryptedCookieSessionFactoryConfig('cheeseprism')

    config = Configurator(root_factory=App, settings=settings,
                          session_factory=session_factory,
                          authentication_policy=\
                          BasicAuthenticationPolicy(BasicAuthenticationPolicy.noop_check))

    config.add_translation_dirs('locale/')
    config.include('pyramid_jinja2')
    config.add_renderer('.html', renderer_factory)

    config.add_static_view('static', 'static')
    config.scan('cheeseprism.views')
    config.scan('cheeseprism.index')
    config.set_request_factory(Request)
    config.add_route('package',
                     'package/{name}/{version}',
                     view='cheeseprism.views.package')
    settings['index_templates'] = EnvFactory.from_str(
        settings['cheeseprism.index_templates'])

    return config.make_wsgi_app()
Esempio n. 5
0
 def test_unauth_userid(self):
     policy = self.makeone()
     assert 'whit' == policy.unauthenticated_userid(self.req)
     self.req.environ['HTTP_AUTHORIZATION'] = 'Bad Auth'
     assert policy.unauthenticated_userid(self.req) is None
Esempio n. 6
0
 def test_effective_p_without_cred(self):
     self.req.environ['HTTP_AUTHORIZATION'] = 'Basic d2hpdCtzZWNyZXQ=\n'
     policy = self.makeone()
     assert policy.effective_principals(self.req) == ['system.Everyone']
Esempio n. 7
0
 def test_effective_p_without_groups(self):
     policy = self.makeone(lambda x, y: None)
     assert policy.effective_principals(self.req) == ['system.Everyone']
Esempio n. 8
0
 def test_authenticated_userid_nocred(self):
     policy = self.makeone()
     del self.req.environ['HTTP_AUTHORIZATION'] 
     userid = policy.authenticated_userid(self.req)
     assert userid is None
Esempio n. 9
0
 def test_effective_principals(self):
     policy = self.makeone()
     princs = policy.effective_principals(self.req)
     assert princs == ['system.Everyone', 'system.Authenticated', 'whit']
Esempio n. 10
0
 def test_effective_principals(self):
     policy = self.makeone()
     princs = policy.effective_principals(self.req)
     assert princs == ['system.Everyone', 'system.Authenticated', 'whit']
Esempio n. 11
0
 def test_get_cred_good(self):
     from cheeseprism.auth import BasicAuthenticationPolicy as policy
     cred = policy._get_credentials(self.req)
     assert cred == {'login': '******', 'password': '******'}
Esempio n. 12
0
 def test_authenticated_userid(self):
     policy = self.makeone()
     userid = policy.authenticated_userid(self.req)
     assert userid == 'whit'
Esempio n. 13
0
 def test_authenticated_userid(self):
     policy = self.makeone()
     userid = policy.authenticated_userid(self.req)
     assert userid == 'whit'
Esempio n. 14
0
 def test_remember(self):
     policy = self.makeone()
     assert policy.remember(self.req, 'whit') == []
Esempio n. 15
0
 def test_forget(self):
     policy = self.makeone()
     assert policy.forget(self.req) == [('WWW-Authenticate', 'Basic realm="Realm"')]
Esempio n. 16
0
 def test_unauth_userid(self):
     policy = self.makeone()
     assert 'whit' == policy.unauthenticated_userid(self.req)
     self.req.environ['HTTP_AUTHORIZATION'] = 'Bad Auth'
     assert policy.unauthenticated_userid(self.req) is None
Esempio n. 17
0
 def test_effective_p_without_groups(self):
     policy = self.makeone(lambda x, y: None)
     assert policy.effective_principals(self.req) == ['system.Everyone']
Esempio n. 18
0
 def test_effective_p_without_cred(self):
     self.req.environ['HTTP_AUTHORIZATION'] = 'Basic d2hpdCtzZWNyZXQ=\n'
     policy = self.makeone()
     assert policy.effective_principals(self.req) == ['system.Everyone']
Esempio n. 19
0
 def test_remember(self):
     policy = self.makeone()
     assert policy.remember(self.req, 'whit') == []
Esempio n. 20
0
 def test_authenticated_userid_nocred(self):
     policy = self.makeone()
     del self.req.environ['HTTP_AUTHORIZATION']
     userid = policy.authenticated_userid(self.req)
     assert userid is None
Esempio n. 21
0
 def test_forget(self):
     policy = self.makeone()
     assert policy.forget(self.req) == [('WWW-Authenticate',
                                         'Basic realm="Realm"')]
Esempio n. 22
0
 def test_get_cred_good(self):
     from cheeseprism.auth import BasicAuthenticationPolicy as policy
     cred = policy._get_credentials(self.req)
     assert cred == {'login': '******', 'password': '******'}