Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
*_flymake.py
*#*
tests/test-indexes/*
/doc/example-index/*
/doc/example-index/*
env*/
tmp/
27 changes: 13 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Run
The following will start the application and a static file server for
`CheesePrism` suitable for testing and development::

$ paster serve development.ini
$ pserve development.ini

**If** you have not installed the source (ie. you installed the
package or from the strap file), you will need to copy the
Expand Down Expand Up @@ -114,11 +114,11 @@ See ``doc/sample-nginx.conf`` and replace ``alias CheesePrism/files;`` and
Serve management app
~~~~~~~~~~~~~~~~~~~~

Use the prod.ini (edited for your setup) for simplest serving. Be sure
Use the production.ini (edited for your setup) for simplest serving. Be sure
to remove such things as ``pyramid.includes = pyramid_debugtoolbar``
if security is a concern::

$ paster serve prod.ini
$ pserve production.ini

Sane people use something like upstart or `supervisord <supervisord.org>`_ to manage this process.

Expand All @@ -138,23 +138,22 @@ python2.6 and better you can setup your ``~/.pypirc`` and then upload to
your prism as you would `pypi <http://pypi.python.org/pypi>`_::

[distutils]
index-servers =
pypi
local
index-servers =
pypi
local


[pypi]
username:user
password:secret
username:user
password:secret

[local]
# your prism of fromage
username:user
password:secret
repository:http://mycheese
# your prism of fromage
username:user
password:secret
repository:http://localhost:6543/simple


The you can upload a source ala::
Then you can upload a source ala::

$ cd /src/MyAwesomePyPkg
$ python setup.py sdist upload -r local
Expand Down
13 changes: 5 additions & 8 deletions cheeseprism/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from paste.httpheaders import AUTHORIZATION
from paste.httpheaders import WWW_AUTHENTICATE
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.security import Authenticated
from pyramid.security import Everyone
Expand Down Expand Up @@ -41,11 +39,10 @@ def authenticated_userid(self, request):

@staticmethod
def _get_credentials(request):
authorization = AUTHORIZATION(request.environ)
try:
authmeth, auth = authorization.split(' ', 1)
except ValueError: # not enough values to unpack
authorization = request.authorization
if authorization is None:
return None
authmeth, auth = request.authorization
if authmeth.lower() == 'basic':
try:
auth = auth.strip().decode('base64')
Expand Down Expand Up @@ -83,8 +80,8 @@ def remember(self, request, principal, **kw):
return []

def forget(self, request):
head = WWW_AUTHENTICATE.tuples('Basic realm="%s"' % self.realm)
return head
headers = [('WWW-Authenticate', 'Basic realm="%s"' % self.realm)]
return headers

@staticmethod
def noop_check(credentials, request):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'pyramid_debugtoolbar',
'pyramid_jinja2',
'requests',
'pip']
'pip',
'Paste']

setup(name='CheesePrism',
version='0.1a2',
Expand Down
16 changes: 8 additions & 8 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def makeone(self, check=None):

def setUp(self):
self.req = CPDummyRequest()
self.req.environ['HTTP_AUTHORIZATION'] = 'Basic d2hpdDpzZWNyZXQ='
self.req.authorization = ('Basic', 'd2hpdDpzZWNyZXQ=')
self.req.headers['Authorization'] = 'Basic d2hpdDpzZWNyZXQ='
self.req.environ['wsgi.version'] = '1.0'

Expand All @@ -22,7 +22,7 @@ def test_authenticated_userid(self):

def test_authenticated_userid_nocred(self):
policy = self.makeone()
del self.req.environ['HTTP_AUTHORIZATION']
self.req.authorization = None
userid = policy.authenticated_userid(self.req)
assert userid is None

Expand All @@ -34,16 +34,16 @@ def test_get_cred_good(self):
def test_get_cred_bad(self):
from cheeseprism.auth import BasicAuthenticationPolicy as policy

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

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

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

self.req.environ['HTTP_AUTHORIZATION'] = 'fah nah'
self.req.authorization = ('fah', 'nah')
assert policy._get_credentials(self.req) is None

def test_effective_principals(self):
Expand All @@ -52,7 +52,7 @@ def test_effective_principals(self):
assert princs == ['system.Everyone', 'system.Authenticated', 'whit']

def test_effective_p_without_cred(self):
self.req.environ['HTTP_AUTHORIZATION'] = 'Basic d2hpdCtzZWNyZXQ=\n'
self.req.authorization = ('Basic', 'd2hpdCtzZWNyZXQ=\n')
policy = self.makeone()
assert policy.effective_principals(self.req) == ['system.Everyone']

Expand All @@ -63,7 +63,7 @@ def test_effective_p_without_groups(self):
def test_unauth_userid(self):
policy = self.makeone()
assert 'whit' == policy.unauthenticated_userid(self.req)
self.req.environ['HTTP_AUTHORIZATION'] = 'Bad Auth'
self.req.authorization = ('Bad', 'Auth')
assert policy.unauthenticated_userid(self.req) is None


Expand Down