Skip to content

Commit

Permalink
Restrict builder names to be unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Sep 29, 2013
2 parents c5264eb + 9aaf540 commit d13c053
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 5 additions & 2 deletions master/buildbot/config.py
Expand Up @@ -21,7 +21,7 @@
import warnings
from buildbot.util import safeTranslate
from buildbot import interfaces
from buildbot import locks
from buildbot import locks, util
from buildbot.revlinks import default_revlink_matcher
from twisted.python import log, failure
from twisted.internet import defer
Expand Down Expand Up @@ -701,7 +701,10 @@ def __init__(self, name=None, slavename=None, slavenames=None,
name = '<unknown>'
elif name[0] == '_':
error("builder names must not start with an underscore: '%s'" % name)
self.name = name
try:
self.name = util.ascii2unicode(name)
except UnicodeDecodeError:
error("builder names must be unicode or ASCII")

# factory is required
if factory is None:
Expand Down
3 changes: 2 additions & 1 deletion master/buildbot/process/builder.py
Expand Up @@ -46,7 +46,6 @@ class Builder(config.ReconfigurableServiceMixin,
def __init__(self, name, _addServices=True):
service.MultiService.__init__(self)
self.name = name
self._builderid = None # filled in by getBuilderId

# this is filled on demand by getBuilderId; don't access it directly
self._builderid = None
Expand Down Expand Up @@ -118,6 +117,8 @@ def getBuilderId(self):
# additional locking around this function.
if self._builderid:
return defer.succeed(self._builderid)
# buildbot.config should ensure this is already unicode, but it doesn't
# hurt to check again
name = ascii2unicode(self.name)
d = self.master.data.updates.findBuilderId(name)
@d.addCallback
Expand Down
13 changes: 13 additions & 0 deletions master/buildbot/test/unit/test_config.py
Expand Up @@ -1090,6 +1090,12 @@ def test_reserved_name(self):
lambda : config.BuilderConfig(name='_a',
factory=self.factory, slavenames=['a']))

def test_utf8_name(self):
self.assertRaisesConfigError(
"builder names must be unicode or ASCII",
lambda : config.BuilderConfig(name=u"\N{SNOWMAN}".encode('utf-8'),
factory=self.factory, slavenames=['a']))

def test_no_factory(self):
self.assertRaisesConfigError(
"builder 'a' has no factory",
Expand Down Expand Up @@ -1167,6 +1173,13 @@ def test_defaults(self):
mergeRequests=None,
description=None)

def test_unicode_name(self):
cfg = config.BuilderConfig(
name=u'a \N{SNOWMAN} c', slavename='a', factory=self.factory)
self.assertIdentical(cfg.factory, self.factory)
self.assertAttributes(cfg,
name=u'a \N{SNOWMAN} c')

def test_args(self):
cfg = config.BuilderConfig(
name='b', slavename='s1', slavenames='s2', builddir='bd',
Expand Down
3 changes: 3 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -62,6 +62,9 @@ Nine

* SQLAlchemy-Migrate-0.6.1 is no longer supported.

* Bulider names are now restricted to unicode strings or ASCII bytestrings.
Encoded bytestrings are not accepted.

..
Any change that adds a feature or fixes a bug should have an entry here.
Most simply need an additional bulleted list item, but more significant
Expand Down

0 comments on commit d13c053

Please sign in to comment.