public static function openProblemInContest($contestData, $problemData, $user)
 {
     // Prepare our request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['problem_alias'] = $problemData['request']['alias'];
     // Log in the user
     $r['auth_token'] = OmegaupTestCase::login($user);
     // Call api
     ProblemController::apiDetails($r);
     unset($_REQUEST);
 }
示例#2
0
<?php

require_once '../../server/bootstrap.php';
$r = new Request($_REQUEST);
$session = SessionController::apiCurrentSession($r);
$r['statement_type'] = 'html';
$r['show_solvers'] = true;
try {
    $result = ProblemController::apiDetails($r);
    $problem = ProblemsDAO::GetByAlias($result['alias']);
} catch (ApiException $e) {
    header('HTTP/1.1 404 Not Found');
    die(file_get_contents('../404.html'));
}
$smarty->assign('problem_statement', $result['problem_statement']);
$smarty->assign('problem_statement_language', $result['problem_statement_language']);
$smarty->assign('problem_alias', $result['alias']);
$smarty->assign('public', $result['public']);
$smarty->assign('source', $result['source']);
$smarty->assign('title', $result['title']);
$smarty->assign('points', $result['points']);
$smarty->assign('validator', $result['validator']);
$smarty->assign('time_limit', $result['time_limit'] / 1000 . 's');
$smarty->assign('validator_time_limit', $result['validator_time_limit'] / 1000 . 's');
$smarty->assign('overall_wall_time_limit', $result['overall_wall_time_limit'] / 1000 . 's');
$smarty->assign('memory_limit', $result['memory_limit'] / 1024 . 'MB');
$smarty->assign('solvers', $result['solvers']);
$smarty->assign('karel_problem', count(array_intersect(explode(',', $result['languages']), array('kp', 'kj'))) == 2);
if (isset($result['sample_input'])) {
    $smarty->assign('sample_input', $result['sample_input']);
}
示例#3
0
 /**
  * Best score is returned, problem inside a contest
  */
 public function testScoreInDetailsInsideContest()
 {
     // Create problem and contest
     $problemData = ProblemsFactory::createProblem();
     $contestData = ContestsFactory::createContest();
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Create contestant
     $contestant = UserFactory::createUser();
     // Create 2 runs, 100 and 50.
     $runDataOutsideContest = RunsFactory::createRunToProblem($problemData, $contestant);
     $runDataInsideContest = RunsFactory::createRun($problemData, $contestData, $contestant);
     RunsFactory::gradeRun($runDataOutsideContest);
     RunsFactory::gradeRun($runDataInsideContest, 0.5, "PA");
     // Call API
     $response = ProblemController::apiDetails(new Request(array("auth_token" => $this->login($contestant), "problem_alias" => $problemData["request"]["alias"], "contest_alias" => $contestData["request"]["alias"])));
     $this->assertEquals(50.0, $response["score"]);
 }
 /**
  * Check that user in private list can view private contest
  */
 public function testNoPrivilegeEscalationOccurs()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest(null, 0);
     // Get some problems into the contest
     $numOfProblems = 3;
     $problems = $this->insertProblemsInContest($contestData, $numOfProblems);
     // Get a user for our scenario
     $contestant = UserFactory::createUser();
     // Prepare our request
     $r = new Request(array('auth_token' => $this->login($contestant), 'contest_alias' => $contestData['request']['alias']));
     // Call api. This should fail.
     try {
         ContestController::apiDetails($r);
         $this->assertTrue(false, 'User with no access could see the contest');
     } catch (ForbiddenAccessException $e) {
         // Pass
     }
     // Get details from a problem in that contest. This should also fail.
     try {
         $problem_request = new Request(array('auth_token' => $this->login($contestant), 'contest_alias' => $contestData['request']['alias'], 'problem_alias' => $problems[0]['request']['alias']));
         ProblemController::apiDetails($problem_request);
         $this->assertTrue(false, 'User with no access could see the problem');
     } catch (ForbiddenAccessException $e) {
         // Pass
     }
     // Call api again. This should (still) fail.
     try {
         $response = ContestController::apiDetails($r);
         $this->assertTrue(false, 'User with no access could see the contest');
     } catch (ForbiddenAccessException $e) {
         // Pass
     }
 }