Exemplo n.º 1
0
    def test_admin_new_release(self):
        """ Test the admin_new_release function. """
        user = None
        with user_set(app.APP, user):
            output = self.app.get('/admin/new', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<title>OpenID transaction in progress</title>'
                in output.data)

        user = FakeFasUser()
        user.groups = []
        user.cla_done = False
        with user_set(app.APP, user):
            output = self.app.get('/admin/new', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">You are not an admin</li>' in output.data)

        user = FakeFasUser()
        user.groups = []
        with user_set(app.APP, user):
            output = self.app.get('/admin/new', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">You are not an admin</li>' in output.data)

        user = FakeFasUser()
        user.groups.append('sysadmin-main')
        with user_set(app.APP, user):
            output = self.app.get('/admin/new')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<title> New release' in output.data)
            self.assertTrue(
                "<label for=\"releasenum\">Release number <span "
                "class='error'>*</span></label>" in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'csrf_token': csrf_token,
                'releasenum': 20,
                'support': 'RELEASE',
            }

            output = self.app.post(
                '/admin/new', data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Release &#34;20&#34; added</li>'
                in output.data)
            self.assertTrue("<a href='/release/20'>" in output.data)
            self.assertTrue("<a href='/admin/20/edit'" in output.data)
Exemplo n.º 2
0
    def test_is_pkgdb_admin(self):
        """ Test the is_pkgdb_admin function of pkgdb2. """
        user = FakeFasUser()
        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, False)

        user.groups = []
        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, False)

        user = FakeFasUser()
        out = pkgdb2.is_pkgdb_admin(None)
        self.assertEqual(out, False)

        user = FakeFasUserAdmin()
        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, True)

        pkgdb2.APP.config['ADMIN_GROUP'] = 'sysadmin-main'

        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, False)

        # Reset the ADMIN_GROUP for the other tests
        pkgdb2.APP.config['ADMIN_GROUP'] = ('sysadmin-main', 'sysadmin-cvs')
Exemplo n.º 3
0
    def test_comaintain_package(self, login_func):
        """ Test the comaintain_package function. """
        login_func.return_value=None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb.APP, user):
            output = self.app.get(
                '/acl/guake/comaintain/', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

            output = self.app.get(
                '/acl/random/comaintain/', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>'
                in output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb.APP, user):
            output = self.app.get(
                '/acl/guake/comaintain/', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">You must be a packager</li>'
                in output.data)
Exemplo n.º 4
0
    def test_is_pkgdb_admin(self):
        """ Test the is_pkgdb_admin function of pkgdb2. """
        user = FakeFasUser()
        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, False)

        user.groups = []
        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, False)

        user = FakeFasUser()
        out = pkgdb2.is_pkgdb_admin(None)
        self.assertEqual(out, False)

        user = FakeFasUserAdmin()
        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, True)

        pkgdb2.APP.config['ADMIN_GROUP'] = 'sysadmin-main'

        out = pkgdb2.is_pkgdb_admin(user)
        self.assertEqual(out, False)

        # Reset the ADMIN_GROUP for the other tests
        pkgdb2.APP.config['ADMIN_GROUP'] = ('sysadmin-main', 'sysadmin-cvs')
    def test_api_package_retire3(self, login_func, mock_func):
        """ Test a third time the api_package_retire function.  """
        login_func.return_value = None
        create_package_acl(self.session)
        mock_func.log.return_value = ''

        # Redirect as you are not a packager
        user = FakeFasUser()
        user.groups = []

        # Add the EPEL 7 collection
        collection = model.Collection(
            name='Fedora EPEL',
            version='7',
            status='Active',
            owner='kevin',
            branchname='epel7',
            dist_tag='.el7',
        )
        self.session.add(collection)
        self.session.commit()

        # Add guake to epel7
        guake_pkg = model.Package.by_name(self.session, 'guake')
        el7_collec = model.Collection.by_name(self.session, 'epel7')

        pkgltg = model.PackageListing(
            point_of_contact='orphan',
            status='Orphaned',
            package_id=guake_pkg.id,
            collection_id=el7_collec.id,
        )
        self.session.add(pkgltg)
        self.session.commit()

        # Retire an orphaned package on an EPEL branch
        user = FakeFasUser()
        data = {
            'pkgnames': 'guake',
            'branches': ['epel7'],
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/retire/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": [""],
                    "output": "ok"
                }
            )
Exemplo n.º 6
0
    def test_is_admin(self):
        """ Test the is_admin method. """
        self.assertFalse(app.is_admin(None))

        user = FakeFasUser()
        user.cla_done = False
        self.assertFalse(app.is_admin(user))

        user = FakeFasUser()
        user.groups = []
        self.assertFalse(app.is_admin(user))

        user = FakeFasUser()
        user.groups.append('sysadmin-main')
        self.assertTrue(app.is_admin(user))
Exemplo n.º 7
0
    def test_comaintain_package(self, login_func):
        """ Test the comaintain_package function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/comaintain/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">You are already a co-maintainer on '
                'F-18</li>' in output.data)
            self.assertFalse(
                '<li class="message">ACLs updated</li>' in output.data)

            output = self.app.get('/acl/random/comaintain/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)

        user = FakeFasUser()
        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/comaintain/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

            output = self.app.get('/acl/random/comaintain/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/comaintain/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<li class="errors">You must be a packager</li>' in
                            output.data)
Exemplo n.º 8
0
    def test_unorphan_package(self):
        """ Test the unorphan_package function. """
        create_package_acl(self.session)

        # Wrong package name
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='asd',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser())

        # Wrong collection
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='asd',
                          pkg_user='******',
                          user=FakeFasUser())

        # Package is not orphaned
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser())

        # Orphan package
        pkgdblib.update_pkg_poc(
            self.session,
            pkg_name='guake',
            clt_name='devel',
            user=FakeFasUserAdmin(),
            pkg_poc='orphan',
        )

        # User cannot unorphan for someone else
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser())

        # User must be a packager
        user = FakeFasUser()
        user.groups = ['cla_done']
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=user)

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        pkgdblib.unorphan_package(self.session,
                                  pkg_name='guake',
                                  clt_name='devel',
                                  pkg_user='******',
                                  user=FakeFasUser())

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')
Exemplo n.º 9
0
    def test_request_acl(self, login_func):
        """ Test the request_acl function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'watchbugzilla',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)
            self.assertTrue(
                '<li class="errors">You must be a packager to apply to the '
                'ACL: commit on devel</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/test/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: test</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/test/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)
Exemplo n.º 10
0
    def test_unorphan_package(self):
        """ Test the unorphan_package function. """
        create_package_acl(self.session)

        # Wrong package name
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='asd',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # Wrong collection
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='asd',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # Package is not orphaned
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # Orphan package
        pkgdblib.update_pkg_poc(self.session,
                                pkg_name='guake',
                                clt_name='devel',
                                user=FakeFasUserAdmin(),
                                pkg_poc='orphan',
                                )

        # User cannot unorphan for someone else
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        # User must be a packager
        user = FakeFasUser()
        user.groups = ['cla_done']
        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.unorphan_package,
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=user
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
        self.assertEqual(pkg_acl[1].status, 'Orphaned')

        pkgdblib.unorphan_package(
                          self.session,
                          pkg_name='guake',
                          clt_name='devel',
                          pkg_user='******',
                          user=FakeFasUser()
                          )

        pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
        self.assertEqual(pkg_acl[1].collection.branchname, 'devel')
        self.assertEqual(pkg_acl[1].package.name, 'guake')
        self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
        self.assertEqual(pkg_acl[1].status, 'Approved')
Exemplo n.º 11
0
    def test_update_acl(self, login_func):
        """ Test the update_acl function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/update/pingou/', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'commit',
                'acl_status': 'Approved',
                'csrf_token': csrf_token,
            }

            output = self.app.post(
                '/acl/guake/update/pingou/', data=data,
                follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/update/test/', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                'No pending ACLs for this user on this package.'
                in output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/update/toshio/devel', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/update/pingou/', follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'watchbugzilla',
                'acl_status': 'Awaiting Review',
                'csrf_token': csrf_token,
            }

            output = self.app.post(
                '/acl/guake/update/pingou/', data=data,
                follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)
Exemplo n.º 12
0
    def test_update_acl(self, login_func):
        """ Test the update_acl function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/update/pingou/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'commit',
                'acl_status': 'Approved',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/update/pingou/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/update/test/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)
            self.assertTrue('No pending ACLs for this user on this package.' in
                            output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/update/toshio/devel',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/update/pingou/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Update ACLs on package: guake</h1>' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'watchbugzilla',
                'acl_status': 'Awaiting Review',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/update/pingou/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)
Exemplo n.º 13
0
    def test_comaintain_package(self, bz_mail_func, login_func, mock_func):
        """ Test the comaintain_package function. """
        login_func.return_value = None
        bz_mail_func.return_value = 1

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/guake/comaintain/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 405)

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/rpms/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post('/acl/rpms/guake/comaintain/',
                                   data=data,
                                   follow_redirects=True)

            self.assertTrue(
                '<li class="error">You are already a co-maintainer on '
                'f18</li>' in output.data)
            self.assertFalse(
                '<li class="message">ACLs updated</li>' in output.data)

            output = self.app.post('/acl/rpms/random/comaintain/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin']

        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/acl/rpms/guake/comaintain/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

            # Nothing to update the second time
            output = self.app.post('/acl/rpms/guake/comaintain/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Nothing to update</li>' in output.data)

            output = self.app.post('/acl/rpms/random/comaintain/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/acl/rpms/guake/comaintain/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<li class="errors">You must be a packager</li>' in
                            output.data)
Exemplo n.º 14
0
    def test_request_acl_all_branch(self, bz_mail_func, login_func, mock_func):
        """ Test the request_acl_all_branch function. """
        login_func.return_value = None
        bz_mail_func.return_value = 1

        create_package_acl(self.session)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin']

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/guake/request/approveacls/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 405)

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/rpms/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post('/acl/rpms/guake/request/approveacls/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                'class="message">ACL approveacls requested on branch f18</li>'
                in output.data)
            self.assertTrue(
                'class="message">ACL approveacls requested on branch master</l'
                in output.data)
            self.assertEqual(output.data.count('<a class="pending"'), 2)

            output = self.app.post('/acl/rpms/guake/request/foobar/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">Invalid ACL provided foobar.</li>' in
                output.data)

            output = self.app.post('/acl/rpms/barfoo/request/commit/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)

        user.username = '******'
        user.groups = []
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/acl/rpms/guake/request/commit/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">You must be a packager to apply to the '
                'ACL: commit on guake</li>' in output.data)

            output = self.app.post('/acl/rpms/guake/request/watchcommits/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACL watchcommits requested on branch '
                'f18</li>' in output.data)
            self.assertTrue(
                '<li class="message">ACL watchcommits requested on branch '
                'master</li>' in output.data)
Exemplo n.º 15
0
    def test_comaintain_package(self, login_func, mock_func):
        """ Test the comaintain_package function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/comaintain/', follow_redirects=True)
            self.assertEqual(output.status_code, 405)

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post(
                '/acl/guake/comaintain/',
                data=data, follow_redirects=True)

            self.assertTrue(
                '<li class="error">You are already a co-maintainer on '
                'f18</li>' in output.data)
            self.assertFalse(
                '<li class="message">ACLs updated</li>' in output.data)

            output = self.app.post(
                '/acl/random/comaintain/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>'
                in output.data)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin']

        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.post(
                '/acl/guake/comaintain/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

            # Nothing to update the second time
            output = self.app.post(
                '/acl/guake/comaintain/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Nothing to update</li>' in output.data)

            output = self.app.post(
                '/acl/random/comaintain/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>'
                in output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.post(
                '/acl/guake/comaintain/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">You must be a packager</li>'
                in output.data)
Exemplo n.º 16
0
    def test_request_acl_all_branch(self, login_func, mock_func):
        """ Test the request_acl_all_branch function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin']

        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/request/approveacls/', follow_redirects=True)
            self.assertEqual(output.status_code, 405)

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post(
                '/acl/guake/request/approveacls/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                'class="message">ACL approveacls requested on branch f18</li>'
                in output.data)
            self.assertTrue(
                'class="message">ACL approveacls requested on branch master</l'
                in output.data)
            self.assertEqual(
                output.data.count('<a class="pending"'), 2)

            output = self.app.post(
                '/acl/guake/request/foobar/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">Invalid ACL provided foobar.</li>'
                in output.data)

            output = self.app.post(
                '/acl/barfoo/request/commit/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>'
                in output.data)

        user.username = '******'
        user.groups = []
        with user_set(pkgdb2.APP, user):
            output = self.app.post(
                '/acl/guake/request/commit/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">You must be a packager to apply to the '
                'ACL: commit on guake</li>'
                in output.data)

            output = self.app.post(
                '/acl/guake/request/watchcommits/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACL watchcommits requested on branch '
                'f18</li>' in output.data)
            self.assertTrue(
                '<li class="message">ACL watchcommits requested on branch '
                'master</li>' in output.data)
Exemplo n.º 17
0
    def test_request_acl(self, login_func):
        """ Test the request_acl function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'watchbugzilla',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<li class="message">ACLs updated</li>' in
                            output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)
            self.assertTrue(
                '<li class="errors">You must be a packager to apply to the '
                'ACL: commit on devel</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/test/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: test</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'pkg_branch': 'devel',
                'pkg_acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/test/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>'
                in output.data)
Exemplo n.º 18
0
    def test_giveup_acl(self, login_func, mock_func):
        """ Test the giveup_acl function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin', 'dodji']

        with user_set(pkgdb2.APP, user):
            output = self.app.get(
                '/acl/guake/giveup/approveacls/', follow_redirects=True)
            self.assertEqual(output.status_code, 405)

        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post(
                '/acl/offlineimap/giveup/approveacls/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No active branches found for you for '
                'the ACL: approveacls</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post(
                '/acl/guake/giveup/approveacls/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Your ACL approveacls is obsoleted on '
                'branch f18 of package guake</li>' in output.data)
            self.assertTrue(
                '<li class="message">Your ACL approveacls is obsoleted on '
                'branch master of package guake</li>' in output.data)
            self.assertEqual(
                output.data.count('<a class="pending"'), 1)

            output = self.app.post(
                '/acl/guake/giveup/foobar/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">Invalid ACL provided foobar.</li>'
                in output.data)

            output = self.app.post(
                '/acl/barfoo/giveup/commit/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>'
                in output.data)

        user.username = '******'
        user.groups = []
        with user_set(pkgdb2.APP, user):
            output = self.app.post(
                '/acl/guake/giveup/commit/',
                data=data, follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">User &#34;toshio&#34; is not in the '
                'packager group</li>' in output.data)
Exemplo n.º 19
0
    def test_api_package_orphan(self, login_func, mock_func):
        """ Test the api_package_orphan function.  """
        login_func.return_value = None

        # Redirect as you are not a packager
        user = FakeFasUser()
        user.groups = []

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/orphan/')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/orphan/')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "pkgnames: This field is required.",
                        "branches: This field is required.",
                    ],
                    "output": "notok"
                }
            )

        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/orphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "No package found by this name",
                    "output": "notok"
                }
            )

        create_package_acl(self.session)
        mock_func.log.return_value = ''

        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/orphan/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": ["", ""],
                    "output": "ok"
                }
            )
            pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
            self.assertEqual(pkg_acl[0].collection.branchname, 'f18')
            self.assertEqual(pkg_acl[0].package.name, 'guake')
            self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
            self.assertEqual(pkg_acl[0].status, 'Orphaned')

            self.assertEqual(pkg_acl[1].collection.branchname, 'master')
            self.assertEqual(pkg_acl[1].package.name, 'guake')
            self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
            self.assertEqual(pkg_acl[1].status, 'Orphaned')
Exemplo n.º 20
0
    def test_request_acl(self, login_func, mock_func):
        """ Test the request_acl function. """
        login_func.return_value = None

        create_package_acl(self.session)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin']

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'branches': 'master',
                'acl': 'watchbugzilla',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<li class="message">ACLs updated</li>' in
                            output.data)

        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'branches': 'master',
                'acl': 'watchbugzilla',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue('<li class="message">ACLs updated</li>' in
                            output.data)

            data = {
                'branches': 'master',
                'acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                'class="error">User &#34;Toshio&#34; is not in the packager'
                ' group</' in output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'branches': 'master',
                'acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/guake/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)
            self.assertTrue(
                '<li class="errors">You must be a packager to apply to the '
                'ACL: commit on master</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/test/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">No package of this name found.</li>'
                in output.data)

            data = {
                'branches': 'master',
                'acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/test/request/', data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">No package of this name found.</li>'
                in output.data)
Exemplo n.º 21
0
    def test_api_package_unorphan(self, login_func, mock_func):
        """ Test the api_package_unorphan function.  """
        login_func.return_value = None

        # Redirect as you are not a packager
        user = FakeFasUser()
        user.groups = []

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unorphan/')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unorphan/')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "pkgnames: This field is required.",
                        "branches: This field is required.",
                        "poc: This field is required.",
                    ],
                    "output": "notok"
                }
            )

        mock_func.get_packagers.return_value = ['test']

        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "No package found by this name",
                    "output": "notok"
                }
            )

        create_package_acl(self.session)
        mock_func.log.return_value = ''

        # Unorphan a not-orphaned package
        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Package \"guake\" is not orphaned on f18",
                    "output": "notok"
                }
            )

        # Orphan the package
        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/orphan/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": ["", ""],
                    "output": "ok"
                }
            )
            pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
            self.assertEqual(pkg_acl[0].collection.branchname, 'f18')
            self.assertEqual(pkg_acl[0].package.name, 'guake')
            self.assertEqual(pkg_acl[0].point_of_contact, 'orphan')
            self.assertEqual(pkg_acl[0].status, 'Orphaned')

            self.assertEqual(pkg_acl[1].collection.branchname, 'master')
            self.assertEqual(pkg_acl[1].package.name, 'guake')
            self.assertEqual(pkg_acl[1].point_of_contact, 'orphan')
            self.assertEqual(pkg_acl[1].status, 'Orphaned')

        # Unorphan the package for someone else
        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "You are not allowed to update ACLs of someone "
                    "else.",
                    "output": "notok"
                }
            )

        mock_func.get_packagers.return_value = ['pingou']

        # Unorphan the package
        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'pingou',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unorphan/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": [
                        "Package guake has been unorphaned on f18 by pingou",
                        "Package guake has been unorphaned on master by pingou"
                    ],
                    "output": "ok"
                }
            )

            pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
            self.assertEqual(pkg_acl[0].collection.branchname, 'f18')
            self.assertEqual(pkg_acl[0].package.name, 'guake')
            self.assertEqual(pkg_acl[0].point_of_contact, 'pingou')
            self.assertEqual(pkg_acl[0].status, 'Approved')

            self.assertEqual(pkg_acl[1].collection.branchname, 'master')
            self.assertEqual(pkg_acl[1].package.name, 'guake')
            self.assertEqual(pkg_acl[1].point_of_contact, 'pingou')
            self.assertEqual(pkg_acl[1].status, 'Approved')
Exemplo n.º 22
0
    def test_giveup_acl(self, bz_mail_func, login_func, mock_func):
        """ Test the giveup_acl function. """
        login_func.return_value = None
        bz_mail_func.return_value = 1

        create_package_acl(self.session)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin', 'dodji']

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/guake/giveup/approveacls/',
                                  follow_redirects=True)
            self.assertEqual(output.status_code, 405)

        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/rpms/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            output = self.app.post(
                '/acl/docker/offlineimap/giveup/approveacls/',
                data=data,
                follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No active branches found for you for '
                'the ACL: approveacls</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/package/rpms/guake/')
            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
            data = {'csrf_token': csrf_token}

            print 'give up'
            output = self.app.post('/acl/rpms/guake/giveup/approveacls/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">Your ACL approveacls is obsoleted on '
                'branch f18 of package guake</li>' in output.data)
            self.assertTrue(
                '<li class="message">Your ACL approveacls is obsoleted on '
                'branch master of package guake</li>' in output.data)
            #print output.data
            self.assertEqual(output.data.count('<a class="pending"'), 1)

            output = self.app.post('/acl/rpms/guake/giveup/foobar/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">Invalid ACL provided foobar.</li>' in
                output.data)

            output = self.app.post('/acl/rpms/barfoo/giveup/commit/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="error">No package found by this name</li>' in
                output.data)

        user.username = '******'
        user.groups = []
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/acl/rpms/guake/giveup/commit/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertFalse(
                '<li class="error">User &#34;toshio&#34; is not in the '
                'packager group</li>' in output.data)
Exemplo n.º 23
0
    def test_api_package_unretire(self, login_func, mock_func):
        """ Test the api_package_unretire function.  """
        login_func.return_value = None

        # Redirect as you are not a packager
        user = FakeFasUser()
        user.groups = []

        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unretire/')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unretire/')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "pkgnames: This field is required.",
                        "branches: This field is required.",
                    ],
                    "output": "notok"
                }
            )

        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
            'poc': 'test',
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unretire/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "No package found by this name",
                    "output": "notok"
                }
            )

        create_package_acl(self.session)
        mock_func.log.return_value = ''

        # User is not an admin
        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unretire/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "You are not allowed to update the status of "
                             "the package: guake on branch f18 to "
                             "Approved.",
                    "output": "notok"
                }
            )

        # Unretire the package
        user = FakeFasUserAdmin()
        data = {
            'pkgnames': 'guake',
            'branches': ['f18', 'master'],
        }
        with user_set(pkgdb2.APP, user):
            output = self.app.post('/api/package/unretire/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": ["", ""],
                    "output": "ok"
                }
            )
Exemplo n.º 24
0
    def test_request_acl(self, bz_mail_func, login_func, mock_func):
        """ Test the request_acl function. """
        login_func.return_value = None
        bz_mail_func.return_value = 1

        create_package_acl(self.session)

        user = FakeFasUser()
        mock_func.return_value = ['pingou', 'ralph', 'kevin']

        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'branches': 'master',
                'acl': 'watchbugzilla',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/rpms/guake/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

        user.username = '******'
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'branches': 'master',
                'acl': 'watchbugzilla',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/rpms/guake/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)

            data = {
                'branches': 'master',
                'acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/rpms/guake/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                'class="error">User &#34;Toshio&#34; is not in the packager'
                ' group</' in output.data)

        user = FakeFasUser()
        user.groups = ['gitr2spec']
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/guake/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<h1>Request ACLs on package: guake</h1>' in output.data)
            self.assertTrue(
                '<input id="csrf_token" name="csrf_token"' in output.data)
            self.assertTrue(
                '<option value="approveacls">approveacls' in output.data)

            csrf_token = output.data.split(
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]

            data = {
                'branches': 'master',
                'acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/rpms/guake/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="message">ACLs updated</li>' in output.data)
            self.assertTrue(
                '<li class="errors">You must be a packager to apply to the '
                'ACL: commit on master</li>' in output.data)

        user = FakeFasUser()
        with user_set(pkgdb2.APP, user):
            output = self.app.get('/acl/rpms/test/request/')
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">No package of this name found.</li>' in
                output.data)

            data = {
                'branches': 'master',
                'acl': 'commit',
                'csrf_token': csrf_token,
            }

            output = self.app.post('/acl/rpms/test/request/',
                                   data=data,
                                   follow_redirects=True)
            self.assertEqual(output.status_code, 200)
            self.assertTrue(
                '<li class="errors">No package of this name found.</li>' in
                output.data)
Exemplo n.º 25
0
    def test_api_package_retire(self, login_func, mock_func):
        """ Test the api_package_retire function.  """
        login_func.return_value=None

        # Redirect as you are not a packager
        user = FakeFasUser()
        user.groups = []

        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/retire/')
            self.assertEqual(output.status_code, 302)

        user = FakeFasUser()
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/retire/')
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "Invalid input submitted",
                    "error_detail": [
                        "clt_name: This field is required.",
                        "pkg_name: This field is required."
                    ],
                    "output": "notok"
                }
            )

        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
            'pkg_poc': 'test',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/retire/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "No package found by this name",
                    "output": "notok"
                }
            )

        create_package_acl(self.session)
        mock_func.log.return_value = ''

        # User is not an admin
        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/retire/', data=data)
            self.assertEqual(output.status_code, 500)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "error": "You are not allowed to retire the package: "
                             "guake on branch F-18.",
                    "output": "notok"
                }

            )

        # Retire the package
        user = FakeFasUserAdmin()
        data = {
            'pkg_name': 'guake',
            'clt_name': 'F-18,devel',
        }
        with user_set(pkgdb.APP, user):
            output = self.app.post('/api/package/retire/', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.data)
            self.assertEqual(
                data,
                {
                    "messages": ["", ""],
                    "output": "ok"
                }
            )