Răsfoiți Sursa

Feedback encryption and upload added to test coverage

Miro Kuratczyk 9 ani în urmă
părinte
comite
b04b8fbd65
3 a modificat fișierele cu 84 adăugiri și 0 ștergeri
  1. 3 0
      .travis.yml
  2. BIN
      psiphon/feedback_test.config.enc
  3. 81 0
      psiphon/feedback_test.go

+ 3 - 0
.travis.yml

@@ -20,5 +20,8 @@ before_install:
 - go get github.com/modocache/gover
 - go get github.com/mattn/goveralls
 - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
+- git rev-parse --short HEAD > psiphon/git_rev
 - openssl aes-256-cbc -K $encrypted_bf83b4ab4874_key -iv $encrypted_bf83b4ab4874_iv
   -in psiphon/controller_test.config.enc -out psiphon/controller_test.config -d
+- openssl aes-256-cbc -K $encrypted_sq6sgjwvsppj_key -iv $encrypted_sq6sgjwvsppj_iv
+  -in psiphon/feedback_test.config.enc -out psiphon/feedback_test.config -d

BIN
psiphon/feedback_test.config.enc


+ 81 - 0
psiphon/feedback_test.go

@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016, Psiphon Inc.
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package psiphon
+
+import (
+	"encoding/json"
+	"io/ioutil"
+	"testing"
+)
+
+type Diagnostics struct {
+	Feedback struct {
+		Message struct {
+			Text string `json:"text"`
+		}
+		Email string `json:"email"`
+	}
+	Metadata struct {
+		Id       string `json:"id"`
+		Platform string `json:"platform"`
+		Version  int    `json:"version"`
+	}
+}
+
+func TestFeedbackUpload(t *testing.T) {
+	configFileContents, err := ioutil.ReadFile("feedback_test.config")
+	if err != nil {
+		// Skip, don't fail, if config file is not present
+		t.Skipf("error loading configuration file: %s", err)
+	}
+
+	shortRevHash, err := ioutil.ReadFile("git_rev")
+	if err != nil {
+		// Skip, don't fail, if git rev file is not present
+		t.Skipf("error loading git revision file: %s", err)
+	}
+
+	var config map[string]interface{}
+
+	err = json.Unmarshal(configFileContents, &config)
+	if err != nil {
+		t.Error(err.Error())
+		t.FailNow()
+	}
+
+	// Form dummy feedback data which can be verified later
+	diagnostics := Diagnostics{}
+	diagnostics.Feedback.Message.Text = "Travis test feedback. Revision " + string(shortRevHash)
+	diagnostics.Metadata.Id = "0000000000000000"
+	diagnostics.Metadata.Platform = "android"
+	diagnostics.Metadata.Version = 4
+
+	diagnosticData, err := json.Marshal(diagnostics)
+	if err != nil {
+		t.Error(err.Error())
+		t.FailNow()
+	}
+
+	err = SendFeedback(string(configFileContents), string(diagnosticData), config["ENCRYPTION_PUBLIC_KEY"].(string), config["UPLOAD_SERVER"].(string), config["UPLOAD_PATH"].(string), config["UPLOAD_SERVER_HEADERS"].(string))
+	if err != nil {
+		t.Error(err.Error())
+		t.FailNow()
+	}
+}