Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 44... Línea 44...
44
    }
44
    }
Línea 45... Línea 45...
45
 
45
 
46
    /**
46
    /**
47
     * Test access_manager private property quizsettings is null.
47
     * Test access_manager private property quizsettings is null.
48
     */
48
     */
49
    public function test_access_manager_quizsettings_null() {
49
    public function test_access_manager_quizsettings_null(): void {
Línea 50... Línea 50...
50
        $this->quiz = $this->create_test_quiz($this->course);
50
        $this->quiz = $this->create_test_quiz($this->course);
Línea 51... Línea 51...
51
 
51
 
Línea 60... Línea 60...
60
    }
60
    }
Línea 61... Línea 61...
61
 
61
 
62
    /**
62
    /**
63
     * Test that SEB is not required.
63
     * Test that SEB is not required.
64
     */
64
     */
65
    public function test_seb_required_false() {
65
    public function test_seb_required_false(): void {
Línea 66... Línea 66...
66
        $this->quiz = $this->create_test_quiz($this->course);
66
        $this->quiz = $this->create_test_quiz($this->course);
67
 
67
 
68
        $accessmanager = $this->get_access_manager();
68
        $accessmanager = $this->get_access_manager();
Línea 69... Línea 69...
69
        $this->assertFalse($accessmanager->seb_required());
69
        $this->assertFalse($accessmanager->seb_required());
70
    }
70
    }
71
 
71
 
72
    /**
72
    /**
73
     * Test that SEB is required.
73
     * Test that SEB is required.
Línea 74... Línea 74...
74
     */
74
     */
75
    public function test_seb_required_true() {
75
    public function test_seb_required_true(): void {
76
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
76
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 77... Línea 77...
77
 
77
 
78
        $accessmanager = $this->get_access_manager();
78
        $accessmanager = $this->get_access_manager();
79
        $this->assertTrue($accessmanager->seb_required());
79
        $this->assertTrue($accessmanager->seb_required());
80
    }
80
    }
81
 
81
 
Línea 82... Línea 82...
82
    /**
82
    /**
83
     * Test that user has capability to bypass SEB check.
83
     * Test that user has capability to bypass SEB check.
Línea 96... Línea 96...
96
    }
96
    }
Línea 97... Línea 97...
97
 
97
 
98
    /**
98
    /**
99
     * Test that user has capability to bypass SEB check.
99
     * Test that user has capability to bypass SEB check.
100
     */
100
     */
101
    public function test_admin_user_can_bypass_seb_check() {
101
    public function test_admin_user_can_bypass_seb_check(): void {
Línea 102... Línea 102...
102
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
102
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
103
 
103
 
104
        // Test normal user cannot bypass check.
104
        // Test normal user cannot bypass check.
Línea 114... Línea 114...
114
    }
114
    }
Línea 115... Línea 115...
115
 
115
 
116
    /**
116
    /**
117
     * Test user does not have capability to bypass SEB check.
117
     * Test user does not have capability to bypass SEB check.
118
     */
118
     */
119
    public function test_user_cannot_bypass_seb_check() {
119
    public function test_user_cannot_bypass_seb_check(): void {
Línea 120... Línea 120...
120
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
120
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
121
 
121
 
Línea 127... Línea 127...
127
    }
127
    }
Línea 128... Línea 128...
128
 
128
 
129
    /**
129
    /**
130
     * Test we can detect SEB usage.
130
     * Test we can detect SEB usage.
131
     */
131
     */
132
    public function test_is_using_seb() {
132
    public function test_is_using_seb(): void {
Línea 133... Línea 133...
133
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
133
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 134... Línea 134...
134
 
134
 
Línea 144... Línea 144...
144
    }
144
    }
Línea 145... Línea 145...
145
 
145
 
146
    /**
146
    /**
147
     * Test that the quiz Config Key matches the incoming request header.
147
     * Test that the quiz Config Key matches the incoming request header.
148
     */
148
     */
149
    public function test_access_keys_validate_with_config_key() {
149
    public function test_access_keys_validate_with_config_key(): void {
150
        global $FULLME;
150
        global $FULLME;
Línea 151... Línea 151...
151
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
151
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 163... Línea 163...
163
    }
163
    }
Línea 164... Línea 164...
164
 
164
 
165
    /**
165
    /**
166
     * Test that the quiz Config Key matches a provided config key with no incoming request header.
166
     * Test that the quiz Config Key matches a provided config key with no incoming request header.
167
     */
167
     */
168
    public function test_access_keys_validate_with_provided_config_key() {
168
    public function test_access_keys_validate_with_provided_config_key(): void {
169
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
169
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
170
        $url = 'https://www.example.com/moodle';
170
        $url = 'https://www.example.com/moodle';
Línea 171... Línea 171...
171
        $accessmanager = $this->get_access_manager();
171
        $accessmanager = $this->get_access_manager();
Línea 177... Línea 177...
177
    }
177
    }
Línea 178... Línea 178...
178
 
178
 
179
    /**
179
    /**
180
     * Test that the quiz Config Key does not match the incoming request header.
180
     * Test that the quiz Config Key does not match the incoming request header.
181
     */
181
     */
182
    public function test_access_keys_fail_to_validate_with_config_key() {
182
    public function test_access_keys_fail_to_validate_with_config_key(): void {
183
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
183
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 184... Línea 184...
184
        $accessmanager = $this->get_access_manager();
184
        $accessmanager = $this->get_access_manager();
185
 
185
 
Línea 186... Línea 186...
186
        $this->assertFalse($accessmanager->validate_config_key());
186
        $this->assertFalse($accessmanager->validate_config_key());
187
    }
187
    }
188
 
188
 
189
    /**
189
    /**
190
     * Test that config key is not checked when using client configuration with SEB.
190
     * Test that config key is not checked when using client configuration with SEB.
191
     */
191
     */
192
    public function test_config_key_not_checked_if_client_requirement_is_selected() {
192
    public function test_config_key_not_checked_if_client_requirement_is_selected(): void {
193
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
193
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
Línea 194... Línea 194...
194
        $accessmanager = $this->get_access_manager();
194
        $accessmanager = $this->get_access_manager();
195
        $this->assertFalse($accessmanager->should_validate_config_key());
195
        $this->assertFalse($accessmanager->should_validate_config_key());
196
    }
196
    }
197
 
197
 
198
    /**
198
    /**
Línea 199... Línea 199...
199
     * Test that if there are no browser exam keys for quiz, check is skipped.
199
     * Test that if there are no browser exam keys for quiz, check is skipped.
200
     */
200
     */
201
    public function test_no_browser_exam_keys_cause_check_to_be_successful() {
201
    public function test_no_browser_exam_keys_cause_check_to_be_successful(): void {
Línea 210... Línea 210...
210
    }
210
    }
Línea 211... Línea 211...
211
 
211
 
212
    /**
212
    /**
213
     * Test that access fails if there is no hash in header.
213
     * Test that access fails if there is no hash in header.
214
     */
214
     */
215
    public function test_access_keys_fail_if_browser_exam_key_header_does_not_exist() {
215
    public function test_access_keys_fail_if_browser_exam_key_header_does_not_exist(): void {
Línea 216... Línea 216...
216
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
216
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
217
 
217
 
218
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
218
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
Línea 223... Línea 223...
223
    }
223
    }
Línea 224... Línea 224...
224
 
224
 
225
    /**
225
    /**
226
     * Test that access fails if browser exam key doesn't match hash in header.
226
     * Test that access fails if browser exam key doesn't match hash in header.
227
     */
227
     */
228
    public function test_access_keys_fail_if_browser_exam_key_header_does_not_match_provided_hash() {
228
    public function test_access_keys_fail_if_browser_exam_key_header_does_not_match_provided_hash(): void {
Línea 229... Línea 229...
229
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
229
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
230
 
230
 
231
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
231
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
Línea 237... Línea 237...
237
    }
237
    }
Línea 238... Línea 238...
238
 
238
 
239
    /**
239
    /**
240
     * Test that browser exam key matches hash in header.
240
     * Test that browser exam key matches hash in header.
241
     */
241
     */
242
    public function test_browser_exam_keys_match_header_hash() {
242
    public function test_browser_exam_keys_match_header_hash(): void {
Línea 243... Línea 243...
243
        global $FULLME;
243
        global $FULLME;
244
 
244
 
245
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
245
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
Línea 257... Línea 257...
257
    }
257
    }
Línea 258... Línea 258...
258
 
258
 
259
    /**
259
    /**
260
     * Test that browser exam key matches a provided browser exam key.
260
     * Test that browser exam key matches a provided browser exam key.
261
     */
261
     */
262
    public function test_browser_exam_keys_match_provided_browser_exam_key() {
262
    public function test_browser_exam_keys_match_provided_browser_exam_key(): void {
263
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
263
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
264
        $url = 'https://www.example.com/moodle';
264
        $url = 'https://www.example.com/moodle';
265
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
265
        $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]);
266
        $browserexamkey = hash('sha256', 'browserexamkey');
266
        $browserexamkey = hash('sha256', 'browserexamkey');
Línea 273... Línea 273...
273
    }
273
    }
Línea 274... Línea 274...
274
 
274
 
275
    /**
275
    /**
276
     * Test can get received config key.
276
     * Test can get received config key.
277
     */
277
     */
278
    public function test_get_received_config_key() {
278
    public function test_get_received_config_key(): void {
279
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
279
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
Línea 280... Línea 280...
280
        $accessmanager = $this->get_access_manager();
280
        $accessmanager = $this->get_access_manager();
Línea 299... Línea 299...
299
    }
299
    }
Línea 300... Línea 300...
300
 
300
 
301
    /**
301
    /**
302
     * Test can correctly get type of SEB usage for the quiz.
302
     * Test can correctly get type of SEB usage for the quiz.
303
     */
303
     */
304
    public function test_get_seb_use_type() {
304
    public function test_get_seb_use_type(): void {
305
        // No SEB.
305
        // No SEB.
306
        $this->quiz = $this->create_test_quiz($this->course);
306
        $this->quiz = $this->create_test_quiz($this->course);
307
        $accessmanager = $this->get_access_manager();
307
        $accessmanager = $this->get_access_manager();
Línea 358... Línea 358...
358
     * @param int $type Type of SEB usage.
358
     * @param int $type Type of SEB usage.
359
     * @param bool $expected Expected result.
359
     * @param bool $expected Expected result.
360
     *
360
     *
361
     * @dataProvider should_validate_basic_header_data_provider
361
     * @dataProvider should_validate_basic_header_data_provider
362
     */
362
     */
363
    public function test_should_validate_basic_header($type, $expected) {
363
    public function test_should_validate_basic_header($type, $expected): void {
364
        $accessmanager = $this->getMockBuilder(seb_access_manager::class)
364
        $accessmanager = $this->getMockBuilder(seb_access_manager::class)
365
            ->disableOriginalConstructor()
365
            ->disableOriginalConstructor()
366
            ->onlyMethods(['get_seb_use_type'])
366
            ->onlyMethods(['get_seb_use_type'])
367
            ->getMock();
367
            ->getMock();
368
        $accessmanager->method('get_seb_use_type')->willReturn($type);
368
        $accessmanager->method('get_seb_use_type')->willReturn($type);
Línea 392... Línea 392...
392
     * @param int $type Type of SEB usage.
392
     * @param int $type Type of SEB usage.
393
     * @param bool $expected Expected result.
393
     * @param bool $expected Expected result.
394
     *
394
     *
395
     * @dataProvider should_validate_config_key_data_provider
395
     * @dataProvider should_validate_config_key_data_provider
396
     */
396
     */
397
    public function test_should_validate_config_key($type, $expected) {
397
    public function test_should_validate_config_key($type, $expected): void {
398
        $accessmanager = $this->getMockBuilder(seb_access_manager::class)
398
        $accessmanager = $this->getMockBuilder(seb_access_manager::class)
399
            ->disableOriginalConstructor()
399
            ->disableOriginalConstructor()
400
            ->onlyMethods(['get_seb_use_type'])
400
            ->onlyMethods(['get_seb_use_type'])
401
            ->getMock();
401
            ->getMock();
402
        $accessmanager->method('get_seb_use_type')->willReturn($type);
402
        $accessmanager->method('get_seb_use_type')->willReturn($type);
Línea 425... Línea 425...
425
     * @param int $type Type of SEB usage.
425
     * @param int $type Type of SEB usage.
426
     * @param bool $expected Expected result.
426
     * @param bool $expected Expected result.
427
     *
427
     *
428
     * @dataProvider should_validate_browser_exam_key_data_provider
428
     * @dataProvider should_validate_browser_exam_key_data_provider
429
     */
429
     */
430
    public function test_should_validate_browser_exam_key($type, $expected) {
430
    public function test_should_validate_browser_exam_key($type, $expected): void {
431
        $accessmanager = $this->getMockBuilder(seb_access_manager::class)
431
        $accessmanager = $this->getMockBuilder(seb_access_manager::class)
432
            ->disableOriginalConstructor()
432
            ->disableOriginalConstructor()
433
            ->onlyMethods(['get_seb_use_type'])
433
            ->onlyMethods(['get_seb_use_type'])
434
            ->getMock();
434
            ->getMock();
435
        $accessmanager->method('get_seb_use_type')->willReturn($type);
435
        $accessmanager->method('get_seb_use_type')->willReturn($type);
Línea 438... Línea 438...
438
    }
438
    }
Línea 439... Línea 439...
439
 
439
 
440
    /**
440
    /**
441
     * Test that access manager uses cached Config Key.
441
     * Test that access manager uses cached Config Key.
442
     */
442
     */
443
    public function test_access_manager_uses_cached_config_key() {
443
    public function test_access_manager_uses_cached_config_key(): void {
444
        global $FULLME;
444
        global $FULLME;
Línea 445... Línea 445...
445
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
445
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 472... Línea 472...
472
    }
472
    }
Línea 473... Línea 473...
473
 
473
 
474
    /**
474
    /**
475
     * Check that valid SEB config key is null if quiz doesn't have SEB settings.
475
     * Check that valid SEB config key is null if quiz doesn't have SEB settings.
476
     */
476
     */
477
    public function test_valid_config_key_is_null_if_no_settings() {
477
    public function test_valid_config_key_is_null_if_no_settings(): void {
478
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
478
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
Línea 479... Línea 479...
479
        $accessmanager = $this->get_access_manager();
479
        $accessmanager = $this->get_access_manager();
480
 
480
 
Línea 484... Línea 484...
484
    }
484
    }
Línea 485... Línea 485...
485
 
485
 
486
    /**
486
    /**
487
     * Test if config key should not be validated.
487
     * Test if config key should not be validated.
488
     */
488
     */
489
    public function test_if_config_key_should_not_be_validated() {
489
    public function test_if_config_key_should_not_be_validated(): void {
490
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
490
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_NO);
Línea 491... Línea 491...
491
        $accessmanager = $this->get_access_manager();
491
        $accessmanager = $this->get_access_manager();
492
 
492
 
Línea 493... Línea 493...
493
        $this->assertTrue($accessmanager->validate_config_key());
493
        $this->assertTrue($accessmanager->validate_config_key());
494
    }
494
    }
495
 
495
 
496
    /**
496
    /**
497
     * Test if browser exam key should not be validated.
497
     * Test if browser exam key should not be validated.
498
     */
498
     */
Línea 499... Línea 499...
499
    public function test_if_browser_exam_key_should_not_be_validated() {
499
    public function test_if_browser_exam_key_should_not_be_validated(): void {
500
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
500
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 501... Línea 501...
501
        $accessmanager = $this->get_access_manager();
501
        $accessmanager = $this->get_access_manager();
502
 
502
 
503
        $this->assertTrue($accessmanager->validate_browser_exam_key());
503
        $this->assertTrue($accessmanager->validate_browser_exam_key());
504
    }
504
    }
505
 
505
 
Línea 506... Línea 506...
506
    /**
506
    /**
507
     * Test that access is set correctly in Moodle session.
507
     * Test that access is set correctly in Moodle session.
Línea 520... Línea 520...
520
    }
520
    }
Línea 521... Línea 521...
521
 
521
 
522
    /**
522
    /**
523
     * Test that access is set in Moodle session for only course module associated with access manager.
523
     * Test that access is set in Moodle session for only course module associated with access manager.
524
     */
524
     */
525
    public function test_session_access_set_for_specific_course_module() {
525
    public function test_session_access_set_for_specific_course_module(): void {
Línea 526... Línea 526...
526
        global $SESSION;
526
        global $SESSION;
527
 
527
 
528
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
528
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CLIENT_CONFIG);
Línea 537... Línea 537...
537
    }
537
    }
Línea 538... Línea 538...
538
 
538
 
539
    /**
539
    /**
540
     * Test that access state can be retrieved from Moodle session.
540
     * Test that access state can be retrieved from Moodle session.
541
     */
541
     */
542
    public function test_validate_session_access() {
542
    public function test_validate_session_access(): void {
Línea 543... Línea 543...
543
        global $SESSION;
543
        global $SESSION;
544
 
544
 
Línea 553... Línea 553...
553
    }
553
    }
Línea 554... Línea 554...
554
 
554
 
555
    /**
555
    /**
556
     * Test that access can be cleared from Moodle session.
556
     * Test that access can be cleared from Moodle session.
557
     */
557
     */
558
    public function test_clear_session_access() {
558
    public function test_clear_session_access(): void {
Línea 559... Línea 559...
559
        global $SESSION;
559
        global $SESSION;
560
 
560
 
Línea 569... Línea 569...
569
    }
569
    }
Línea 570... Línea 570...
570
 
570
 
571
    /**
571
    /**
572
     * Test we can decide if need to redirect to SEB config link.
572
     * Test we can decide if need to redirect to SEB config link.
573
     */
573
     */
574
    public function test_should_redirect_to_seb_config_link() {
574
    public function test_should_redirect_to_seb_config_link(): void {
575
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
575
        $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY);
Línea 576... Línea 576...
576
        $accessmanager = $this->get_access_manager();
576
        $accessmanager = $this->get_access_manager();
577
 
577