Roots uploaded by bots don't get author specified properly
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Jul 2017 21:14:52 +0000 (21:14 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Jul 2017 21:14:52 +0000 (21:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174087

Reviewed by Andreas Kling.

When a root file is uploaded from the bot, we manually specify the remote user to upload_file_in_transaction.
However, this was getting ignored by create_uploaded_file_from_form_data since it was always calling
remote_user_name to get the user name off of $_SERVER.

Fixed the bug by passing in the user name from upload_file_in_transaction to create_uploaded_file_from_form_data.

* public/include/uploaded-file-helpers.php:
(create_uploaded_file_from_form_data): Take the remote user as an argument instead of calling remote_user_name.
(upload_file_in_transaction):
* server-tests/api-upload-root-tests.js: Updated an existing test cases to make sure root files' author is set.
(createTestGroupWihPatch): Manually override the author of a test group for testing.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219092 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/include/uploaded-file-helpers.php
Websites/perf.webkit.org/server-tests/api-upload-root-tests.js

index 4a4f026..5882c06 100644 (file)
@@ -1,5 +1,24 @@
 2017-07-03  Ryosuke Niwa  <rniwa@webkit.org>
 
+        Roots uploaded by bots don't get author specified properly
+        https://bugs.webkit.org/show_bug.cgi?id=174087
+
+        Reviewed by Andreas Kling.
+
+        When a root file is uploaded from the bot, we manually specify the remote user to upload_file_in_transaction.
+        However, this was getting ignored by create_uploaded_file_from_form_data since it was always calling
+        remote_user_name to get the user name off of $_SERVER.
+
+        Fixed the bug by passing in the user name from upload_file_in_transaction to create_uploaded_file_from_form_data.
+
+        * public/include/uploaded-file-helpers.php:
+        (create_uploaded_file_from_form_data): Take the remote user as an argument instead of calling remote_user_name.
+        (upload_file_in_transaction):
+        * server-tests/api-upload-root-tests.js: Updated an existing test cases to make sure root files' author is set.
+        (createTestGroupWihPatch): Manually override the author of a test group for testing.
+
+2017-07-03  Ryosuke Niwa  <rniwa@webkit.org>
+
         Prune unused uploaded files when the file quota is reached
         https://bugs.webkit.org/show_bug.cgi?id=174086
 
index 9949afa..2f36a92 100644 (file)
@@ -63,7 +63,7 @@ function query_total_file_usage($db)
     return intval($count_result[0]["sum"]);
 }
 
-function create_uploaded_file_from_form_data($input_file)
+function create_uploaded_file_from_form_data($input_file, $remote_user)
 {
     $file_sha256 = hash_file('sha256', $input_file['tmp_name']);
     if (!$file_sha256)
@@ -77,7 +77,7 @@ function create_uploaded_file_from_form_data($input_file)
     }
 
     return array(
-        'author' => remote_user_name(),
+        'author' => $remote_user,
         'filename' => $input_file['name'],
         'extension' => $file_extension,
         'mime' => $input_file['type'], // Sanitize MIME types.
@@ -97,7 +97,7 @@ function upload_file_in_transaction($db, $input_file, $remote_user, $additional_
             exit_with_error('FileSizeQuotaExceeded');
     }
 
-    $uploaded_file = create_uploaded_file_from_form_data($input_file);
+    $uploaded_file = create_uploaded_file_from_form_data($input_file, $remote_user);
 
     $db->begin_transaction();
     $file_row = $db->select_or_insert_row('uploaded_files', 'file',
index 9096afc..bffcf60 100644 (file)
@@ -48,7 +48,8 @@ function createTestGroupWihPatch()
         ]
     };
 
-    return MockData.addMockData(TestServer.database()).then(() => {
+    const db = TestServer.database();
+    return MockData.addMockData(db).then(() => {
         return Promise.all([TemporaryFile.makeTemporaryFile('patch.dat', 'patch file'), Manifest.fetch()]);
     }).then((result) => {
         const patchFile = result[0];
@@ -67,7 +68,9 @@ function createTestGroupWihPatch()
         return TestGroup.createWithTask('custom task', Platform.findById(MockData.somePlatformId()), someTest, 'some group', 2, [set1, set2]);
     }).then((task) => {
         return TestGroup.findAllByTask(task.id())[0];
-    })
+    }).then((group) => {
+        return db.query('UPDATE analysis_test_groups SET testgroup_author = $1', ['someUser']).then(() => group);
+    });
 }
 
 describe('/api/upload-root/', function () {
@@ -247,6 +250,7 @@ describe('/api/upload-root/', function () {
             const uploadedRootRawData = response['uploadedFile'];
             uploadedRoot = UploadedFile.ensureSingleton(uploadedRootRawData.id, uploadedRootRawData);
             assert.equal(uploadedRoot.filename(), 'some.dat');
+            assert.equal(uploadedRoot.author(), 'someUser');
             return TestGroup.fetchForTask(buildRequest.testGroup().task().id(), true);
         }).then((testGroups) => {
 
@@ -382,6 +386,7 @@ describe('/api/upload-root/', function () {
             const uploadedRootRawData = response['uploadedFile'];
             uploadedRoot = UploadedFile.ensureSingleton(uploadedRootRawData.id, uploadedRootRawData);
             assert.equal(uploadedRoot.filename(), 'some.dat');
+            assert.equal(uploadedRoot.author(), 'someUser');
             return TestGroup.fetchForTask(buildRequest.testGroup().task().id(), true);
         }).then((testGroups) => {