Exemplo n.º 1
0
    def test_log_entry_collection_handler_sensitive(self):
        account = RedHatAccount()
        account.username = "******"
        account.password = "******"
        account.license_type = "rhsm"
        self.db.add(account)
        self.db.commit()

        log_entries = [
            [
                time.strftime(settings.UI_LOG_DATE_FORMAT),
                'LEVEL111',
                'begin REDHATUSERNAME REDHATPASSWORD end',
            ],
        ]
        response_log_entries = [
            [
                time.strftime(settings.UI_LOG_DATE_FORMAT),
                'LEVEL111',
                'begin username password end',
            ],
        ]
        self._create_logfile_for_node(settings.LOGS[0], log_entries)
        resp = self.app.get(reverse('LogEntryCollectionHandler'),
                            params={'source': settings.LOGS[0]['id']},
                            headers=self.default_headers)
        self.assertEquals(200, resp.status)
        response = json.loads(resp.body)
        response['entries'].reverse()
        self.assertEquals(response['entries'], response_log_entries)
Exemplo n.º 2
0
    def test_log_entry_collection_handler_sensitive(self):
        account = RedHatAccount()
        account.username = "******"
        account.password = "******"
        account.license_type = "rhsm"
        self.db.add(account)
        self.db.commit()

        log_entries = [
            [
                time.strftime(settings.UI_LOG_DATE_FORMAT),
                'LEVEL111',
                'begin REDHATUSERNAME REDHATPASSWORD end',
            ],
        ]
        response_log_entries = [
            [
                time.strftime(settings.UI_LOG_DATE_FORMAT),
                'LEVEL111',
                'begin username password end',
            ],
        ]
        self._create_logfile_for_node(settings.LOGS[0], log_entries)
        resp = self.app.get(
            reverse('LogEntryCollectionHandler'),
            params={'source': settings.LOGS[0]['id']},
            headers=self.default_headers
        )
        self.assertEquals(200, resp.status)
        response = json.loads(resp.body)
        response['entries'].reverse()
        self.assertEquals(response['entries'], response_log_entries)
Exemplo n.º 3
0
    def test_log_package_handler_sensitive_gz(self):
        account = RedHatAccount()
        account.username = "******"
        account.password = "******"
        account.license_type = "rhsm"
        self.db.add(account)
        self.db.commit()

        f = tempfile.NamedTemporaryFile(mode='r+b', suffix='.gz')
        fgz = gzip.GzipFile(mode='w+b', fileobj=f)
        fgz.write('begin\nREDHATUSERNAME\nREDHATPASSWORD\nend')
        fgz.flush()
        fgz.close()

        settings.LOGS_TO_PACK_FOR_SUPPORT = {'test.gz': f.name}
        resp = self.app.get(reverse('LogPackageHandler'))
        self.assertEquals(200, resp.status)
        tf = tarfile.open(fileobj=StringIO(resp.body), mode='r:gz')

        m = tf.extractfile('test.gz')
        mgz = gzip.GzipFile(mode='r+b', fileobj=m)
        self.assertEquals(mgz.read(), 'begin\nusername\npassword\nend')
        mgz.close()

        f.close()
        m.close()
Exemplo n.º 4
0
    def test_log_package_handler_sensitive_gz(self):
        account = RedHatAccount()
        account.username = "******"
        account.password = "******"
        account.license_type = "rhsm"
        self.db.add(account)
        self.db.commit()

        f = tempfile.NamedTemporaryFile(mode='r+b', suffix='.gz')
        fgz = gzip.GzipFile(mode='w+b', fileobj=f)
        fgz.write('begin\nREDHATUSERNAME\nREDHATPASSWORD\nend')
        fgz.flush()
        fgz.close()

        settings.LOGS_TO_PACK_FOR_SUPPORT = {'test.gz': f.name}
        resp = self.app.get(reverse('LogPackageHandler'))
        self.assertEquals(200, resp.status)
        tf = tarfile.open(fileobj=StringIO(resp.body), mode='r:gz')

        m = tf.extractfile('test.gz')
        mgz = gzip.GzipFile(mode='r+b', fileobj=m)
        self.assertEquals(mgz.read(), 'begin\nusername\npassword\nend')
        mgz.close()

        f.close()
        m.close()
Exemplo n.º 5
0
    def POST(self):
        """:returns: JSONized RedHatAccount object.
        :http: * 200 (OK)
               * 400 (invalid account data specified)
               * 404 (account not found in db)
        """
        data = self.checked_data()

        license_type = data.get("license_type")
        if license_type == 'rhsm':
            data["satellite"] = ""
            data["activation_key"] = ""

        release_id = data.pop('release_id')
        release_db = db().query(Release).get(release_id)
        if not release_db:
            raise web.notfound(
                "No release with ID={0} found".format(release_id))
        account = db().query(RedHatAccount).first()
        if account:
            db().query(RedHatAccount).update(data)
        else:
            account = RedHatAccount(**data)
            db().add(account)
        db().commit()
        return self.render(account)
Exemplo n.º 6
0
    def test_log_package_handler_sensitive(self):
        account = RedHatAccount()
        account.username = "******"
        account.password = "******"
        account.license_type = "rhsm"
        self.db.add(account)
        self.db.commit()

        f = tempfile.NamedTemporaryFile(mode="r+b")
        f.write("begin\nREDHATUSERNAME\nREDHATPASSWORD\nend")
        f.flush()
        settings.LOGS_TO_PACK_FOR_SUPPORT = {"test": f.name}
        resp = self.app.get(reverse("LogPackageHandler"))
        self.assertEquals(200, resp.status)
        tf = tarfile.open(fileobj=StringIO(resp.body), mode="r:gz")
        m = tf.extractfile("test")
        self.assertEquals(m.read(), "begin\nusername\npassword\nend")
        f.close()
        m.close()
Exemplo n.º 7
0
 def create_rh_account(self, **kwargs):
     username = kwargs.pop("username", "rh_username")
     password = kwargs.pop("password", "rh_password")
     license_type = kwargs.pop("license_type", "rhsm")
     rh_account = RedHatAccount(username=username,
                                password=password,
                                license_type=license_type,
                                **kwargs)
     self.db.add(rh_account)
     self.db.commit()
     return rh_account
Exemplo n.º 8
0
    def POST(self):
        """Starts Red Hat setup and download process

        :returns: JSONized Task object.
        :http: * 202 (setup task created and started)
               * 400 (invalid account data specified)
               * 404 (release not found in db)
        """
        data = self.checked_data()

        license_type = data.get("license_type")
        if license_type == 'rhsm':
            data["satellite"] = ""
            data["activation_key"] = ""

        release_data = {'release_id': data['release_id']}
        release_id = data.pop('release_id')
        release_db = db().query(Release).get(release_id)
        if not release_db:
            raise web.notfound(
                "No release with ID={0} found".format(release_id))
        release_data['redhat'] = data
        release_data['release_name'] = release_db.name

        account = db().query(RedHatAccount).first()
        if account:
            db().query(RedHatAccount).update(data)
        else:
            account = RedHatAccount(**data)
            db().add(account)
        db().commit()

        task_manager = RedHatSetupTaskManager(release_data)
        try:
            task = task_manager.execute()
        except Exception as exc:
            logger.error(u'RedHatAccountHandler: error while execution'
                         ' Red Hat validation task: {0}'.format(str(exc)))
            logger.error(traceback.format_exc())
            raise web.badrequest(str(exc))

        data = build_json_response(TaskHandler.render(task))
        raise web.accepted(data=data)
Exemplo n.º 9
0
    def POST(self):
        data = self.checked_data()

        license_type = data.get("license_type")
        if license_type == 'rhsm':
            data["satellite"] = ""
            data["activation_key"] = ""

        release_id = data.pop('release_id')
        release_db = db().query(Release).get(release_id)
        if not release_db:
            raise web.notfound(
                "No release with ID={0} found".format(release_id))
        account = db().query(RedHatAccount).first()
        if account:
            db().query(RedHatAccount).update(data)
        else:
            account = RedHatAccount(**data)
            db().add(account)
        db().commit()
        return self.render(account)