api/report-commit should authenticate with a slave name and password
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jan 2015 22:25:31 +0000 (22:25 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jan 2015 22:25:31 +0000 (22:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140308

Reviewed by Benjamin Poulain.

Use a slave name and a password to authenticate new commit reports.

* public/api/report-commits.php:
(main):
* public/include/json-header.php:
(verify_slave): Renamed and repurposed from verify_builder in report-commits.php. Now authenticates with
a slave name and a password instead of a builder name and a password.
* tests/api-report-commits.js: Updated tests.
* tools/pull-svn.py:
(main): Renamed variables.
(submit_commits): Submits slaveName and slavePassword instead of builderName and builderPassword.

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

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/api/report-commits.php
Websites/perf.webkit.org/public/include/json-header.php
Websites/perf.webkit.org/tests/api-report-commits.js
Websites/perf.webkit.org/tools/pull-svn.py

index ccdeafe..4f59d4e 100644 (file)
@@ -1,3 +1,22 @@
+2015-01-09  Ryosuke Niwa  <rniwa@webkit.org>
+
+        api/report-commit should authenticate with a slave name and password
+        https://bugs.webkit.org/show_bug.cgi?id=140308
+
+        Reviewed by Benjamin Poulain.
+
+        Use a slave name and a password to authenticate new commit reports.
+
+        * public/api/report-commits.php:
+        (main):
+        * public/include/json-header.php:
+        (verify_slave): Renamed and repurposed from verify_builder in report-commits.php. Now authenticates with
+        a slave name and a password instead of a builder name and a password.
+        * tests/api-report-commits.js: Updated tests.
+        * tools/pull-svn.py:
+        (main): Renamed variables.
+        (submit_commits): Submits slaveName and slavePassword instead of builderName and builderPassword.
+
 2014-12-19  Ryosuke Niwa  <rniwa@webkit.org>
 
         Perf dashboard should support authentication via a slave password
index 18f4211..d4026f2 100644 (file)
@@ -9,7 +9,7 @@ function main($post_data) {
 
     $report = json_decode($post_data, true);
 
-    verify_builder($db, $report);
+    verify_slave($db, $report);
 
     $commits = array_get($report, 'commits', array());
 
@@ -73,20 +73,6 @@ function main($post_data) {
     exit_with_success();
 }
 
-function verify_builder($db, $report) {
-    array_key_exists('builderName', $report) or exit_with_error('MissingBuilderName');
-    array_key_exists('builderPassword', $report) or exit_with_error('MissingBuilderPassword');
-
-    $builder_info = array(
-        'name' => $report['builderName'],
-        'password_hash' => hash('sha256', $report['builderPassword'])
-    );
-
-    $matched_builder = $db->select_first_row('builders', 'builder', $builder_info);
-    if (!$matched_builder)
-        exit_with_error('BuilderNotFound', array('name' => $builder_info['name']));
-}
-
 main($HTTP_RAW_POST_DATA);
 
 ?>
index 0fef7a1..07ad8e8 100644 (file)
@@ -111,4 +111,18 @@ function verify_token($token) {
     return $expected_token && $token == $expected_token && $_COOKIE['CSRFExpiration'] > time();
 }
 
+function verify_slave($db, $params) {
+    array_key_exists('slaveName', $params) or exit_with_error('MissingSlaveName');
+    array_key_exists('slavePassword', $params) or exit_with_error('MissingSlavePassword');
+
+    $slave_info = array(
+        'name' => $params['slaveName'],
+        'password_hash' => hash('sha256', $params['slavePassword'])
+    );
+
+    $matched_slave = $db->select_first_row('build_slaves', 'slave', $slave_info);
+    if (!$matched_slave)
+        exit_with_error('SlaveNotFound', array('name' => $slave_info['name']));
+}
+
 ?>
index 92d8cc3..042714f 100644 (file)
@@ -1,11 +1,11 @@
 describe("/api/report-commits/", function () {
     var emptyReport = {
-        "builderName": "someBuilder",
-        "builderPassword": "somePassword",
+        "slaveName": "someSlave",
+        "slavePassword": "somePassword",
     };
     var subversionCommit = {
-        "builderName": "someBuilder",
-        "builderPassword": "somePassword",
+        "slaveName": "someSlave",
+        "slavePassword": "somePassword",
         "commits": [
             {
                 "repository": "WebKit",
@@ -17,8 +17,8 @@ describe("/api/report-commits/", function () {
         ],
     };
     var subversionInvalidCommit = {
-        "builderName": "someBuilder",
-        "builderPassword": "somePassword",
+        "slaveName": "someSlave",
+        "slavePassword": "somePassword",
         "commits": [
             {
                 "repository": "WebKit",
@@ -30,8 +30,8 @@ describe("/api/report-commits/", function () {
         ],
     };
     var subversionTwoCommits = {
-        "builderName": "someBuilder",
-        "builderPassword": "somePassword",
+        "slaveName": "someSlave",
+        "slavePassword": "somePassword",
         "commits": [
             {
                 "repository": "WebKit",
@@ -51,20 +51,20 @@ describe("/api/report-commits/", function () {
         ]
     }
 
-    function addBuilder(report, callback) {
-        queryAndFetchAll('INSERT INTO builders (builder_name, builder_password_hash) values ($1, $2)',
-            [report.builderName, sha256(report.builderPassword)], callback);
+    function addSlave(report, callback) {
+        queryAndFetchAll('INSERT INTO build_slaves (slave_name, slave_password_hash) values ($1, $2)',
+            [report.slaveName, sha256(report.slavePassword)], callback);
     }
 
-    it("should reject error when builder name is missing", function () {
+    it("should reject error when slave name is missing", function () {
         postJSON('/api/report-commits/', {}, function (response) {
             assert.equal(response.statusCode, 200);
-            assert.equal(JSON.parse(response.responseText)['status'], 'MissingBuilderName');
+            assert.equal(JSON.parse(response.responseText)['status'], 'MissingSlaveName');
             notifyDone();
         });
     });
 
-    it("should reject when there are no builders", function () {
+    it("should reject when there are no slaves", function () {
         postJSON('/api/report-commits/', emptyReport, function (response) {
             assert.equal(response.statusCode, 200);
             assert.notEqual(JSON.parse(response.responseText)['status'], 'OK');
@@ -77,7 +77,7 @@ describe("/api/report-commits/", function () {
     });
 
     it("should accept an empty report", function () {
-        addBuilder(emptyReport, function () {
+        addSlave(emptyReport, function () {
             postJSON('/api/report-commits/', emptyReport, function (response) {
                 assert.equal(response.statusCode, 200);
                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
@@ -87,7 +87,7 @@ describe("/api/report-commits/", function () {
     });
 
     it("should add a missing repository", function () {
-        addBuilder(subversionCommit, function () {
+        addSlave(subversionCommit, function () {
             postJSON('/api/report-commits/', subversionCommit, function (response) {
                 assert.equal(response.statusCode, 200);
                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
@@ -100,8 +100,8 @@ describe("/api/report-commits/", function () {
         });
     });
 
-    it("should store a commit from a valid builder", function () {
-        addBuilder(subversionCommit, function () {
+    it("should store a commit from a valid slave", function () {
+        addSlave(subversionCommit, function () {
             postJSON('/api/report-commits/', subversionCommit, function (response) {
                 assert.equal(response.statusCode, 200);
                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
@@ -120,7 +120,7 @@ describe("/api/report-commits/", function () {
     });
 
     it("should reject an invalid revision number", function () {
-        addBuilder(subversionCommit, function () {
+        addSlave(subversionCommit, function () {
             subversionCommit
             postJSON('/api/report-commits/', subversionInvalidCommit, function (response) {
                 assert.equal(response.statusCode, 200);
@@ -133,8 +133,8 @@ describe("/api/report-commits/", function () {
         });
     });
 
-    it("should store two commits from a valid builder", function () {
-        addBuilder(subversionTwoCommits, function () {
+    it("should store two commits from a valid slave", function () {
+        addSlave(subversionTwoCommits, function () {
             postJSON('/api/report-commits/', subversionTwoCommits, function (response) {
                 assert.equal(response.statusCode, 200);
                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
@@ -166,7 +166,7 @@ describe("/api/report-commits/", function () {
                 [repositoryId, reportedData['revision'], reportedData['time']], function (existingCommits) {
                 var commitId = existingCommits[0]['commit_id'];
                 assert.equal(existingCommits[0]['commit_message'], null);
-                addBuilder(subversionCommit, function () {
+                addSlave(subversionCommit, function () {
                     postJSON('/api/report-commits/', subversionCommit, function (response) {
                         assert.equal(response.statusCode, 200);
                         assert.equal(JSON.parse(response.responseText)['status'], 'OK');
@@ -193,7 +193,7 @@ describe("/api/report-commits/", function () {
                 reportedData = subversionTwoCommits.commits[0];
                 queryAndFetchAll('INSERT INTO commits (commit_repository, commit_revision, commit_time) VALUES ($1, $2, $3) RETURNING *',
                     [repositoryId, reportedData['revision'], reportedData['time']], function () {
-                        addBuilder(subversionCommit, function () {
+                        addSlave(subversionCommit, function () {
                             postJSON('/api/report-commits/', subversionCommit, function (response) {
                                 assert.equal(response.statusCode, 200);
                                 assert.equal(JSON.parse(response.responseText)['status'], 'OK');
@@ -218,7 +218,7 @@ describe("/api/report-commits/", function () {
         queryAndFetchAll('INSERT INTO repositories (repository_id, repository_name) VALUES (1, \'WebKit\')', [], function () {
             var author = subversionCommit.commits[0]['author'];
             queryAndFetchAll('INSERT INTO committers (committer_repository, committer_account) VALUES (1, $1)', [author['account']], function () {
-                addBuilder(subversionCommit, function () {
+                addSlave(subversionCommit, function () {
                     postJSON('/api/report-commits/', subversionCommit, function (response) {
                         assert.equal(response.statusCode, 200);
                         assert.equal(JSON.parse(response.responseText)['status'], 'OK');
index 6915862..da6d0ad 100755 (executable)
@@ -12,13 +12,13 @@ from xml.dom.minidom import parseString as parseXmlString
 
 def main(argv):
     if len(argv) < 7:
-        sys.exit('Usage: pull-svn <repository-name> <repository-URL> <dashboard-URL> <builder-name> <builder-password> <seconds-to-sleep> [<account-to-name-helper>]')
+        sys.exit('Usage: pull-svn <repository-name> <repository-URL> <dashboard-URL> <slave-name> <slave-password> <seconds-to-sleep> [<account-to-name-helper>]')
 
     repository_name = argv[1]
     repository_url = argv[2]
     dashboard_url = argv[3]
-    builder_name = argv[4]
-    builder_password = argv[5]
+    slave_name = argv[4]
+    slave_password = argv[5]
     seconds_to_sleep = float(argv[6])
     account_to_name_helper = argv[7] if len(argv) > 7 else None
 
@@ -42,7 +42,7 @@ def main(argv):
         if not commit or len(pending_commits_to_send) >= 10:
             if pending_commits_to_send:
                 print "Submitting the above commits to %s..." % dashboard_url
-                submit_commits(pending_commits_to_send, dashboard_url, builder_name, builder_password)
+                submit_commits(pending_commits_to_send, dashboard_url, slave_name, slave_password)
                 print "Successfully submitted."
             pending_commits_to_send = []
             time.sleep(seconds_to_sleep)
@@ -136,11 +136,11 @@ def resolve_author_name_from_account(helper, account):
     return output.strip()
 
 
-def submit_commits(commits, dashboard_url, builder_name, builder_password):
+def submit_commits(commits, dashboard_url, slave_name, slave_password):
     try:
         payload = json.dumps({
-            'builderName': builder_name,
-            'builderPassword': builder_password,
+            'slaveName': slave_name,
+            'slavePassword': slave_password,
             'commits': commits,
         })
         request = urllib2.Request(dashboard_url + '/api/report-commits')