Пример #1
0
    def test_default(self):
        master = self.make_master(url='http://a/b/', auth=auth.NoAuth(), avatar_methods=[])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, '/')
        self.assertEquals(res, dict(redirected=avatar.AvatarResource.defaultAvatarUrl))
Пример #2
0
    def __init__(self):
        # local import to avoid circular imports
        from buildbot.process import properties
        # default values for all attributes

        # global
        self.title = 'Buildbot'
        self.titleURL = 'http://buildbot.net'
        self.buildbotURL = 'http://localhost:8080/'
        self.changeHorizon = None
        self.eventHorizon = 50
        self.logHorizon = None
        self.buildHorizon = None
        self.logCompressionLimit = 4 * 1024
        self.logCompressionMethod = 'gz'
        self.logEncoding = 'utf-8'
        self.logMaxSize = None
        self.logMaxTailSize = None
        self.properties = properties.Properties()
        self.collapseRequests = None
        self.codebaseGenerator = None
        self.prioritizeBuilders = None
        self.multiMaster = False
        self.manhole = None
        self.protocols = {}

        self.validation = dict(
            branch=re.compile(r'^[\w.+/~-]*$'),
            revision=re.compile(r'^[ \w\.\-/]*$'),
            property_name=re.compile(r'^[\w\.\-/~:]*$'),
            property_value=re.compile(r'^[\w\.\-/~:]*$'),
        )
        self.db = dict(
            db_url=DEFAULT_DB_URL,
        )
        self.mq = dict(
            type='simple',
        )
        self.metrics = None
        self.caches = dict(
            Builds=15,
            Changes=10,
        )
        self.schedulers = {}
        self.builders = []
        self.workers = []
        self._registerOldWorkerAttr("workers")
        self.change_sources = []
        self.status = []
        self.user_managers = []
        self.revlink = default_revlink_matcher
        self.www = dict(
            port=None,
            plugins=dict(),
            auth=auth.NoAuth(),
            authz=authz.Authz(),
            avatar_methods=avatar.AvatarGravatar(),
            logfileName='http.log',
        )
        self.services = {}
Пример #3
0
    def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()
        master = self.make_master(url='h:/a/b/', auth=_auth)
        rsrc = config.IndexResource(master, "foo")
        rsrc.reconfigResource(master.config)
        rsrc.jinja = mock.Mock()
        template = mock.Mock()
        rsrc.jinja.get_template = lambda x: template
        template.render = lambda configjson, config: configjson

        res = yield self.render_resource(rsrc, '/')
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = '{"titleURL": "http://buildbot.net", "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        self.assertIn(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"email": "*****@*****.**", "name": "me"}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        self.assertIn(res, exp)

        master = self.make_master(url='h:/a/c/', auth=_auth)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        self.assertIn(res, exp)
Пример #4
0
    def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()

        custom_versions = [('test compoent', '0.1.2'), ('test component 2', '0.2.1')]

        master = self.make_master(url='h:/a/b/', auth=_auth, versions=custom_versions)
        rsrc = config.IndexResource(master, "foo")
        rsrc.reconfigResource(master.config)
        rsrc.jinja = mock.Mock()
        template = mock.Mock()
        rsrc.jinja.get_template = lambda x: template
        template.render = lambda configjson, config: configjson

        vjson = json.dumps(rsrc.getEnvironmentVersions() + custom_versions)

        res = yield self.render_resource(rsrc, '/')
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = '{"titleURL": "http://buildbot.net", "versions": %s, "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        exp = exp % vjson
        self.assertIn(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "versions": %s, "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"email": "*****@*****.**", "name": "me"}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        exp = exp % vjson
        self.assertIn(res, exp)

        master = self.make_master(url='h:/a/c/', auth=_auth, versions=custom_versions)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, '/')
        exp = '{"titleURL": "http://buildbot.net", "versions": %s, "title": "Buildbot", "auth": {"name": "NoAuth"}, "user": {"anonymous": true}, "buildbotURL": "h:/a/b/", "multiMaster": false, "port": null}'
        exp = exp % vjson
        self.assertIn(res, exp)
Пример #5
0
    def setUp(self):
        self.setup_test_reactor()

        avatar_method = avatar.AvatarGitHub(client_id="oauth_id",
                                            client_secret="oauth_secret")
        master = self.make_master(url='http://a/b/',
                                  auth=auth.NoAuth(),
                                  avatar_methods=[avatar_method])

        self.rsrc = avatar.AvatarResource(master)
        self.rsrc.reconfigResource(master.config)

        headers = {
            'User-Agent': 'Buildbot',
            # oauth_id:oauth_secret in Base64
            'Authorization': 'basic b2F1dGhfaWQ6b2F1dGhfc2VjcmV0',
        }
        self._http = yield fakehttpclientservice.HTTPClientService.getService(
            master,
            self,
            avatar.AvatarGitHub.DEFAULT_GITHUB_API_URL,
            headers=headers,
            debug=False,
            verify=False)
        yield self.master.startService()
Пример #6
0
    def test_gravatar(self):
        master = self.make_master(url='http://a/b/', auth=auth.NoAuth(), avatar_methods=[avatar.AvatarGravatar()])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, '/?email=foo')
        self.assertEquals(res, dict(redirected='//www.gravatar.com/avatar/acbd18db4cc2f85ce'
                                               'def654fccc4a4d8?s=32&d=http%3A%2F%2Fa%2Fb%2Fimg%2Fnobody.png'))
Пример #7
0
 def makeConfig(self, **kwargs):
     w = dict(port=None, auth=auth.NoAuth(), logfileName='l')
     w.update(kwargs)
     new_config = mock.Mock()
     new_config.www = w
     new_config.buildbotURL = 'h:/'
     self.master.config = new_config
     return new_config
Пример #8
0
 def makeConfig(self, **kwargs):
     pwd = os.getcwd()
     w = dict(url='h:/', port=None, public_html=pwd, auth=auth.NoAuth())
     w.update(kwargs)
     new_config = mock.Mock()
     new_config.www = w
     self.master.config = new_config
     return new_config
Пример #9
0
    def test_invalid_size(self):
        master = self.make_master(url='http://a/b/',
                                  auth=auth.NoAuth(),
                                  avatar_methods=[TestAvatar()])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, b'/?email=foo&size=abcd')
        self.assertEqual(res, b"b'foo' 32 b'http://a/b/img/nobody.png'")
Пример #10
0
    def make_master(self, **kwargs):
        master = fakemaster.make_master(wantData=True, testcase=self)
        self.master = master
        master.www = mock.Mock()  # to handle the resourceNeedsReconfigs call
        cfg = dict(url='//', port=None, auth=auth.NoAuth())
        cfg.update(kwargs)
        master.config.www = cfg
        self.master.session = FakeSession()

        return master
Пример #11
0
    def test_github(self):
        master = self.make_master(url='http://a/b/',
                                  auth=auth.NoAuth(),
                                  avatar_methods=[avatar.AvatarGitHub()])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, b'/?username=warner')
        self.assertEqual(
            res,
            dict(redirected=b'https://avatars.githubusercontent.com/warner'))
Пример #12
0
    def setUp(self):
        # set up a full master serving HTTP
        yield self.setUpRealDatabase(table_names=['masters', 'objects', 'object_state'],
                                     sqlite_memory=False)

        master = fakemaster.FakeMaster(reactor)

        master.config.db = dict(db_url=self.db_url)
        master.db = dbconnector.DBConnector('basedir')
        yield master.db.setServiceParent(master)
        yield master.db.setup(check_version=False)

        master.config.mq = dict(type='simple')
        master.mq = mqconnector.MQConnector()
        yield master.mq.setServiceParent(master)
        yield master.mq.setup()

        master.data = dataconnector.DataConnector()
        yield master.data.setServiceParent(master)

        master.config.www = dict(
            port='tcp:0:interface=127.0.0.1',
            debug=True,
            auth=auth.NoAuth(),
            authz=authz.Authz(),
            avatar_methods=[],
            logfileName='http.log')
        master.www = wwwservice.WWWService()
        yield master.www.setServiceParent(master)
        yield master.www.startService()
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)
        session = mock.Mock()
        session.uid = "0"
        master.www.site.sessionFactory = mock.Mock(return_value=session)

        # now that we have a port, construct the real URL and insert it into
        # the config.  The second reconfig isn't really required, but doesn't
        # hurt.
        self.url = 'http://127.0.0.1:%d/' % master.www.getPortnum()
        self.url = unicode2bytes(self.url)
        master.config.buildbotURL = self.url
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)

        self.master = master

        # build an HTTP agent, using an explicit connection pool if Twisted
        # supports it (Twisted 13.0.0 and up)
        if hasattr(client, 'HTTPConnectionPool'):
            self.pool = client.HTTPConnectionPool(reactor)
            self.agent = client.Agent(reactor, pool=self.pool)
        else:
            self.pool = None
            self.agent = client.Agent(reactor)
Пример #13
0
    def test_gravatar(self):
        master = self.make_master(url='http://a/b/',
                                  auth=auth.NoAuth(),
                                  avatar_methods=[avatar.AvatarGravatar()])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, b'/?email=foo')
        self.assertEqual(
            res,
            dict(redirected=b'//www.gravatar.com/avatar/acbd18db4cc2f85ce'
                 b'def654fccc4a4d8?d=retro&s=32'))
Пример #14
0
    def test_custom(self):
        class CustomAvatar(avatar.AvatarBase):

            def getUserAvatar(self, email, size, defaultAvatarUrl):
                return defer.succeed(("image/png", email + str(size) + defaultAvatarUrl))

        master = self.make_master(url='http://a/b/', auth=auth.NoAuth(), avatar_methods=[CustomAvatar()])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, '/?email=foo')
        self.assertEquals(res, "foo32http://a/b/img/nobody.png")
Пример #15
0
 def make_master(self, url=None, **kwargs):
     master = fakemaster.make_master(wantData=True, testcase=self)
     self.master = master
     master.www = mock.Mock()  # to handle the resourceNeedsReconfigs call
     master.www.getUserInfos = lambda _: getattr(self.master.session, "user_info", {"anonymous": True})
     cfg = dict(port=None, auth=auth.NoAuth(), authz=authz.Authz())
     cfg.update(kwargs)
     master.config.www = cfg
     if url is not None:
         master.config.buildbotURL = url
     self.master.session = FakeSession()
     self.master.authz = cfg["authz"]
     self.master.authz.setMaster(self.master)
     return master
Пример #16
0
    def test_custom_not_found(self):
        # use gravatar if the custom avatar fail to return a response
        class CustomAvatar(avatar.AvatarBase):

            def getUserAvatar(self, email, size, defaultAvatarUrl):
                return defer.succeed(None)

        master = self.make_master(url='http://a/b/', auth=auth.NoAuth(),
                                  avatar_methods=[CustomAvatar(), avatar.AvatarGravatar()])
        rsrc = avatar.AvatarResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, '/?email=foo')
        self.assertEquals(res, dict(redirected='//www.gravatar.com/avatar/acbd18db4cc2f85ce'
                                               'def654fccc4a4d8?s=32&d=http%3A%2F%2Fa%2Fb%2Fimg%2Fnobody.png'))
Пример #17
0
    def setUp(self):
        # set up a full master serving HTTP
        yield self.setUpRealDatabase(table_names=['masters'],
                                     sqlite_memory=False)

        master = fakemaster.FakeMaster()

        master.config.db = dict(db_url=self.db_url)
        master.db = dbconnector.DBConnector(master, 'basedir')
        yield master.db.setup(check_version=False)

        master.config.mq = dict(type='simple')
        master.mq = mqconnector.MQConnector(master)
        master.mq.setup()

        master.data = dataconnector.DataConnector(master)

        master.config.www = dict(port='tcp:0:interface=127.0.0.1',
                                 debug=True,
                                 auth=auth.NoAuth(),
                                 url="not yet known",
                                 avatar_methods=[])
        master.www = wwwservice.WWWService(master)
        yield master.www.startService()
        yield master.www.reconfigService(master.config)

        # now that we have a port, construct the real URL and insert it into
        # the config.  The second reconfig isn't really required, but doesn't
        # hurt.
        self.url = 'http://127.0.0.1:%d/' % master.www.getPortnum()
        master.config.www['url'] = self.url
        yield master.www.reconfigService(master.config)

        self.master = master

        # build an HTTP agent, using an explicit connection pool if Twisted
        # supports it (Twisted 13.0.0 and up)
        if hasattr(client, 'HTTPConnectionPool'):
            self.pool = client.HTTPConnectionPool(reactor)
            self.agent = client.Agent(reactor, pool=self.pool)
        else:
            self.pool = None
            self.agent = client.Agent(reactor)
def processwwwindex(config):
    master = yield fakemaster.make_master()
    master_service = WWWService()
    master_service.setServiceParent(master)
    if not config.get('index-file'):
        print(
            "Path to the index.html file is required with option --index-file or -i"
        )
        defer.returnValue(1)
    path = config.get('index-file')
    if not os.path.isfile(path):
        print("Invalid path to index.html")
        defer.returnValue(2)

    main_dir = os.path.dirname(path)

    for name in master_service.apps.names:
        if name != 'base':
            pluginapp = master_service.apps.get(name)
            try:
                os.symlink(pluginapp.static_dir, os.path.join(main_dir, name))
            except OSError:
                pass

    plugins = dict((k, {}) for k in master_service.apps.names if k != "base")

    fakeconfig = {"user": {"anonymous": True}}
    fakeconfig['buildbotURL'] = master.config.buildbotURL
    fakeconfig['title'] = master.config.title
    fakeconfig['titleURL'] = master.config.titleURL
    fakeconfig['multiMaster'] = master.config.multiMaster
    fakeconfig['versions'] = IndexResource.getEnvironmentVersions()
    fakeconfig['plugins'] = plugins
    fakeconfig['auth'] = auth.NoAuth().getConfigDict()
    outputstr = ''
    with open(path) as indexfile:
        template = jinja2.Template(indexfile.read())
        outputstr = template.render(configjson=json.dumps(fakeconfig),
                                    config=fakeconfig)
    with open(path, 'w') as indexfile:
        indexfile.write(outputstr)
    defer.returnValue(0)
Пример #19
0
    def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()
        master = self.make_master(url='h:/a/b/', auth=_auth)
        rsrc = config.SessionConfigResource(master)
        rsrc.reconfigResource(master.config)

        res = yield self.render_resource(rsrc, '/')
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = 'this.config = {"url": "h:/a/b/", "user": {"anonymous": true}, "auth": {"name": "NoAuth"}, "port": null}'
        self.assertEqual(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, '/')
        exp = 'this.config = {"url": "h:/a/b/", "user": {"email": "*****@*****.**", "name": "me"}, "auth": {"name": "NoAuth"}, "port": null}'
        self.assertEqual(res, exp)

        master = self.make_master(url='h:/a/c/', auth=_auth)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, '/')
        exp = 'this.config = {"url": "h:/a/c/", "user": {"anonymous": true}, "auth": {"name": "NoAuth"}, "port": null}'
        self.assertEqual(res, exp)
Пример #20
0
    def setUp(self):
        self.setUpTestReactor()

        master = self.make_master(
            url='http://a/b/',
            auth=auth.NoAuth(),
            avatar_methods=[avatar.AvatarGitHub(token="abcd")])

        self.rsrc = avatar.AvatarResource(master)
        self.rsrc.reconfigResource(master.config)

        headers = {
            'User-Agent': 'Buildbot',
            'Authorization': 'token abcd',
        }
        self._http = yield fakehttpclientservice.HTTPClientService.getService(
            master,
            self,
            avatar.AvatarGitHub.DEFAULT_GITHUB_API_URL,
            headers=headers,
            debug=False,
            verify=False)
        yield self.master.startService()
Пример #21
0
 def setUp(self):
     self.auth = auth.RemoteUserAuth(header=b'HDR')
     self.auth = auth.NoAuth()
     self.make_master()
Пример #22
0
    def setUp(self):
        yield self.setUpRealDatabase(table_names=[
            'objects', 'object_state', 'masters', 'workers',
            'configured_workers', 'connected_workers', 'builder_masters',
            'builders'
        ],
                                     sqlite_memory=False)
        master = fakemaster.FakeMaster(reactor)

        master.data = dataconnector.DataConnector()
        master.data.setServiceParent(master)

        master.config.db = dict(db_url=self.db_url)
        master.db = dbconnector.DBConnector('basedir')
        master.db.setServiceParent(master)
        yield master.db.setup(check_version=False)

        master.config.mq = dict(type='simple')
        master.mq = mqconnector.MQConnector()
        master.mq.setServiceParent(master)
        master.mq.setup()

        master.config.www = dict(port='tcp:0:interface=127.0.0.1',
                                 debug=True,
                                 auth=auth.NoAuth(),
                                 authz=authz.Authz(),
                                 avatar_methods=[],
                                 logfileName='http.log')
        master.www = wwwservice.WWWService()
        master.www.setServiceParent(master)
        yield master.www.startService()
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)
        session = mock.Mock()
        session.uid = "0"
        master.www.site.sessionFactory = mock.Mock(return_value=session)

        # now that we have a port, construct the real URL and insert it into
        # the config.  The second reconfig isn't really required, but doesn't
        # hurt.
        self.url = 'http://127.0.0.1:%d/' % master.www.getPortnum()
        self.url = unicode2bytes(self.url)
        master.config.buildbotURL = self.url
        yield master.www.reconfigServiceWithBuildbotConfig(master.config)

        self.master = master

        self.agent = client.Agent(reactor)

        # create a telegram bot service
        tb = master.config.services['TelegramBot'] = telegram.TelegramBot(
            bot_token='12345:secret',
            useWebhook=True,
            chat_ids=[-123456],
            notify_events=['worker'])
        tb._get_http = self.get_http
        tb.setServiceParent(self.master)
        self.bot_url = self.url + b"telegram12345:secret"

        yield tb.startService()

        self.sent_messages = []

        def send_message(chat, message, **kwargs):
            self.sent_messages.append((chat, message))

        tb.bot.send_message = send_message
Пример #23
0
    def test_render(self):
        _auth = auth.NoAuth()
        _auth.maybeAutoLogin = mock.Mock()

        custom_versions = [
            ['test compoent', '0.1.2'], ['test component 2', '0.2.1']]

        master = self.make_master(
            url='h:/a/b/', auth=_auth, versions=custom_versions)
        rsrc = config.IndexResource(master, "foo")
        rsrc.reconfigResource(master.config)
        rsrc.jinja = mock.Mock()
        template = mock.Mock()
        rsrc.jinja.get_template = lambda x: template
        template.render = lambda configjson, config, custom_templates: configjson

        vjson = [list(v)
                 for v in rsrc.getEnvironmentVersions()] + custom_versions

        res = yield self.render_resource(rsrc, b'/')
        res = json.loads(bytes2unicode(res))
        _auth.maybeAutoLogin.assert_called_with(mock.ANY)
        exp = {
            "authz": {},
            "titleURL": "http://buildbot.net",
            "versions": vjson,
            "title": "Buildbot",
            "auth": {"name": "NoAuth"},
            "user": {"anonymous": True},
            "buildbotURL": "h:/a/b/",
            "multiMaster": False,
            "port": None
        }
        self.assertEqual(res, exp)

        master.session.user_info = dict(name="me", email="*****@*****.**")
        res = yield self.render_resource(rsrc, b'/')
        res = json.loads(bytes2unicode(res))
        exp = {
            "authz": {},
            "titleURL": "http://buildbot.net",
            "versions": vjson,
            "title": "Buildbot",
            "auth": {"name": "NoAuth"},
            "user": {"email": "*****@*****.**", "name": "me"},
            "buildbotURL": "h:/a/b/",
            "multiMaster": False,
            "port": None
        }
        self.assertEqual(res, exp)

        master = self.make_master(
            url='h:/a/c/', auth=_auth, versions=custom_versions)
        rsrc.reconfigResource(master.config)
        res = yield self.render_resource(rsrc, b'/')
        res = json.loads(bytes2unicode(res))
        exp = {
            "authz": {},
            "titleURL": "http://buildbot.net",
            "versions": vjson,
            "title": "Buildbot",
            "auth": {"name": "NoAuth"},
            "user": {"anonymous": True},
            "buildbotURL": "h:/a/b/",
            "multiMaster": False,
            "port": None
        }
        self.assertEqual(res, exp)