Let compileserver add auth parameter.

Change-Id: I17c9039f1447c72233418f66c300998bc8cdd3e3
diff --git a/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/guice/BenchmarkModule.java b/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/guice/BenchmarkModule.java
index edac4ad..2773d50 100644
--- a/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/guice/BenchmarkModule.java
+++ b/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/guice/BenchmarkModule.java
@@ -79,6 +79,8 @@
         .toInstance(settings.getScriptsDirectory());
     bind(Boolean.class).annotatedWith(Names.named("useReporter"))
         .toInstance(settings.reportResults());
+    bind(String.class).annotatedWith(Names.named("reporterSecret")).toInstance(
+        settings.getReporterSecret());
     bind(String.class).annotatedWith(Names.named("benchmarkDashboardUrl"))
         .toInstance(settings.getReporterUrl());
     bind(File.class).annotatedWith(Names.named("persistenceDir"))
diff --git a/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporter.java b/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporter.java
index 6989d6f..83a3e2e 100644
--- a/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporter.java
+++ b/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporter.java
@@ -19,6 +19,7 @@
 import com.google.gwt.benchmark.compileserver.server.manager.BenchmarkRun.Result;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
+import com.google.inject.name.Named;
 import com.google.web.bindery.autobean.shared.AutoBean;
 import com.google.web.bindery.autobean.shared.AutoBeanCodex;
 import com.google.web.bindery.autobean.shared.AutoBeanUtils;
@@ -73,12 +74,15 @@
 
   private final long commitMsEpoch;
 
+  private String reporterSecret;
+
   @Inject
   public BenchmarkReporter(HttpURLConnectionFactory httpURLConnectionFactory,
-      @Assisted Map<String, BenchmarkRun> results, @Assisted("commitId") String commitId,
-      @Assisted("commitDate") long commitMsEpoch,
+      @Named("reporterSecret") String reporterSecret, @Assisted Map<String, BenchmarkRun> results,
+      @Assisted("commitId") String commitId, @Assisted("commitDate") long commitMsEpoch,
       @Assisted ReportProgressHandler reportProgressHandler) {
     this.httpURLConnectionFactory = httpURLConnectionFactory;
+    this.reporterSecret = reporterSecret;
     this.results = results;
     this.commitId = commitId;
     this.commitMsEpoch = commitMsEpoch;
@@ -145,6 +149,7 @@
     try {
 
       HttpURLConnection httpCon = httpURLConnectionFactory.create();
+      httpCon.addRequestProperty("auth", reporterSecret);
       httpCon.setDoOutput(true);
       httpCon.setRequestMethod("PUT");
 
diff --git a/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/runners/settings/Settings.java b/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/runners/settings/Settings.java
index 4aa981b..3a3f1a4 100644
--- a/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/runners/settings/Settings.java
+++ b/compileserver/src/main/java/com/google/gwt/benchmark/compileserver/server/runners/settings/Settings.java
@@ -47,6 +47,7 @@
       settings.ipAddress = Util.getFirstNonLoopbackAddress().getHostAddress();
       settings.reportResults = prop.getProperty("reportResuts").equals("true");
       settings.reporterUrl = prop.getProperty("reporterUrl");
+      settings.reporterSecret = prop.getProperty("reporterSecret");
       settings.mode =
           prop.getProperty("mode").equals("server") ? ManagerMode.SERVER : ManagerMode.LOCAL;
       settings.persistenceDir = new File(prop.getProperty("persistenceDir"));
@@ -85,6 +86,7 @@
   private int threadPoolSize;
   private boolean reportResults;
   private String reporterUrl;
+  private String reporterSecret;
   private File persistenceDir;
   private ManagerMode mode;
   private File gwtSourceLocation;
@@ -127,6 +129,10 @@
     return reporterUrl;
   }
 
+  public String getReporterSecret() {
+    return reporterSecret;
+  }
+
   public ManagerMode getMode() {
     return mode;
   }
diff --git a/compileserver/src/test/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporterTest.java b/compileserver/src/test/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporterTest.java
index 73cd09d..ab44ec3 100644
--- a/compileserver/src/test/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporterTest.java
+++ b/compileserver/src/test/java/com/google/gwt/benchmark/compileserver/server/manager/BenchmarkReporterTest.java
@@ -85,13 +85,14 @@
     Mockito.when(urlConnection.getOutputStream()).thenReturn(outputStream);
     Mockito.when(urlConnection.getResponseCode()).thenReturn(200);
 
-    reporter =
-        new BenchmarkReporter(urlFactory, results, commitId, commitDate, reportProgressHandler);
+    reporter = new BenchmarkReporter(urlFactory, "auth1", results, commitId, commitDate,
+        reportProgressHandler);
 
     reporter.run();
 
     Mockito.verify(outputStream).close();
     Mockito.verify(urlConnection).setRequestMethod("PUT");
+    Mockito.verify(urlConnection).addRequestProperty("auth", "auth1");
     ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
     Mockito.verify(outputStream).write(captor.capture());
 
@@ -142,15 +143,15 @@
 
     final List<Integer> waitingTimes = new ArrayList<>();
 
-    reporter =
-        new BenchmarkReporter(urlFactory, results, commitId, commitDate, reportProgressHandler) {
+    reporter = new BenchmarkReporter(urlFactory, "auth1", results, commitId, commitDate,
+        reportProgressHandler) {
 
-          @Override
-          boolean sleep(int seconds) {
-            waitingTimes.add(seconds);
-            return true;
-          }
-        };
+      @Override
+      boolean sleep(int seconds) {
+        waitingTimes.add(seconds);
+        return true;
+      }
+    };
 
     reporter.run();