Skip to content

Commit

Permalink
s/user_infos/user_info/g
Browse files Browse the repository at this point in the history
Plus fix docs so they build

+autopep8
  • Loading branch information
djmitche committed Apr 13, 2014
1 parent 32232b9 commit ea0e348
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 32 deletions.
10 changes: 5 additions & 5 deletions master/buildbot/test/unit/test_www_auth.py
Expand Up @@ -39,7 +39,7 @@ def test_render(self):
exp = 'this.config = {"url": "h:/a/b/", "user": {"anonymous": true}, "auth": {"name": "noauth"}, "port": null}'
self.assertEqual(res, exp)

master.session.user_infos = dict(name="me", email="me@me.org")
master.session.user_info = dict(name="me", email="me@me.org")
res = yield self.render_resource(rsrc, '/')
exp = 'this.config = {"url": "h:/a/b/", "user": {"email": "me@me.org", "name": "me"}, "auth": {"name": "noauth"}, "port": null}'
self.assertEqual(res, exp)
Expand All @@ -59,7 +59,7 @@ def test_render(self):
_auth.maybeAutoLogin = mock.Mock()

def authenticateViaLogin(request):
request.getSession().user_infos = dict(name="me")
request.getSession().user_info = dict(name="me")
_auth.authenticateViaLogin = mock.Mock(side_effect=authenticateViaLogin)
master = self.make_master(url='h:/a/b/', auth=_auth)
rsrc = _auth.getLoginResource(master)
Expand All @@ -81,7 +81,7 @@ def test_render(self):

def updateUserInfo(request):
session = request.getSession()
session.user_infos['email'] = session.user_infos['username'] + "@org"
session.user_info['email'] = session.user_info['username'] + "@org"
_auth.updateUserInfo = mock.Mock(side_effect=updateUserInfo)
master = self.make_master(url='h:/a/b/', auth=_auth)
rsrc = auth.PreAuthenticatedLoginResource(master, _auth, "him")
Expand All @@ -92,7 +92,7 @@ def updateUserInfo(request):
_auth.maybeAutoLogin.assert_not_called()
_auth.authenticateViaLogin.assert_not_called()
_auth.updateUserInfo.assert_called()
self.assertEqual(master.session.user_infos, {'email': 'him@org', 'username': 'him'})
self.assertEqual(master.session.user_info, {'email': 'him@org', 'username': 'him'})


class LogoutResource(www.WwwTestMixin, unittest.TestCase):
Expand Down Expand Up @@ -180,4 +180,4 @@ def test_AuthRealm(self):
_, rsrc, _ = realm.requestAvatar("me", None, IResource)
res = yield self.render_resource(rsrc, '/')
self.assertEqual(res, "")
self.assertEqual(master.session.user_infos, {'email': 'me', 'username': 'me'})
self.assertEqual(master.session.user_info, {'email': 'me', 'username': 'me'})
9 changes: 5 additions & 4 deletions master/buildbot/test/unit/test_www_oauth.py
Expand Up @@ -16,9 +16,9 @@
import mock
import sys

from buildbot.test.util import www
from twisted.internet import defer
from twisted.trial import unittest
from buildbot.test.util import www


class FakeClient(object):
Expand All @@ -34,6 +34,7 @@ class FakeSanction(object):
class OAuth2Auth(www.WwwTestMixin, unittest.TestCase):
# we completely fake the python sanction module, so no need to require
# it to run the unit tests

def setUp(self):
self.oldsanction = sys.modules.get("sanction", None)
self.sanction = FakeSanction()
Expand Down Expand Up @@ -141,11 +142,11 @@ class fakeAuth(object):
res = yield self.render_resource(rsrc, '/?code=code!')
rsrc.auth.getLoginURL.assert_not_called()
rsrc.auth.verifyCode.assert_called_once_with("code!")
self.assertEqual(self.master.session.user_infos, {'username': 'bar'})
self.assertEqual(self.master.session.user_info, {'username': 'bar'})
self.assertEqual(res, {'redirected': '://me'})

def test_getConfig(self):
self.assertEqual(self.githubAuth.getConfigDict(), {'fa_icon': 'fa-github',
'name': 'GitHub', 'oauth2': True})
'name': 'GitHub', 'oauth2': True})
self.assertEqual(self.googleAuth.getConfigDict(), {'fa_icon': 'fa-google-plus',
'name': 'Google', 'oauth2': True})
'name': 'Google', 'oauth2': True})
14 changes: 7 additions & 7 deletions master/buildbot/www/auth.py
Expand Up @@ -58,8 +58,8 @@ def getLoginResource(self, master):
def updateUserInfo(self, request):
session = request.getSession()
if self.userInfoProvider is not None:
infos = yield self.userInfoProvider.getUserInfo(session.user_infos['username'])
session.user_infos.update(infos)
infos = yield self.userInfoProvider.getUserInfo(session.user_info['username'])
session.user_info.update(infos)


class UserInfoProviderBase(config.ConfiguredMixin):
Expand Down Expand Up @@ -96,8 +96,8 @@ def maybeAutoLogin(self, request):
raise Error(403, 'http header does not match regex! "%s" not matching %s' %
(header, self.headerRegex.pattern))
session = request.getSession()
if not hasattr(session, "user_infos"):
session.user_infos = dict(res.groupdict())
if not hasattr(session, "user_info"):
session.user_info = dict(res.groupdict())
yield self.updateUserInfo(request)
defer.returnValue(True)

Expand Down Expand Up @@ -176,8 +176,8 @@ def renderConfig(self, request):
except Error, e:
config["on_load_warning"] = e.message

if hasattr(session, "user_infos"):
config.update({"user": session.user_infos})
if hasattr(session, "user_info"):
config.update({"user": session.user_info})
else:
config.update({"user": {"anonymous": True}})
config.update(self.config)
Expand Down Expand Up @@ -218,7 +218,7 @@ def __init__(self, master, auth, username):
@defer.inlineCallbacks
def renderLogin(self, request):
session = request.getSession()
session.user_infos = dict(username=self.username)
session.user_info = dict(username=self.username)
yield self.auth.updateUserInfo(request)


Expand Down
7 changes: 4 additions & 3 deletions master/buildbot/www/oauth2.py
@@ -1,9 +1,10 @@
import sanction

from buildbot.www import auth, resource
from buildbot.www import auth
from buildbot.www import resource
from posixpath import join
from twisted.internet import defer
from twisted.internet import threads
from posixpath import join


class OAuth2LoginResource(auth.LoginResource):
Expand All @@ -22,7 +23,7 @@ def renderLogin(self, request):
defer.returnValue(url)
else:
details = yield self.auth.verifyCode(code)
request.getSession().user_infos = details
request.getSession().user_info = details
raise resource.Redirect(self.auth.homeUri)


Expand Down
16 changes: 8 additions & 8 deletions master/docs/developer/cls-auth.rst
Expand Up @@ -69,7 +69,7 @@ API documentation
.. py:class:: AuthBase
This class is the base class for all authentication methods.
All authentications are not done at the same level, so several optional methods are available. This class implements default implementation. The login session is stored via twisted's ``request.getSession()``, and detailed used information is stored in ``request.getSession().user_infos``. The session information is then sent to the UI via the ``config`` constant (in the ``user`` attribute of ``config``)
All authentications are not done at the same level, so several optional methods are available. This class implements default implementation. The login session is stored via twisted's ``request.getSession()``, and detailed used information is stored in ``request.getSession().user_info``. The session information is then sent to the UI via the ``config`` constant (in the ``user`` attribute of ``config``)

.. py:attribute:: userInfoProvider
Expand All @@ -89,31 +89,31 @@ API documentation
Automatically login the user on one of the first request (when browser fetches ``/config.js``). This is the entry-point for reverse-proxy driven authentication.

returns a deferred which fires with ignored results, when the authentication task is done.
If it succeeded, ``request.getSession().user_infos`` is defined.
If it succeeded, ``request.getSession().user_info`` is defined.
If it failed, ``resource.Error`` must be raised.
If it is not implemented, the deferred will fire with user_infos unset.
If it is not implemented, the deferred will fire with user_info unset.

.. py:method:: authenticateViaLogin(request)
:param request: the request object

Entry point for login via /login request. The default UI is passing the login credential via BasicAuth method. One can verify the login credential via deferred using this simple API. Once the user is authenticated, this method is responsible for filling ``request.getSession().user_infos``, by calling ``updateUserInfos()``
Entry point for login via /login request. The default UI is passing the login credential via BasicAuth method. One can verify the login credential via deferred using this simple API. Once the user is authenticated, this method is responsible for filling ``request.getSession().user_info``, by calling ``updateUserInfo()``
returns a deferred which fires with ignored results, when the authentication task is done.
If it succeeded, ``request.getSession().user_infos`` is defined.
If it succeeded, ``request.getSession().user_info`` is defined.
If it failed, ``resource.Error`` must be raised.
If it is not implemented, the deferred will fire with user_infos unset.
If it is not implemented, the deferred will fire with user_info unset.

.. py:method:: getLoginResource(master)
:param request: the request object

Entry point for getting a customized loginResource. This is a mean to reuse twisted code.

.. py:method:: updateUserInfos(request)
.. py:method:: updateUserInfo(request)
Separate entrypoint for getting user information. This is a mean to call self.userInfoProvider if provided.

.. py:class:: UserInfosBase
.. py:class:: UserInfoBase
Class that can be used, to get more info for the user like groups, in a separate database.

Expand Down
2 changes: 1 addition & 1 deletion master/docs/developer/config.rst
Expand Up @@ -14,7 +14,7 @@ implemented as services, subclassing :py:class:`ReconfigurableServiceMixin`, as
described in :ref:`developer-Reconfiguration`.

IConfigured
~~~~~~~~~~~
-----------

.. class:: buildbot.interfaces.IConfigured

Expand Down
8 changes: 4 additions & 4 deletions master/docs/manual/cfg-global.rst
Expand Up @@ -707,7 +707,7 @@ This server is configured with the :bb:cfg:`www` configuration key, which specif
'avatar_methods': []
}

For use of corporate pictures, you can use LdapUserInfos, which can also acts as an avatar provider. See :bb:cfg:`auth`
For use of corporate pictures, you can use LdapUserInfo, which can also acts as an avatar provider. See :bb:cfg:`auth`

.. bb:cfg:: auth
Expand Down Expand Up @@ -837,7 +837,7 @@ In order to access control feature in the web UI, you will need to configure an

You can configure RemoteUserAuth to use ldap directory to fill remaining user info data

.. py:class:: buildbot.ldapuserinfos.LdapUserInfos
.. py:class:: buildbot.ldapuserinfos.LdapUserInfo
* ``uri``: uri of the ldap server
* ``bind_user``: username of the ldap account that is used to get the infos for other users (usually a "faceless" account)
Expand All @@ -856,12 +856,12 @@ In order to access control feature in the web UI, you will need to configure an
Example::
from buildbot.www.auth import RemoteUserAuth
from buildbot.www.ldapuserinfos import LdapUserInfos
from buildbot.www.ldapuserinfos import LdapUserInfo
from buildbot.www.avatar import AvatarGravatar
# this configuration works for MS Active Directory ldap implementation
# we use it for user info, and avatars
userInfos = LdapUserInfos(
userInfos = LdapUserInfo(
uri='ldap://ldap.mycompany.com:3268',
bind_user='ldap_user',
bind_pw='p4$$wd',
Expand Down

0 comments on commit ea0e348

Please sign in to comment.