Esempio n. 1
0
    def test_get_or_create(self):
        r = Round.create(num=0)
        cs = ChallengeSet.create(name="foo")
        cbn1 = ChallengeBinaryNode.create(name="foo1", cs=cs, blob="aaa1")
        cbn2 = ChallengeBinaryNode.create(name="foo1", cs=cs, blob="aaa2")
        ids = IDSRule.create(cs=cs, rules="aaa", sha256="sum")

        cbl1, crtd1 = CSSubmissionCable.get_or_create(cs=cs,
                                                      ids=ids,
                                                      cbns=[cbn1],
                                                      round=r)
        assert_true(crtd1)

        cbl2, crtd2 = CSSubmissionCable.get_or_create(cs=cs,
                                                      ids=ids,
                                                      cbns=[cbn1],
                                                      round=r)
        assert_false(crtd2)
        assert_equals(cbl1.id, cbl2.id)

        cbl3, crtd3 = CSSubmissionCable.get_or_create(cs=cs,
                                                      ids=ids,
                                                      cbns=[cbn1, cbn2],
                                                      round=r)
        assert_true(crtd3)

        cbl4, crtd4 = CSSubmissionCable.get_or_create(cs=cs,
                                                      ids=ids,
                                                      cbns=[cbn1, cbn2],
                                                      round=r)
        assert_false(crtd4)
        assert_equals(cbl3.id, cbl4.id)
Esempio n. 2
0
def upload_cbns(args):
    cs = CS.select().where(CS.name == args.cs)

    patch_type, _ = PT.get_or_create(name="manual",
                                     functionality_risk=1.0,
                                     exploitability=0.0)

    cbns = []
    for patched_file in args.patched_files:
        with open(patched_file) as f:
            content = f.read()
        try:
            cbn = CBN.create(cs=cs,
                             blob=content,
                             name=patched_file,
                             patch_type=patch_type)
        except peewee.IntegrityError:
            print "CBN already exists. Fetching."
            cbn = CBN.select().where(CBN.name == args.patched_file,
                                     CBN.cs == cs, CBN.blob == content)
        cbns.append(cbn)

    if args.field:
        ids = IDSRule.get_or_create(cs=target_cs, rules='')
        CSSubmissionCable.get_or_create(cs=target_cs,
                                        cbns=cbns,
                                        ids=ids,
                                        round=Round.current_round())

    if args.eF is not None and args.eT is not None and args.eM is not None and cbn.patch_type is not None:
        perf_score = {
            'score': {
                'ref': {
                    'task_clock': 1.0,
                    'rss': 1.0,
                    'flt': 1.0,
                    'file_size': 1.0
                },
                'rep': {
                    'task_clock': args.eT,
                    'file_size': args.size_overhead,
                    'rss': args.eM,
                    'flt': args.eM,
                }
            }
        }
        PS.create(cs=cs,
                  perf_score=perf_score,
                  patch_type=cbn.patch_type,
                  has_failed_polls=args.eF != 0,
                  failed_polls=args.eF)
    if args.pT is not None and args.pM is not None and args.pS is not None:
        csf.poll_feedback = PF.create(cs=cs,
                                      round_id=Round.current_round().id,
                                      success=args.pS,
                                      time_overhead=args.pT,
                                      memory_overhead=args.pM,
                                      size_overhead=args.size_overhead)
        csf.save()
Esempio n. 3
0
def field_cbns(args):
    cs = CS.select().where(CS.name == args.cs)
    # i know i could use one query for this, but then we might get duplicate CBNs and more than we want
    cbns = [
        CBN.get(CBN.cs == cs, CBN.sha256 == sha) for sha in args.patched_shas
    ]
    ids, _ = IDSRule.get_or_create(cs=cs, rules='')
    CSSubmissionCable.get_or_create(cs=cs,
                                    cbns=cbns,
                                    ids=ids,
                                    round=Round.current_round())
    def test_unprocessed_submission_cables(self):
        r = Round.create(num=0)
        cs = ChallengeSet.create(name="foo")
        cbn = ChallengeBinaryNode.create(name="foo1", cs=cs, blob="aaa")
        ids = IDSRule.create(cs=cs, rules="aaa", blob="aaa")
        cable1 = CSSubmissionCable.create(cs=cs, ids=ids, cbns=[cbn], round=r)
        cable2 = CSSubmissionCable.create(cs=cs, ids=ids, cbns=[], round=r)

        assert_equals(len(cs.unprocessed_submission_cables()), 2)
        assert_equals(cable1, cs.unprocessed_submission_cables()[0])
        assert_equals(cable2, cs.unprocessed_submission_cables()[1])

        cable1.process()
        assert_equals(len(cs.unprocessed_submission_cables()), 1)
Esempio n. 5
0
    def rotator_submission(target_cs):
        global NEXT_PATCH_ORDER

        round_ = Round.current_round()

        if target_cs.name not in ORDERS or len(ORDERS[target_cs.name]) == 0:
            ORDERS[target_cs.name] = list(NEXT_PATCH_ORDER)
            #print target_cs.name, NEXT_PATCH_ORDER
            NEXT_PATCH_ORDER = NEXT_PATCH_ORDER[1:] + NEXT_PATCH_ORDER[:1]

        all_patches = target_cs.cbns_by_patch_type()
        for n in ORDERS[target_cs.name]:
            pt = PatchType.get(name=n)
            if pt not in all_patches:
                continue
            ORDERS[target_cs.name].remove(n)
            cbns = all_patches[pt]
            print "SUBMITTING", target_cs.name, cbns[0].name, cbns[
                0].patch_type.name
            c, _ = CSSubmissionCable.get_or_create(cs=target_cs,
                                                   cbns=cbns,
                                                   ids=cbns[0].ids_rule,
                                                   round=round_)
            print "...", c.id
            break
Esempio n. 6
0
 def process_patch_submission(target_cs):
     """
     Process a patch submission request for the provided ChallengeSet
     :param target_cs: ChallengeSet for which the request needs to be processed.
     """
     round_ = Round.current_round()
     cbns_to_submit = CBSubmitter.patch_decision_simple(target_cs, round_)
     if cbns_to_submit is not None:
         if cbns_to_submit[0].ids_rule is None:
             ids = IDSRule.create(cs=target_cs, rules='')
         else:
             ids = cbns_to_submit[0].ids_rule
         CSSubmissionCable.get_or_create(cs=target_cs,
                                         cbns=cbns_to_submit,
                                         ids=ids,
                                         round=round_)
     else:
         LOG.info("%s - leaving old CBNs in place for", target_cs.name)
Esempio n. 7
0
    def test_variable_submitter(self):
        t = Team.create(name=Team.OUR_NAME)
        r0 = Round.create(num=0)

        # set up several CSes
        cses = [CS.create(name='CS_%s' % i) for i in range(10)]

        # Set up the patches
        for cs in cses:
            for pt in PT.select():
                ids = IDSRule.create(cs=cs, rules="HAHAHA")
                cbn = CBN.create(cs=cs,
                                 name=cs.name + "_" + pt.name,
                                 blob="XXXX",
                                 patch_type=pt,
                                 ids_rule=ids)

        patch_names = scriba.submitters.cb.ORIG_PATCH_ORDER

        try:
            cur_cssc_id = CSSC.select().order_by(CSSC.id.desc()).get().id
        except CSSC.DoesNotExist:
            cur_cssc_id = 0

        # run the scheduler
        for _ in scriba.submitters.cb.ORIG_PATCH_ORDER:
            for c in cses:
                scriba.submitters.cb.CBSubmitter.rotator_submission(c)

        # make sure they got rotated correctly
        for n, cs in enumerate(cses):
            cables = list(
                CSSC.select().where((CSSC.cs == cs)
                                    & (CSSC.id > cur_cssc_id)).order_by(
                                        CSSC.id.asc()))
            assert len(cables) > 0
            assert all(c.cbns[0].patch_type.name == pn
                       for c, pn in zip(cables, (patch_names * 10)[n:]))