#247095: Upload.module hard-codes 'view uploaded files' permission check has been fixed in D7 but we don't have a test for it, so opening this issue.

Steps to reproduce from the original issue which need to be converted into a patch:

To test this you'd need to:
- enable private file transfers
- grant one role 'view uploaded files' permissions
- upload files to a node
- determine the download URL of the uploaded file
- log in as the user with the 'view uploaded files' permissions and ensure that they're able to view the file
- log in as the user without the 'view uploaded files' permissions and ensure that they aren't able to view the file

CommentFileSizeAuthor
#7 upload_test.patch8.45 KBandreiashu
#5 upload_test.patch4.95 KBandreiashu
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Title: Tests for upload module 'view uploaded file' permissions » Tests for private file transfers

Broadening the scope.

andreiashu’s picture

Assigned: Unassigned » andreiashu

I'll try to take on this one.
I'll give you status in a few hours.

Edit: i need to enable upload module too :)
Edit2: i now saw that is is already enabled ('parent::setUp('upload');')

andreiashu’s picture

Status: Active » Postponed (maintainer needs more info)

I'm working on the test but i have a problem at "determine the download URL of the uploaded file". In our case the download URL of the uploaded file should be in the form of 'system/files/FILENAME' right ? Not something like file_directory_path() . '/FILENAME'.

Damien Tournoud’s picture

@andreiashu: you can probably directly use file_create_url().

andreiashu’s picture

Status: Postponed (maintainer needs more info) » Needs work
FileSize
4.95 KB

It needs some little more work. I'll review it in a couple of hours.
@Damien Tournoud: thanks, it your suggestion came at the right time.

Damien Tournoud’s picture

Quick review:

+    $edit = array();
+    $edit['file_directory_path'] = variable_get('file_directory_path', 'sites/default/files');
+    $edit['file_directory_temp'] = variable_get('file_directory_temp', '/tmp');
+    $edit['file_downloads'] = 2;
+    $this->drupalPost('admin/settings/file-system', $edit, t('Save configuration'));
+    $this->assertText('The configuration options have been saved.', 'Download method saved.');

You don't need to specify items that you don't want to change (here you can drop 'file_directory_path' and 'file_downloads'). Also, please use the FILE_DOWNLOADS_PRIVATE constant instead of the '2').

+      $this->assertResponse(array(200), 'Uploaded ' . $file_url . ' is accessible for users with \'view uploaded files\' permission.');
+      $this->assertResponse(array(403), 'Uploaded ' . basename($files[0]) . ' is not accessible for users without \'view uploaded files\' permission.');

The assert messages have to go thru t() (even if they are not translated, yet). That will allow you to write them in the form t("Uploaded @file is accessible for user with the 'view uploaded files' permission.", array('@file' => $file_url)). Also, please use " when you need to have single-quotes in your strings. That's cleaner.

Finally, you should extend UploadTestCase or integrate your test in that class. This way, you wouldn't have to redefine uploadFile() and checkUploadedFile().

andreiashu’s picture

Status: Needs work » Needs review
FileSize
8.45 KB

Refactored.
Edit: reattached the correct patch this time.

lilou’s picture

Title: Tests for private file transfers » TestingParty08: Tests for private file transfers
chx’s picture

Title: TestingParty08: Tests for private file transfers » Tests for private file transfers

As there is ongoing work already why did you move this to the testing party?

catch’s picture

Status: Needs review » Needs work

Still applies with some fuzz. A few code style issues - some functions missing documentaion, comments should start with a capital letter and end with a full stop etc. All minor stuff and otherwise it looks pretty good :)

catch’s picture

Component: tests » base system
Category: bug » task
Priority: Critical » Normal

Fixing the critical / pending bugs queues to reflect things which are really bugs or release critical.