コード例 #1
0
ファイル: test_group_edit.py プロジェクト: ShaolongHu/beaker
    def test_show_group_owners(self):
        with session.begin():
            owner = data_setup.create_user(user_name='zzzz', password='******')
            group = data_setup.create_group(owner=owner)
            member1 = data_setup.create_user(user_name='aaaa', password='******')
            member1.groups.append(group)
            member2 = data_setup.create_user(user_name='bbbb', password='******')
            member2.groups.append(group)

        b = self.browser
        login(b, user=member1.user_name, password='******')
        b.get(get_server_base() + 'groups/edit?group_id=%d' % group.group_id)

        # the first entry should always be the owner(s)
        user_name, ownership = b.find_element_by_xpath('//table[@id="group_members_grid"]//tr[1]/td[1]').text, \
            b.find_element_by_xpath('//table[@id="group_members_grid"]//tr[1]/td[2]').text

        self.assertTrue(user_name, owner.user_name)
        self.assertTrue(ownership, 'Yes')

        user_name, ownership = b.find_element_by_xpath('//table[@id="group_members_grid"]//tr[2]/td[1]').text, \
            b.find_element_by_xpath('//table[@id="group_members_grid"]//tr[2]/td[2]').text

        self.assertTrue(user_name in [member1.user_name, member2.user_name])
        self.assertTrue(ownership, 'No')
コード例 #2
0
    def test_add_rule_for_new_user(self):
        with session.begin():
            data_setup.create_user(user_name=u'marple')
        b = self.browser
        login(b, user=self.system_owner.user_name, password='******')
        b.get(get_server_base() + 'view/%s/' % self.system.fqdn)
        b.find_element_by_link_text('Access Policy').click()

        # grant edit_policy permission to marple user
        pane = b.find_element_by_id('access-policy')
        pane.find_element_by_xpath('.//input[@placeholder="Username"]')\
            .send_keys('marple')
        # There is a small race here between typing and the typeahead 
        # suggestions appearing. I don't think humans can hit it, but the tests 
        # can, so we make sure the typeahead suggestion has appeared before we 
        # press tab.
        pane.find_element_by_xpath('.//div[@class="tt-suggestion" and '
                'contains(string(.), "marple")]')
        pane.find_element_by_xpath('.//input[@placeholder="Username"]')\
            .send_keys('\t')
        self.find_checkbox('marple', 'Edit this policy').click()
        self.check_row_is_dirty('marple')
        pane.find_element_by_xpath('.//button[text()="Save changes"]').click()
        self.check_row_is_not_dirty('marple')

        # refresh to check it has been persisted
        b.get(get_server_base() + 'view/%s/' % self.system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        self.assertTrue(self.find_checkbox('marple', 'Edit this policy').is_selected())
コード例 #3
0
ファイル: test_system_pools.py プロジェクト: omps/beaker
 def setUp(self):
     with session.begin():
         self.owner = data_setup.create_user(password='******')
         self.pool = data_setup.create_system_pool(owning_user=self.owner)
         self.user = data_setup.create_user()
         self.pool.access_policy.add_rule(user=self.user,
                                          permission=SystemPermission.edit_system)
コード例 #4
0
 def test_give_away_permission(self):
     with session.begin():
         user = data_setup.create_user(password='******')
         owner = data_setup.create_user(password='******')
         system = data_setup.create_system(owner=owner)
         pool = data_setup.create_system_pool(systems=[system])
         pool.access_policy.add_rule(user=user,
                                     permission=SystemPermission.edit_policy)
         system.active_access_policy = pool.access_policy
     b = self.browser
     login(b, user=user.user_name, password='******')
     b.get(get_server_base() + 'view/%s/' % system.fqdn)
     b.find_element_by_link_text('Access Policy').click()
     pane = b.find_element_by_id('access-policy')
     # Currently the system is using a pool access policy
     self.assertTrue(pane.find_element_by_xpath(
         '//label[contains(string(.), "Use policy from pool:")]'
         '/input[@type="radio"]').is_selected())
     # change to custom access policy
     pane.find_element_by_xpath(
                        '//label[contains(string(.), "Use custom access policy")]'
                        '/input[@type="radio"]').click()
     pane.find_element_by_xpath('.//button[text()="Save changes"]').click()
     pane.find_element_by_xpath('//div[@id="access-policy" and not (.//div[@class="form-actions"])]')
     self.assertTrue(pane.find_element_by_xpath(
         '//label[contains(string(.), "Use custom access policy")]'
         '/input[@type="radio"]').is_selected())
     # The radio buttons should be read only
     self.assertFalse(b.find_element_by_xpath(
         '//label[contains(string(.), "Use policy from pool:")]'
         '/input[@type="radio"]').is_enabled())
     self.assertFalse(b.find_element_by_xpath(
         '//label[contains(string(.), "Use custom access policy")]'
         '/input[@type="radio"]').is_enabled())
コード例 #5
0
    def test_job_group(self):
        with session.begin():
            user_in_group = data_setup.create_user(password='******')
            group = data_setup.create_group()
            user_in_group.groups.append(group)
            user_not_in_group = data_setup.create_user(password='******')

        # Test submitting on behalf of user's group
        config1 = create_client_config(username=user_in_group.user_name,
            password='******')
        out = run_client(['bkr', 'workflow-simple', '--random',
                '--arch', self.distro_tree.arch.arch,
                '--family', self.distro.osversion.osmajor.osmajor,
                '--job-group', group.group_name,
                '--task', self.task.name], config=config1)
        self.assertTrue(out.startswith('Submitted:'), out)
        m = re.search('J:(\d+)', out)
        job_id = m.group(1)
        with session.begin():
            job = Job.by_id(job_id)
        self.assertEqual(group, job.group)

        # Test submitting on behalf of group user does not belong to
        config2 = create_client_config(username=user_not_in_group.user_name,
            password='******')
        try:
            out2 = run_client(['bkr', 'workflow-simple', '--random',
                    '--arch', self.distro_tree.arch.arch,
                    '--family', self.distro.osversion.osmajor.osmajor,
                    '--job-group', group.group_name,
                    '--task', self.task.name], config=config2)
            fail('should raise')
        except ClientError, e:
            self.assertTrue('You are not a member of the %s group' % \
                group.group_name in e.stderr_output, e)
コード例 #6
0
    def test_add_systems_pool_privileges(self):
        pool_name = data_setup.unique_name(u'mypool%s')
        with session.begin():
            system_owner = data_setup.create_user(password=u'password')
            pool_owner = data_setup.create_user(password=u'password')
            s1 = data_setup.create_system(owner=system_owner)
            pool = data_setup.create_system_pool(name=pool_name,
                                                 owning_user=pool_owner)
        try:
            run_client(['bkr', 'pool-add', '--pool', pool_name,
                        '--system', s1.fqdn],
                       config=create_client_config(
                           username=system_owner.user_name,
                           password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn('You do not have permission to'
                          ' add systems to pool %s' % pool_name,
                          e.stderr_output)

        try:
            run_client(['bkr', 'pool-add', '--pool', pool_name,
                        '--system', s1.fqdn],
                       config=create_client_config(
                           username=pool_owner.user_name,
                           password='******'))
            self.fail('Must fail')
        except ClientError as e:
            self.assertIn('You do not have permission to'
                          ' modify system %s' % s1.fqdn,
                          e.stderr_output)
コード例 #7
0
ファイル: test_add_user.py プロジェクト: ShaolongHu/beaker
    def test_add_invalid_details_existing_user(self):
        with session.begin():
            existing_name = data_setup.unique_name("user%s")
            existing_email = data_setup.unique_name("*****@*****.**")
            data_setup.create_user(user_name=existing_name, email_address=existing_email)

            existing_name2 = data_setup.unique_name("user%s")
            existing_email2 = data_setup.unique_name("*****@*****.**")
            data_setup.create_user(user_name=existing_name2, email_address=existing_email2)

        b = self.browser
        b.get(get_server_base() + "users")
        # Test with duplicate name
        b.find_element_by_name("user.text").send_keys(existing_name)
        b.find_element_by_xpath("//form[@id='Search']").submit()
        b.find_element_by_link_text(existing_name).click()
        b.find_element_by_name("user_name").clear()
        b.find_element_by_name("user_name").send_keys(existing_name2)
        b.find_element_by_xpath("//form[@id='User']").submit()
        self.assert_(
            b.find_element_by_xpath(
                "//form[@id='User'] \
            //input[@name='user_name']/following-sibling::span"
            ).text
            == "Login name is not unique"
        )
        # Reset back to current name
        b.find_element_by_name("user_name").clear()
        b.find_element_by_name("user_name").send_keys(existing_name)

        # Verify our exiting details submit ok
        b.find_element_by_name("email_address").clear()
        b.find_element_by_name("email_address").send_keys(existing_email)
        b.find_element_by_xpath("//form[@id='User']").submit()
        is_text_present(b, "%s saved" % existing_name)
コード例 #8
0
    def test_modify_attributes_policy(self):
        with session.begin():
            system1 = data_setup.create_system(shared=False)
            system2 = data_setup.create_system(shared=False)
            new_owner = data_setup.create_user()
            perm = SystemPermission.reserve
            user1 = data_setup.create_user()
            system1.custom_access_policy.add_rule(perm, user=user1)
            system2.custom_access_policy.add_rule(perm, user=user1)
            pool = data_setup.create_system_pool(systems=[system1, system2])
            user2 = data_setup.create_user()
            pool.access_policy.add_rule(perm, user=user2)

        run_client(['bkr', 'system-modify',
                    '--owner', new_owner.user_name,
                    '--condition', 'Manual',
                    '--pool-policy', pool.name,
                    system1.fqdn, system2.fqdn])
        with session.begin():
            session.expire_all()
            for s in [system1, system2]:
                self.assertEquals(s.owner.user_name, new_owner.user_name)
                self.assertEquals(s.status, SystemStatus.manual)
                self.assertFalse(s.active_access_policy.grants(user1, perm))
                self.assertTrue(s.active_access_policy.grants(user2, perm))
コード例 #9
0
ファイル: test_jobs.py プロジェクト: omps/beaker
    def test_invalid_submission_delegate(self):
        with session.begin():
            user = data_setup.create_user()
            invalid_delegate = data_setup.create_user(password='******')

        b = self.browser
        login(b, user=invalid_delegate.user_name, password='******')
        b.get(get_server_base() + 'jobs/new')
        xml_file = tempfile.NamedTemporaryFile()
        xml_file.write('''
            <job user="******">
                <whiteboard>job with submission delegate who is not allowed</whiteboard>
                <recipeSet>
                    <recipe>
                        <distroRequires>
                            <distro_name op="=" value="BlueShoeLinux5-5" />
                        </distroRequires>
                        <hostRequires>
                           <system>
                              <last_inventoried op="&gt;" value="2010-10-10"/>
                           </system>
                           <system_type value="Machine"/>
                        </hostRequires>
                        <task name="/distribution/install" role="STANDALONE"/>
                    </recipe>
                </recipeSet>
            </job>
            ''' % user.user_name)
        xml_file.flush()
        b.find_element_by_xpath("//input[@id='jobs_filexml']").send_keys(xml_file.name)
        b.find_element_by_xpath("//button[text()='Submit Data']").click()
        b.find_element_by_xpath("//button[text()='Queue']").click()
        flash_text = b.find_element_by_class_name('flash').text
        self.assertEquals('Failed to import job because of: %s is not a valid'
            ' submission delegate for %s' % (invalid_delegate.user_name, user.user_name), flash_text, flash_text)
コード例 #10
0
ファイル: test_add_user.py プロジェクト: ShaolongHu/beaker
 def test_filter_autocomplete_works(self):
     with session.begin():
         data_setup.create_user(user_name=u"barackobama")
     b = self.browser
     b.get(get_server_base() + "users")
     b.find_element_by_name("user.text").send_keys("bara")
     b.find_element_by_xpath('//span[@id="autoCompleteResultsSearch_user"]' '//td[string(.)="barackobama"]')
コード例 #11
0
    def test_inverted_group_modify_grant_owner(self):
        with session.begin():
            group = data_setup.create_group(owner=self.user,
                    membership_type=GroupMembershipType.inverted)
            user1 = data_setup.create_user()
            group.add_member(user1)
            user2 = data_setup.create_user()
            group.add_member(user2)
            # user3 is not associated but can also be set as the group owner.
            user3 = data_setup.create_user()

        out = run_client(['bkr', 'group-modify',
                          '--grant-owner', user1.user_name,
                          '--grant-owner', user2.user_name,
                          '--grant-owner', user3.user_name,
                          group.group_name],
                         config = self.client_config)

        with session.begin():
            session.expire_all()
            self.assertTrue(group.has_owner(user1))
            self.assertTrue(group.has_owner(user2))
            self.assertTrue(group.has_owner(user3))
            self.assertEquals(group.activity[-1].action, u'Added')
            self.assertEquals(group.activity[-1].field_name, u'Owner')
            self.assertEquals(group.activity[-1].new_value, user3.user_name)
            self.assertEquals(group.activity[-1].service, u'HTTP')
コード例 #12
0
ファイル: test_mail.py プロジェクト: beaker-project/beaker
    def test_actions(self):

        with session.begin():
            owner = data_setup.create_user()
            member = data_setup.create_user()
            group = data_setup.create_group(owner=owner)
            group.add_member(member)

        mail_capture_thread.start_capturing()
        bkr.server.mail.group_membership_notify(member, group, owner, 'Added')
        captured_mails = mail_capture_thread.stop_capturing()
        self.assertEqual(len(captured_mails), 1)

        with session.begin():
            group.remove_member(member)

        mail_capture_thread.start_capturing()
        bkr.server.mail.group_membership_notify(member, group, owner, 'Removed')
        captured_mails = mail_capture_thread.stop_capturing()
        self.assertEqual(len(captured_mails), 1)

        # invalid action
        try:
            bkr.server.mail.group_membership_notify(member, group, owner, 'Unchanged')
            self.fail('Must fail or die')
        except ValueError, e:
            self.assert_('Unknown action' in str(e))
コード例 #13
0
ファイル: test_nag_mail.py プロジェクト: ustbgaofan/beaker
    def setupClass(cls):
        cls.two_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=2)
        cls.three_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=3)

        cls.just_now = datetime.datetime.utcnow()

        cls.user_1 = data_setup.create_user()
        cls.user_2 = data_setup.create_user()
        def _create_system(user):
            return data_setup.create_system(owner=user, shared=True,
                                            status=SystemStatus.manual)
        cls.system_1 = _create_system(cls.user_1)
        cls.system_2 = _create_system(cls.user_1)
        cls.system_3 = _create_system(cls.user_2)

        cls.subject_header = '[Beaker Reminder]: System'

        #Shouldn't send
        #This tests that mail is not sent if user == owner
        cls.system_1.reserve_manually(service=u'testdata', user=cls.user_1)
        cls.system_1.reservations[-1].start_time = cls.two_days_ago

        #Shouldn't send
        #This tests that threshold value is honoured
        cls.system_2.reserve_manually(service=u'testdata', user=cls.user_2)
        cls.system_2.reservations[-1].start_time = cls.just_now

        #Should send
        #This tests that with owner != user and taken > threshold, should send nag
        cls.system_3.reserve_manually(service=u'testdata', user=cls.user_1)
        cls.system_3.reservations[-1].start_time = cls.three_days_ago
コード例 #14
0
ファイル: test_system_view.py プロジェクト: ustbgaofan/beaker
    def setUp(self):
        with session.begin():
            self.lab_controller = data_setup.create_labcontroller()
            self.system_owner = data_setup.create_user()
            self.unprivileged_user = data_setup.create_user(password=u'password')
            self.system = data_setup.create_system(lab_controller=self.lab_controller,
                    owner=self.system_owner, status=u'Automated', arch=u'i386')
            self.distro_tree = data_setup.create_distro_tree(
                    lab_controllers=[self.lab_controller])
            self.system.provisions[self.distro_tree.arch] = Provision(
                    arch=self.distro_tree.arch, ks_meta=u'some_ks_meta_var=1',
                    kernel_options=u'some_kernel_option=1',
                    kernel_options_post=u'some_kernel_option=2')
            self.system.provisions[self.distro_tree.arch]\
                .provision_families[self.distro_tree.distro.osversion.osmajor] = \
                    ProvisionFamily(osmajor=self.distro_tree.distro.osversion.osmajor,
                        ks_meta=u'some_ks_meta_var=2', kernel_options=u'some_kernel_option=3',
                        kernel_options_post=u'some_kernel_option=4')
            self.system.provisions[self.distro_tree.arch]\
                .provision_families[self.distro_tree.distro.osversion.osmajor]\
                .provision_family_updates[self.distro_tree.distro.osversion] = \
                    ProvisionFamilyUpdate(osversion=self.distro_tree.distro.osversion,
                        ks_meta=u'some_ks_meta_var=3', kernel_options=u'some_kernel_option=5',
                        kernel_options_post=u'some_kernel_option=6')

        self.browser = self.get_browser()
コード例 #15
0
ファイル: test_job_ack.py プロジェクト: sujithshankar/beaker
    def test_disable_legacy_perms(self):
        try:
            stop_process('gunicorn')
        except ValueError:
            # It seems gunicorn is not a running process
            raise SkipTest('Can only run this test against gunicorn')
        try:
            tmp_config = edit_file(CONFIG_FILE,
                'beaker.deprecated_job_group_permissions.on = True',
                'beaker.deprecated_job_group_permissions.on = False')
            start_process('gunicorn', env={'BEAKER_CONFIG_FILE': tmp_config.name})

            with session.begin():
                owner = data_setup.create_user()
                member = data_setup.create_user(password=u'group_member')
                group = data_setup.create_group()
                data_setup.add_user_to_group(owner, group)
                data_setup.add_user_to_group(member, group)
                job = data_setup.create_job(owner=owner, group=None)
                data_setup.mark_job_complete(job, result=TaskResult.fail)
            b = self.browser
            login(b, user=member.user_name, password='******')
            b.get(get_server_base() + 'jobs/%s' % job.id)
            self.check_cannot_review()
        finally:
            stop_process('gunicorn')
            start_process('gunicorn')
コード例 #16
0
ファイル: test_system_view.py プロジェクト: sibiaoluo/beaker
 def setUp(self):
     self.lab_controller = data_setup.create_labcontroller()
     self.system_owner = data_setup.create_user()
     self.unprivileged_user = data_setup.create_user(password=u"password")
     self.distro_tree = data_setup.create_distro_tree()
     self.system = data_setup.create_system(owner=self.system_owner, status=u"Automated", arch=u"i386")
     self.system.shared = True
     self.system.provisions[self.distro_tree.arch] = Provision(
         arch=self.distro_tree.arch,
         ks_meta=u"some_ks_meta_var=1",
         kernel_options=u"some_kernel_option=1",
         kernel_options_post=u"some_kernel_option=2",
     )
     self.system.provisions[self.distro_tree.arch].provision_families[
         self.distro_tree.distro.osversion.osmajor
     ] = ProvisionFamily(
         osmajor=self.distro_tree.distro.osversion.osmajor,
         ks_meta=u"some_ks_meta_var=2",
         kernel_options=u"some_kernel_option=3",
         kernel_options_post=u"some_kernel_option=4",
     )
     self.system.provisions[self.distro_tree.arch].provision_families[
         self.distro_tree.distro.osversion.osmajor
     ].provision_family_updates[self.distro_tree.distro.osversion] = ProvisionFamilyUpdate(
         osversion=self.distro_tree.distro.osversion,
         ks_meta=u"some_ks_meta_var=3",
         kernel_options=u"some_kernel_option=5",
         kernel_options_post=u"some_kernel_option=6",
     )
     self.system.lab_controller = self.lab_controller
     self.selenium = self.get_selenium()
     self.selenium.start()
コード例 #17
0
ファイル: test_jobs.py プロジェクト: omps/beaker
    def test_valid_submission_delegate(self):
        with session.begin():
            user = data_setup.create_user()
            submission_delegate = data_setup.create_user(password='******')
            user.submission_delegates[:] = [submission_delegate]

        b = self.browser
        login(b, user=submission_delegate.user_name, password='******')
        b.get(get_server_base() + 'jobs/new')
        xml_file = tempfile.NamedTemporaryFile()
        xml_file.write('''
            <job user="******">
                <whiteboard>job with submission delegate who is allowed</whiteboard>
                <recipeSet>
                    <recipe>
                        <distroRequires>
                            <distro_name op="=" value="BlueShoeLinux5-5" />
                        </distroRequires>
                        <hostRequires>
                           <system_type value="Machine"/>
                        </hostRequires>
                        <task name="/distribution/install" role="STANDALONE"/>
                    </recipe>
                </recipeSet>
            </job>
            ''' % user.user_name)
        xml_file.flush()
        b.find_element_by_xpath("//input[@id='jobs_filexml']").send_keys(xml_file.name)
        b.find_element_by_xpath("//button[text()='Submit Data']").click()
        b.find_element_by_xpath("//button[text()='Queue']").click()
        flash_text = b.find_element_by_class_name('flash').text
        self.assert_('Success!' in flash_text, flash_text)
        self.assertEqual(b.title, 'My Jobs')
コード例 #18
0
    def test_modify_active_access_policy(self):
        with session.begin():
            user1 = data_setup.create_user()
            perm = SystemPermission.reserve
            system1 = data_setup.create_system(shared=False)
            system2 = data_setup.create_system(shared=False)
            system1.custom_access_policy.add_rule(perm, user=user1)
            system2.custom_access_policy.add_rule(perm, user=user1)

            pool = data_setup.create_system_pool(systems=[system1, system2])
            user2 = data_setup.create_user()
            pool.access_policy.add_rule(perm, user=user2)

        # use pool policy
        run_client(['bkr', 'system-modify',
                    '--pool-policy', pool.name,
                    system1.fqdn, system2.fqdn])
        with session.begin():
            session.expire_all()
            for s in [system1, system2]:
                self.assertFalse(s.active_access_policy.grants(user1, perm))
                self.assertTrue(s.active_access_policy.grants(user2, perm))
                self.assertEquals(s.activity[-1].field_name, u'Active Access Policy')
                self.assertEquals(s.activity[-1].action, u'Changed')
                self.assertEquals(s.activity[-1].old_value, 'Custom Access Policy')
                self.assertEquals(s.activity[-1].new_value,'Pool policy: %s' % pool.name)

        # system not in a pool
        try:
            run_client(['bkr', 'system-modify',
                        '--pool-policy', data_setup.create_system_pool().name,
                        system1.fqdn])
        except ClientError as e:
            self.assertIn('To use a pool policy, the system must be in the pool first',
                          e.stderr_output)

        # Revert to custom policy
        run_client(['bkr', 'system-modify',
                    '--use-custom-policy',
                    system1.fqdn, system2.fqdn])

        with session.begin():
            session.expire_all()
            for s in [system1, system2]:
                self.assertTrue(s.active_access_policy.grants(user1, perm))
                self.assertFalse(s.active_access_policy.grants(user2, perm))

        # insufficient permission to change active policy
        with session.begin():
            user1 = data_setup.create_user(password='******')
        try:
            run_client(['bkr', 'system-modify',
                        '--use-custom-policy',
                        '--user', user1.user_name,
                        '--password', 'abc',
                        system1.fqdn])
            self.fail('Must raise')
        except ClientError as e:
            self.assertIn('Cannot edit system access policy',
                          e.stderr_output)
コード例 #19
0
ファイル: test_systems.py プロジェクト: ShaolongHu/beaker
    def test_set_active_policy_to_custom_policy(self):
        with session.begin():
            user1 = data_setup.create_user()
            user2 = data_setup.create_user()
            self.system.custom_access_policy.add_rule(
                permission=SystemPermission.edit_system, user=user1)
            pool = data_setup.create_system_pool()
            pool.access_policy.add_rule(
                permission=SystemPermission.edit_system, user=user2)
            self.system.active_access_policy = pool.access_policy

        self.assertFalse(self.system.active_access_policy.grants 
                        (user1, SystemPermission.edit_system))
        self.assertTrue(self.system.active_access_policy.grants
                         (user2, SystemPermission.edit_system))

        s = requests.Session()
        s.post(get_server_base() + 'login', data={'user_name': self.owner.user_name,
                'password': '******'}).raise_for_status()
        response = patch_json(get_server_base() +
                              'systems/%s/' % self.system.fqdn, session=s,
                              data={'active_access_policy': {'custom': True}},
                         )
        response.raise_for_status()
        with session.begin():
            session.expire_all()
            self.assertTrue(self.system.active_access_policy.grants \
                            (user1, SystemPermission.edit_system))
コード例 #20
0
    def test_job_priority_changes(self):
        user1 = data_setup.create_user()
        user2 = data_setup.create_user()
        job1 = data_setup.create_job(owner=user1)
        job2 = data_setup.create_job(owner=user1)
        job3 = data_setup.create_job(owner=user2)
        job4 = data_setup.create_job(owner=user2)

        for j in [job1, job2, job3]:
            for rs in j.recipesets:
                activity = RecipeSetActivity(j.owner,
                                             'TEST',
                                             'Changed',
                                             'Priority',
                                             rs.priority.value,
                                             TaskPriority.high)
                activity.created = datetime.datetime(year=2012,
                                                     month=10,
                                                     day=10)
                rs.activity.append(activity)
        session.flush()

        rows = self.execute_reporting_query('job-priority-changes-by-user')
        all_rows = rows.fetchall()
        user1_rows = [row for row in all_rows if row.user_name == user1.user_name]
        user2_rows = [row for row in all_rows if row.user_name == user2.user_name]

        self.assertTrue(user1_rows[0].number_of_jobs_changed, 2)
        self.assertTrue(user2_rows[0].number_of_jobs_changed, 1)
コード例 #21
0
    def setUp(self):
        self.selenium = self.get_selenium()
        self.password = '******'

        # create users
        self.user_1 = data_setup.create_user(password=self.password)
        self.user_2 = data_setup.create_user(password=self.password)
        self.user_3 = data_setup.create_user(password=self.password)

        # create admin users
        self.admin_1 = data_setup.create_user(password=self.password)
        self.admin_1.groups.append(Group.by_name(u'admin'))
        self.admin_2 = data_setup.create_user(password=self.password)
        self.admin_2.groups.append(Group.by_name(u'admin'))

        # create systems
        self.system_1 = data_setup.create_system(shared=True)
        self.system_2 = data_setup.create_system(shared=True)
        self.system_3 = data_setup.create_system(shared=False,
                                                 owner=self.user_3)

        # create group and add users/systems to it
        self.group_1 = data_setup.create_group()
        self.user_3.groups.append(self.group_1)
        self.admin_2.groups.append(self.group_1)
        self.system_2.groups.append(self.group_1)

        lc = data_setup.create_labcontroller()
        self.system_1.lab_controller = lc
        self.system_2.lab_controller = lc
        self.system_3.lab_controller = lc

        self.selenium.start()
コード例 #22
0
    def setUpClass(cls):
        cls.browser = cls.get_browser()
        login(cls.browser)
        cls.system_one_details = { 'fqdn' : u'a1',
                                    'type' : u'Machine',
                                    'arch' : u'i386',
                                    'status' : u'Automated',
                                    'owner' : data_setup.create_user(),}
        cls.system_one = data_setup.create_system(**cls.system_one_details)
        cls.system_one.loaned = data_setup.create_user()
        cls.system_one.numa = Numa(nodes=2)
        cls.system_one.key_values_string.append(Key_Value_String(
            Key.by_name(u'CPUMODEL'), 'foocodename'))
        cls.system_one.key_values_string.append(Key_Value_String(
            Key.by_name(u'HVM'), '1'))
        cls.system_one.cpu = Cpu(flags=['flag1', 'flag2'])

        cls.system_one.key_values_int.append(Key_Value_Int(
            Key.by_name(u'DISKSPACE'), '1024'))
        cls.system_one.key_values_int.append(Key_Value_Int(
            Key.by_name(u'MEMORY'), '4096'))

        cls.system_two_details = { 'fqdn' : u'a2',
                                    'type' : u'Prototype',
                                    'arch' : u'x86_64',
                                    'status' : u'Manual',
                                    'owner' : data_setup.create_user(),}
        cls.system_two = data_setup.create_system(**cls.system_two_details)
        cls.system_two.key_values_int.append(Key_Value_Int(
            Key.by_name(u'DISKSPACE'), '900'))
        cls.system_two.key_values_string.append(Key_Value_String(
            Key.by_name(u'HVM'), '1'))

        device_class = DeviceClass.lazy_create(device_class='class_type')
        device1 = Device.lazy_create(vendor_id = '0000',
                                      device_id = '0000',
                                      subsys_vendor_id = '2223',
                                      subsys_device_id = '2224',
                                      bus = '0000',
                                      driver = '0000',
                                      device_class_id = device_class.id,
                                      description = 'blah')
        cls.system_two.devices.append(device1)
        cls.system_three_details = { 'fqdn' : u'a3',
                                    'type' : u'Laptop',
                                    'arch' : u'ia64',
                                    'status' : u'Removed',
                                    'owner' : data_setup.create_user(),}
        cls.system_three = data_setup.create_system(**cls.system_three_details)
        cls.system_three.numa = Numa(nodes=1)
        device2 = Device.lazy_create(vendor_id = '0000',
                                      device_id = '0000',
                                      subsys_vendor_id = '1111',
                                      subsys_device_id = '1112',
                                      bus = '0000',
                                      driver = '0000',
                                      device_class_id = device_class.id,
                                      description = 'blah')
        cls.system_three.devices.append(device2)
コード例 #23
0
 def setUp(self):
     data_setup.create_product(product_name=u'the_product')
     data_setup.create_group(group_name=u'somegroup')
     self.user_foo = data_setup.create_user(password=u'foo')
     self.user_bar = data_setup.create_user(password=u'bar')
     self.bot = data_setup.create_user(password=u'bot')
     # Add bot as delegate submission of foo
     self.user_foo.add_submission_delegate(self.bot, service=u'testdata')
コード例 #24
0
    def setUp(self):
        self.user1 = data_setup.create_user(password=u'asdf')
        self.user2 = data_setup.create_user(password=u'qwerty')

        self.client_config1 = create_client_config(username=self.user1.user_name,
                password='******')
        self.client_config2 = create_client_config(username=self.user2.user_name,
                password='******')
コード例 #25
0
ファイル: test_system_pools.py プロジェクト: omps/beaker
 def setUp(self):
     with session.begin():
         self.owner = data_setup.create_user(password='******')
         self.system = data_setup.create_system(owner=self.owner, shared=False)
         self.pool = data_setup.create_system_pool(owning_user=self.owner)
         self.user = data_setup.create_user(password='******')
         self.group = data_setup.create_group()
         self.pool.systems[:] = [self.system]
コード例 #26
0
ファイル: test_group_edit.py プロジェクト: ShaolongHu/beaker
    def test_add_remove_owner_group(self):
        with session.begin():
            user = data_setup.create_user(password='******')
            group = data_setup.create_group(owner=user)
            user1 = data_setup.create_user(password='******')

        b = self.browser
        login(b, user=user.user_name, password='******')
        b.get(get_server_base() + 'groups/mine')

        # remove self (as only owner)
        b.find_element_by_link_text(group.group_name).click()
        b.find_element_by_xpath('//td[preceding-sibling::td/text()="%s"]' % user.user_name)\
                .find_element_by_link_text('Remove').click()

        flash_text = b.find_element_by_class_name('flash').text
        self.assert_("Cannot remove the only owner" in flash_text)

        # add a new user as owner
        b.find_element_by_xpath('//input[@id="GroupUser_user_text"]').send_keys(user1.user_name)
        b.find_element_by_id('GroupUser').submit()
        b.find_element_by_xpath('//td[text()="%s"]' % user1.user_name)
        b.find_element_by_xpath('//td[preceding-sibling::td/text()="%s"]' % user1.user_name)\
                .find_element_by_link_text('Add').click()
        b.find_element_by_xpath('//td[preceding-sibling::td/text()="%s"]' % user1.user_name)\
                .find_element_by_link_text('Remove')
        logout(b)

        # login as the new user and check for ownership
        login(b, user=user1.user_name, password='******')
        b.get(get_server_base() + 'groups/mine')
        b.find_element_by_link_text(group.group_name).click()
        b.find_element_by_xpath('//input')
        with session.begin():
            self.assertEquals(Activity.query.filter_by(service=u'WEBUI',
                                                       field_name=u'Owner', action=u'Added',
                                                       new_value=user1.user_name).count(), 1)
            group = Group.by_name(group.group_name)
            self.assert_(group.has_owner(user1))
            self.assertEquals(group.activity[-1].action, u'Added')
            self.assertEquals(group.activity[-1].field_name, u'Owner')
            self.assertEquals(group.activity[-1].new_value, user1.user_name)
            self.assertEquals(group.activity[-1].service, u'WEBUI')

        # remove self as owner
        b.find_element_by_xpath('//td[preceding-sibling::td/text()="%s"]' % user1.user_name)\
                .find_element_by_link_text('Remove').click()
        b.find_element_by_xpath('//title[text()="My Groups"]')

        with session.begin():
            self.assertEquals(Activity.query.filter_by(service=u'WEBUI',
                                                       field_name=u'Owner', action=u'Removed',
                                                       old_value=user1.user_name).count(), 1)
            session.refresh(group)
            self.assertEquals(group.activity[-1].action, u'Removed')
            self.assertEquals(group.activity[-1].field_name, u'Owner')
            self.assertEquals(group.activity[-1].old_value, user1.user_name)
            self.assertEquals(group.activity[-1].service, u'WEBUI')
コード例 #27
0
 def setUp(self):
     with session.begin():
         distro_tree = data_setup.create_distro_tree(distro_name=u'DansAwesomeLinux6.5')
         self.job = data_setup.create_completed_job(whiteboard=u"foo", distro_tree=distro_tree)
         self.user_foo = data_setup.create_user(password=u'foo')
         self.user_bar = data_setup.create_user(password=u'bar')
         self.bot = data_setup.create_user(password=u'bot')
         # Add bot as delegate submission of foo
         self.user_foo.add_submission_delegate(self.bot, service=u'testdata')
コード例 #28
0
ファイル: test_job_ack.py プロジェクト: sibiaoluo/beaker
 def setupClass(cls):
     cls.password = '******'
     with session.begin():
         cls.user_1 = data_setup.create_user(password=cls.password)
         cls.user_2 = data_setup.create_user(password=cls.password)
         cls.user_3 = data_setup.create_user(password=cls.password)
         cls.job = data_setup.create_completed_job(owner=cls.user_1)
         cls.group = data_setup.create_group()
     cls.browser = cls.get_browser()
コード例 #29
0
    def test_active_access_policy_selection(self):
        with session.begin():
            user = data_setup.create_user()
            owner = data_setup.create_user(password='******')
            system = data_setup.create_system(owner=owner)
            data_setup.create_system_pool(systems=[system])
            pool2 = data_setup.create_system_pool(systems=[system])
            pool2.access_policy.add_rule(user=user,
                                         permission=SystemPermission.edit_system)
        b = self.browser
        login(b, owner.user_name, password='******')
        b.get(get_server_base() + 'view/%s/' % system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        pane = b.find_element_by_id('access-policy')
        # Currently the system is using its custom access policy
        self.assertTrue(pane.find_element_by_xpath(
            '//label[contains(string(.), "Use custom access policy")]'
            '/input[@type="radio"]').is_selected())

        # change to pool policy
        pane.find_element_by_xpath(
                           '//label[contains(string(.), "Use policy from pool:")]'
                           '/input[@type="radio"]').click()
        Select(pane.find_element_by_name('pool_name')).select_by_visible_text(pool2.name)
        pane.find_element_by_xpath('.//button[text()="Save changes"]').click()
        # wait for the request to complete
        pane.find_element_by_xpath('.//span[@class="sync-status" and not(node())]')
        # check if the policy change has persisted
        b.get(get_server_base() + 'view/%s/' % system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        self.assertTrue(b.find_element_by_xpath(
                                        '//label[contains(string(.), "Use policy from pool:")]'
                                        '/input[@type="radio"]').is_selected())
        selected_options = Select(b.find_element_by_name('pool_name')).\
                           all_selected_options
        self.assertTrue(len(selected_options), 1)
        self.assertEquals(selected_options[0].text, pool2.name)
        self.assertFalse(b.find_element_by_xpath(
                                         '//label[contains(string(.), "Use custom access policy")]'
                                         '/input[@type="radio"]').is_selected())
        with session.begin():
            session.expire_all()
            self.assertTrue(system.active_access_policy.grants(user,
                                                   SystemPermission.edit_system))
        logout(b)
        # no change allowed when not logged in/no right privileges
        b.get(get_server_base() + 'view/%s/' % system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        self.assertFalse(b.find_element_by_xpath(
                                         '//label[contains(string(.), "Use policy from pool:")]'
                                         '/input[@type="radio"]').is_enabled())
        selected_options = Select(b.find_element_by_name('pool_name')). \
                           all_selected_options
        self.assertEquals(selected_options[0].text, pool2.name)
        self.assertFalse(b.find_element_by_xpath(
            '//label[contains(string(.), "Use custom access policy")]'
            '/input[@type="radio"]').is_enabled())
コード例 #30
0
    def test_grant_policy_pool(self):
        with session.begin():
            pool = data_setup.create_system_pool()
            user = data_setup.create_user()
            group = data_setup.create_group()
            group.add_member(user)
            user1 = data_setup.create_user()

        # group
        run_client(['bkr', 'policy-grant', '--pool', pool.name,
                    '--permission', 'edit_system', '--group', group.group_name])
        with session.begin():
            session.refresh(pool)
            self.assertTrue(pool.access_policy.grants(
                user, SystemPermission.edit_system))
        # non-existent group
        try:
            run_client(['bkr', 'policy-grant', '--pool', pool.name,
                        '--permission', 'edit_system', '--group', 'idontexist'])
            self.fail('Must fail or die')
        except ClientError as e:
            self.assertIn("Group 'idontexist' does not exist", e.stderr_output)

        # Everybody edit_system
        run_client(['bkr', 'policy-grant', '--pool', pool.name,
                '--permission', 'edit_system', '--everybody'])
        with session.begin():
            session.refresh(pool)
            self.assertTrue(pool.access_policy.grants(
                    user1, SystemPermission.edit_system))

        # test_multiple_permissions_and_targets
        with session.begin():
            user = data_setup.create_user()
            group = data_setup.create_group()
            user1 = data_setup.create_user()
            group.add_member(user1)
        run_client(['bkr', 'policy-grant', '--pool', pool.name,
                    '--permission=reserve', '--permission=view_power', \
                    '--user', user.user_name, '--group', group.group_name])
        with session.begin():
            session.refresh(pool)
            self.assertTrue(pool.access_policy.grants(
                    user, SystemPermission.view_power))
            self.assertTrue(pool.access_policy.grants(
                    user, SystemPermission.reserve))
            self.assertTrue(pool.access_policy.grants(
                user1, SystemPermission.view_power))
            self.assertTrue(pool.access_policy.grants(
                    user1, SystemPermission.reserve))
        # non-existent pool
        try:
            run_client(['bkr', 'policy-grant', '--pool', 'idontexist',
                        '--permission=reserve', '--permission=view_power', \
                        '--user', user.user_name, '--group', group.group_name])
        except ClientError as e:
            self.assertIn("System pool idontexist does not exist", e.stderr_output)
コード例 #31
0
 def test_cannot_provision_automated_system(self):
     with session.begin():
         system = data_setup.create_system(owner=User.by_user_name(
             data_setup.ADMIN_USER),
                                           status=u'Automated',
                                           shared=True)
         user = data_setup.create_user(password=u'password')
     self.server.auth.login_password(user.user_name, 'password')
     try:
         self.server.systems.provision(system.fqdn, 'distro')
     except xmlrpclib.Fault, e:
         self.assertIn('Reserve a system before provisioning',
                       e.faultString)
コード例 #32
0
ファイル: test_users.py プロジェクト: clrkwllms/beaker
 def test_cannot_create_keystone_trust_if_openstack_is_disabled(self):
     if config.get('openstack.identity_api_url'):
         raise SkipTest('OpenStack integration is enabled')
     with session.begin():
         user = data_setup.create_user()
     s = requests.Session()
     requests_login(s)
     response = put_json(get_server_base() +
                         'users/%s/keystone-trust' % user.user_name,
                         session=s,
                         data={'openstack_username': u'dummyuser'})
     self.assertEqual(response.status_code, 400)
     self.assertIn('OpenStack Integration is not enabled', response.text)
コード例 #33
0
 def test_clear_netboot(self):
     with session.begin():
         owner = data_setup.create_user(password=u'password')
         system = data_setup.create_system(owner=owner)
         data_setup.configure_system_power(system)
         system.lab_controller = self.lab_controller
         system.user = None
     self.server.auth.login_password(owner.user_name, 'password')
     self.server.systems.power('reboot', system.fqdn, True)
     with session.begin():
         self.assertEqual(system.command_queue[0].action, 'on')
         self.assertEqual(system.command_queue[1].action, 'off')
         self.assertEqual(system.command_queue[2].action, 'clear_netboot')
コード例 #34
0
 def test_record_retention_tag_change(self):
     with session.begin():
         job_owner = data_setup.create_user(password=u'owner')
         job = data_setup.create_job(owner=job_owner,
                                     retention_tag=u'scratch')
     login(self.browser, user=job_owner.user_name, password=u'owner')
     self.check_can_change_retention_tag(job, '60days')
     with session.begin():
         self.assertEquals(job.activity[0].service, u'WEBUI')
         self.assertEquals(job.activity[0].field_name, 'Retention Tag')
         self.assertEquals(job.activity[0].object_name(), 'Job: %s' % job.id)
         self.assertEquals(job.activity[0].old_value, u'scratch')
         self.assertEquals(job.activity[0].new_value, u'60days')
コード例 #35
0
ファイル: test_users.py プロジェクト: clrkwllms/beaker
 def test_reenable_user(self):
     with session.begin():
         user = data_setup.create_user()
         user.disabled = True
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
                           data={'disabled': False},
                           session=s)
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertFalse(user.disabled)
コード例 #36
0
    def test_subsequent_user_after_fail_not_added(self):
        with session.begin():
            user1 = data_setup.create_user()
            user2 = data_setup.create_user()
            self.group.add_member(user1)
            session.flush()
            self.assertIn(user1, self.group.users)
            self.assertNotIn(user2, self.group.users)

        try:
            out = run_client([
                'bkr', 'group-modify', '--add-member', user1.user_name,
                '--add-member', user2.user_name, self.group.group_name
            ],
                             config=self.client_config)
            self.fail('should raise')
        except ClientError, e:
            self.assert_(
                'User %s is already a member of group %s' %
                (user1.user_name, self.group.group_name) in e.stderr_output,
                e.stderr_output)
            self.assertNotIn(user2, self.group.users)
コード例 #37
0
ファイル: test_group_members.py プロジェクト: walbon/beaker
    def test_group_members(self):

        with session.begin():
            user2 = data_setup.create_user()
            group = data_setup.create_group(owner=user2)
            user1 = data_setup.create_user()
            group.add_member(user1)

        # list output
        out = run_client(
            ['bkr', 'group-members', '--format', 'list', group.group_name])

        self.assert_(
            '%s %s %s' % (user2.user_name, user2.email_address, 'Owner')
            in out.splitlines(), out.splitlines())
        self.assert_(
            '%s %s %s' % (user1.user_name, user1.email_address, 'Member')
            in out.splitlines(), out.splitlines())

        # json output
        out = run_client(['bkr', 'group-members', group.group_name])
        out = json.loads(out)
        self.assert_(
            dict(username=user2.user_name,
                 email=user2.email_address,
                 owner=True) in out, out)
        self.assert_(
            dict(username=user1.user_name,
                 email=user1.email_address,
                 owner=False) in out, out)

        # non-existent group
        try:
            non_existent_group = 'idontexist'
            run_client(['bkr', 'group-members', non_existent_group])
            self.fail('Must fail or die')
        except ClientError, e:
            self.assertIn('Group %s does not exist' % non_existent_group,
                          e.stderr_output)
コード例 #38
0
 def test_change_retention_tag_clearing_product(self):
     with session.begin():
         job_owner = data_setup.create_user(password=u'owner')
         job = data_setup.create_job(owner=job_owner,
                                     retention_tag=u'active',
                                     product=data_setup.create_product())
     login(self.browser, user=job_owner.user_name, password=u'owner')
     b = self.browser
     b.get(get_server_base() + 'jobs/%s' % job.id)
     Select(b.find_element_by_id('job_retentiontag'))\
         .select_by_visible_text('scratch')
     b.find_element_by_xpath('//button[text()="Clear product"]').click()
     b.find_element_by_xpath('//div[text()="Tag has been updated"]')
コード例 #39
0
 def test_non_shared_system(self):
     with session.begin():
         user = data_setup.create_user(password=u'testing')
         system = data_setup.create_system(status=SystemStatus.automated,
                                           lab_controller=self.lc,
                                           shared=False)
     b = self.browser
     login(b, user=user.user_name, password='******')
     self.check_system_is_not_available(system)
     # same thing, as admin
     logout(b)
     login(b)
     self.check_system_is_not_available(system)
コード例 #40
0
ファイル: test_job_submit.py プロジェクト: tcler/beaker
    def test_submit_job(self):
        with session.begin():
            user = data_setup.create_user(password=u'password')
            group = data_setup.create_group(group_name=u'somegroup')
            group.add_member(user)

        # Test submitting on behalf of user's group
        config = create_client_config(username=user.user_name,
                                       password=u'password')
        out = run_client(['bkr', 'job-submit',
                pkg_resources.resource_filename('bkr.inttest', 'complete-job.xml')],
                         config=config)
        self.assert_(out.startswith('Submitted:'), out)
コード例 #41
0
    def test_invalid_submission_delegate(self):
        with session.begin():
            user = data_setup.create_user()
            invalid_delegate = data_setup.create_user(password='******')

        b = self.browser
        login(b, user=invalid_delegate.user_name, password='******')
        b.get(get_server_base() + 'jobs/new')
        xml_file = tempfile.NamedTemporaryFile()
        xml_file.write('''
            <job user="******">
                <whiteboard>job with submission delegate who is not allowed</whiteboard>
                <recipeSet>
                    <recipe>
                        <distroRequires>
                            <distro_name op="=" value="BlueShoeLinux5-5" />
                        </distroRequires>
                        <hostRequires>
                           <system>
                              <last_inventoried op="&gt;" value="2010-10-10"/>
                           </system>
                           <system_type value="Machine"/>
                        </hostRequires>
                        <task name="/distribution/install" role="STANDALONE"/>
                    </recipe>
                </recipeSet>
            </job>
            ''' % user.user_name)
        xml_file.flush()
        b.find_element_by_xpath("//input[@id='jobs_filexml']").send_keys(
            xml_file.name)
        b.find_element_by_xpath("//button[text()='Submit Data']").click()
        b.find_element_by_xpath("//button[text()='Queue']").click()
        flash_text = b.find_element_by_class_name('flash').text
        self.assertEquals(
            'Failed to import job because of: %s is not a valid'
            ' submission delegate for %s' %
            (invalid_delegate.user_name, user.user_name), flash_text,
            flash_text)
コード例 #42
0
 def test_can_not_change_loan_when_system_has_loanee_and_not_admin(self):
     p_word = 'password'
     with session.begin():
         user = data_setup.create_user(password=p_word)
         self.system.user = user
         self.system.loaned = user
     b = self.browser
     login(b, user=user.user_name, password=p_word)
     self.go_to_loan_page()
     tab = b.find_element_by_id('loan')
     tab.find_element_by_xpath('.//button[text()="Return Loan"]')
     self.assertNotIn('Borrow', tab.text)
     self.assertNotIn('Lend', tab.text)
コード例 #43
0
    def setUp(self):
        with session.begin():
            self.user = data_setup.create_user(password=u'asdf')
            self.group = data_setup.create_group(owner=self.user)
            self.client_config = create_client_config(
                username=self.user.user_name, password=u'asdf')

            rand_user = data_setup.create_user(password=u'asdf')
            self.group.add_member(rand_user)
            self.rand_client_config = create_client_config(
                username=rand_user.user_name, password=u'asdf')

            admin = data_setup.create_admin(password=u'password')
            self.admin_client_config = create_client_config(
                username=admin.user_name, password=u'password')

            self.fake_ldap_group = data_setup.create_group(
                membership_type=GroupMembershipType.ldap)

        self.mail_capture = mail_capture.MailCaptureThread()
        self.mail_capture.start()
        self.addCleanup(self.mail_capture.stop)
コード例 #44
0
ファイル: test_mail.py プロジェクト: walbon/beaker
    def test_subject_format(self):
        mail_capture_thread.start_capturing()
        with session.begin():
            job_owner = data_setup.create_user()
            job = data_setup.create_job(owner=job_owner)
            session.flush()
            data_setup.mark_job_complete(job)

        captured_mails = mail_capture_thread.stop_capturing()
        self.assertEqual(len(captured_mails), 1)
        sender, rcpts, raw_msg = captured_mails[0]
        msg = email.message_from_string(raw_msg)
        self.assert_('[Beaker Job Completion] [Completed/Pass]' in msg['Subject'])
コード例 #45
0
    def test_add_rule_for_new_user(self):
        with session.begin():
            data_setup.create_user(user_name=u'marple')
        b = self.browser
        login(b, user=self.system_owner.user_name, password='******')
        b.get(get_server_base() + 'view/%s/' % self.system.fqdn)
        b.find_element_by_link_text('Access Policy').click()

        # grant edit_policy permission to marple user
        pane = b.find_element_by_id('access-policy')
        pane.find_element_by_xpath('.//input[@placeholder="Username"]')\
            .send_keys('marple\n')
        find_policy_checkbox(b, 'marple', 'Edit this policy').click()
        check_policy_row_is_dirty(b, 'marple')
        pane.find_element_by_xpath('.//button[text()="Save changes"]').click()
        pane.find_element_by_xpath('.//span[@class="sync-status" and not(node())]')
        check_policy_row_is_not_dirty(b, 'marple')

        # refresh to check it has been persisted
        b.get(get_server_base() + 'view/%s/' % self.system.fqdn)
        b.find_element_by_link_text('Access Policy').click()
        self.assertTrue(find_policy_checkbox(b, 'marple', 'Edit this policy').is_selected())
コード例 #46
0
 def test_manual_system_restricted_to_users_group(self):
     with session.begin():
         system = data_setup.create_system(status=SystemStatus.manual,
                                           shared=False,
                                           lab_controller=self.lc)
         user = data_setup.create_user(password=u'testing')
         group = data_setup.create_group()
         data_setup.add_user_to_group(user, group)
         system.custom_access_policy.add_rule(
             permission=SystemPermission.reserve, group=group)
     b = self.browser
     login(b, user=user.user_name, password='******')
     self.check_take(system)
コード例 #47
0
 def test_revoke_user(self):
     with session.begin():
         user = data_setup.create_user()
         self.system.custom_access_policy.add_rule(
                 permission=SystemPermission.edit_system, user=user)
         self.assertTrue(self.system.custom_access_policy.grants(
                 user, SystemPermission.edit_system))
     run_client(['bkr', 'policy-revoke', '--system', self.system.fqdn,
             '--permission', 'edit_system', '--user', user.user_name])
     with session.begin():
         session.expire_all()
         self.assertFalse(self.system.custom_access_policy.grants(
                 user, SystemPermission.edit_system))
コード例 #48
0
ファイル: test_users.py プロジェクト: walbon/beaker
 def test_renaming_user_to_existing_username(self):
     with session.begin():
         other_user = data_setup.create_user()
     b = self.browser
     login(b)
     b.get(get_server_base() + 'users/%s' % self.user.user_name)
     b.find_element_by_xpath('//h1//button[contains(text(), "Edit")]').click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_name('user_name').clear()
     modal.find_element_by_name('user_name').send_keys(other_user.user_name)
     modal.find_element_by_tag_name('form').submit()
     self.assertIn('User %s already exists' % other_user.user_name,
             modal.find_element_by_class_name('alert-error').text)
コード例 #49
0
ファイル: test_users.py プロジェクト: walbon/beaker
 def test_delete_ssh_public_key(self):
     with session.begin():
         user = data_setup.create_user()
         user.sshpubkeys.append(SSHPubKey(keytype=u'ssh-rsa',
                 pubkey=u'abc', ident=u'*****@*****.**'))
     s = requests.Session()
     requests_login(s)
     response = s.delete(get_server_base() + 'users/%s/ssh-public-keys/%s'
             % (user.user_name, user.sshpubkeys[0].id))
     self.assertEqual(response.status_code, 204)
     with session.begin():
         session.expire_all()
         self.assertEqual(len(user.sshpubkeys), 0)
コード例 #50
0
ファイル: test_users.py プロジェクト: walbon/beaker
 def test_rename_user(self):
     with session.begin():
         user = data_setup.create_user()
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
             session=s, data={'user_name': 'sgamgee'})
     response.raise_for_status()
     self.assertEqual(response.headers['Location'], get_server_base() + 'users/sgamgee')
     self.assertEqual(response.json()['user_name'], 'sgamgee')
     with session.begin():
         session.expire_all()
         self.assertEqual(user.user_name, u'sgamgee')
コード例 #51
0
 def test_report_problem_via_recipe(self):
     with session.begin():
         owner = data_setup.create_user()
         job = data_setup.create_completed_job(owner=owner)
     # Completing a job creates an email which we don't need
     self.mail_capture.captured_mails[:] = []
     b = self.browser
     b.get(get_server_base() + 'recipes/%s' % job.recipesets[0].recipes[0].id)
     b.find_element_by_link_text('Report Problem with System').click()
     b.find_element_by_id('problem_description').send_keys('I broke it')
     b.find_element_by_xpath('//input[@value=\'Report\']').click()
     b.find_element_by_xpath('//div/span[text()=\'Success\']')
     self.assertEqual(len(self.mail_capture.captured_mails), 1)
コード例 #52
0
ファイル: test_users.py プロジェクト: walbon/beaker
 def test_unremove_account(self):
     with session.begin():
         user = data_setup.create_user()
         user.removed = datetime.datetime.utcnow()
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
             data={'removed': None}, session=s)
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertIsNone(user.removed)
         self.assertFalse(user.disabled)
コード例 #53
0
ファイル: test_users.py プロジェクト: clrkwllms/beaker
 def test_update_email_address(self):
     with session.begin():
         user = data_setup.create_user(
             email_address=u'*****@*****.**')
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
                           data={'email_address': u'*****@*****.**'},
                           session=s)
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertEqual(user.email_address, u'*****@*****.**')
コード例 #54
0
ファイル: test_jobs.py プロジェクト: qhsong/beaker
 def setUp(self):
     session.begin()
     from bkr.server.jobs import Jobs
     self.controller = Jobs()
     self.user = data_setup.create_user(
         user_name=u'test-job-owner',
         email_address=u'*****@*****.**')
     group = data_setup.create_group(group_name='somegroup')
     group.add_member(self.user)
     testutil.set_identity_user(self.user)
     data_setup.create_distro_tree(distro_name=u'BlueShoeLinux5-5')
     data_setup.create_product(product_name=u'the_product')
     session.flush()
コード例 #55
0
ファイル: test_mail.py プロジェクト: qhsong/beaker
    def test_job_owner_is_notified(self):
        with session.begin():
            job_owner = data_setup.create_user()
            job = data_setup.create_job(owner=job_owner)
            session.flush()
            data_setup.mark_job_complete(job)

        self.assertEqual(len(self.mail_capture.captured_mails), 1)
        sender, rcpts, raw_msg = self.mail_capture.captured_mails[0]
        msg = email.message_from_string(raw_msg)
        self.assertEqual([job_owner.email_address], rcpts)
        self.assertEqual(job_owner.email_address, msg['To'])
        self.assert_('[Beaker Job Completion]' in msg['Subject'])
コード例 #56
0
ファイル: test_users.py プロジェクト: clrkwllms/beaker
 def test_set_password(self):
     with session.begin():
         user = data_setup.create_user()
         user.password = u'frodo'
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
                           data={'password': u'bilbo'},
                           session=s)
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertTrue(user.check_password(u'bilbo'))
コード例 #57
0
ファイル: test_users.py プロジェクト: clrkwllms/beaker
 def test_clear_root_password(self):
     with session.begin():
         user = data_setup.create_user()
         user.root_password = u'D6BeK7Cq9a4M'
     s = requests.Session()
     requests_login(s)
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
                           data={'root_password': u''},
                           session=s)
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertIsNone(user._root_password)
コード例 #58
0
ファイル: test_users.py プロジェクト: clrkwllms/beaker
 def test_set_use_old_job_page(self):
     with session.begin():
         user = data_setup.create_user(password=u'password')
         user.use_old_job_page = True
     s = requests.Session()
     requests_login(s, user=user.user_name, password='******')
     response = patch_json(get_server_base() + 'users/%s' % user.user_name,
                           data={'use_old_job_page': False},
                           session=s)
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertEqual(user.use_old_job_page, False)
コード例 #59
0
ファイル: test_job_cancel.py プロジェクト: ShaolongHu/beaker
 def test_cancel_group_job(self):
     b = self.browser
     with session.begin():
         group = data_setup.create_group()
         user = data_setup.create_user(password='******')
         user.groups.append(group)
         self.job.group = group
     login(b, user.user_name, 'password')
     b.get(get_server_base() + 'jobs/%s' % self.job.id)
     b.find_element_by_xpath('//div[contains(@class, "job-action-container")]//a[text()="Cancel"]').click()
     b.find_element_by_xpath("//input[@value='Yes']").click()
     self.assertTrue(is_text_present(b, "Successfully cancelled job %s"
         % self.job.id))
コード例 #60
0
 def test_unprivileged_user_cannot_delete_note(self):
     with session.begin():
         self.system.notes.append(Note(text=u'asdf', user=self.owner))
         session.flush()
         note_id = self.system.notes[0].id
         unprivileged = data_setup.create_user(password=u'password')
     s = requests.Session()
     requests_login(s, user=unprivileged.user_name, password=u'password')
     response = patch_json(get_server_base() + 'systems/%s/notes/%s' %
                           (self.system.fqdn, note_id),
                           session=s,
                           data={'deleted': 'now'})
     self.assertEquals(response.status_code, 403)