Skip to content

Commit

Permalink
Refactor playlist acl tests
Browse files Browse the repository at this point in the history
Decreases redundant code
  • Loading branch information
dennis531 committed Dec 11, 2024
1 parent 24884a9 commit f8961bd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 159 deletions.
159 changes: 0 additions & 159 deletions tests/AclCest.php

This file was deleted.

36 changes: 36 additions & 0 deletions tests/CoursesCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
class CoursesCest
{
private $config_id;
private $api_token;
private $course_student;
private $course_id;

public function _before(ApiTester $I)
{
$config = $I->getConfig();

$this->config_id = $config['config_id'];
$this->api_token = $config['api_token'];
$this->course_student = $config['course_student'];
$this->course_id = $config['course_id'];

$I->amHttpAuthenticated($config['dozent_name'], $config['dozent_password']);
Expand Down Expand Up @@ -68,10 +72,27 @@ public function testAddPlaylist(ApiTester $I)
$I->seeResponseContainsJson(['users' => [['perm' => 'owner']]]);

list($token) = $I->grabDataFromResponseByJsonPath('$.token');
list($service_playlist_id) = $I->grabDataFromResponseByJsonPath('$.service_playlist_id');

// Add playlist to course
$response = $I->sendPost('/courses/' . $this->course_id . '/playlist/' . $token);
$I->seeResponseCodeIs(204);

// Check if student of course has read access only
$response = $I->sendGetAsJson('/opencast/user/' . $this->course_student, ['token' => $this->api_token]);

$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

$I->seeResponseContainsJson([
'username' => $this->course_student,
'roles' => [
'PLAYLIST_' . $service_playlist_id . '_read',
]
]);
$I->dontSeeResponseContainsJson(['roles' => [
'PLAYLIST_' . $service_playlist_id . '_write',
]]);
}

public function testRemovePlaylist(ApiTester $I)
Expand All @@ -92,6 +113,7 @@ public function testRemovePlaylist(ApiTester $I)
$I->seeResponseContainsJson(['users' => [['perm' => 'owner']]]);

list($token) = $I->grabDataFromResponseByJsonPath('$.token');
list($service_playlist_id) = $I->grabDataFromResponseByJsonPath('$.service_playlist_id');

// Add playlist to course
$response = $I->sendPost('/courses/' . $this->course_id . '/playlist/' . $token);
Expand All @@ -100,6 +122,20 @@ public function testRemovePlaylist(ApiTester $I)
// Remove playlist from course
$response = $I->sendDelete('/courses/' . $this->course_id . '/playlist/' . $token);
$I->seeResponseCodeIs(204);

// Check if student of course has no access
$response = $I->sendGetAsJson('/opencast/user/' . $this->course_student, ['token' => $this->api_token]);

$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

$roles = ['PLAYLIST_' . $service_playlist_id . '_read', 'PLAYLIST_' . $service_playlist_id . '_write'];
foreach ($roles as $role) {
$I->dontseeResponseContainsJson([
'username' => $this->course_student,
'roles' => [$role]
]);
}
}

}
37 changes: 37 additions & 0 deletions tests/PlaylistsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

class PlaylistsCest
{
private $opencast_url;
private $config_id;
private $api_token;
private $opencast_admin_user;
private $opencast_admin_password;

private $dozent_name;
private $author_name;
private $author_password;

public function _before(ApiTester $I)
{
$config = $I->getConfig();

$this->opencast_url = $config['opencast_url'];
$this->config_id = $config['config_id'];
$this->api_token = $config['api_token'];
$this->opencast_admin_user = $config['opencast_admin_user'];
$this->opencast_admin_password = $config['opencast_admin_password'];
$this->dozent_name = $config['dozent_name'];
$this->author_name = $config['author_name'];
$this->author_password = $config['author_password'];

Expand All @@ -34,6 +44,33 @@ public function testCreatePlaylist(ApiTester $I)

$I->seeResponseContainsJson($playlist);
$I->seeResponseContainsJson(['users' => [['perm' => 'owner']]]);

list($service_playlist_id) = $I->grabDataFromResponseByJsonPath('$.service_playlist_id');

// Check if user has correct playlist role
$response = $I->sendGetAsJson('/opencast/user/' . $this->dozent_name, ['token' => $this->api_token]);

$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

$I->seeResponseContainsJson([
'username' => $this->dozent_name,
'roles' => [
'PLAYLIST_' . $service_playlist_id . '_write',
]
]);

// Check ACLs in Opencast

// Login as opencast admin
$I->amHttpAuthenticated($this->opencast_admin_user, $this->opencast_admin_password);

$response = $I->sendGetAsJson($this->opencast_url . '/api/playlists/' . $service_playlist_id);
$I->seeResponseContainsJson(['accessControlEntries' => [
['allow' => true, 'role' => 'PLAYLIST_' . $service_playlist_id . '_read', 'action' => 'read'],
['allow' => true, 'role' => 'PLAYLIST_' . $service_playlist_id . '_write', 'action' => 'read'],
['allow' => true, 'role' => 'PLAYLIST_' . $service_playlist_id . '_write', 'action' => 'write'],
]]);
}

public function testDeletePlaylist(ApiTester $I)
Expand Down

0 comments on commit f8961bd

Please sign in to comment.