Преглед изворни кода

Merge branch 'master' of https://github.com/Psiphon-Labs/psiphon-tunnel-core

Rod Hynes пре 10 година
родитељ
комит
1def0df3f2
3 измењених фајлова са 47 додато и 36 уклоњено
  1. 38 34
      psiphon/config_test.go
  2. 2 0
      psiphon/controller.go
  3. 7 2
      psiphon/notice.go

+ 38 - 34
psiphon/config_test.go

@@ -86,42 +86,46 @@ func (suite *ConfigTestSuite) Test_LoadConfig_BadJson() {
 	_, err := LoadConfig([]byte(`{"f1": 11, "f2": "two"}`))
 	suite.NotNil(err, "JSON with none of our fields should fail")
 
-	// Test config missing each required field
-	for i := range suite.requiredFields {
-	  json.Unmarshal(suite.confStubBlob, &testObj)
-	  delete(testObj, suite.requiredFields[i])
-	  testObjJSON, _ = json.Marshal(testObj)
-	  _, err = LoadConfig(testObjJSON)
-	  suite.NotNil(err, "JSON with one of our required fields missing should fail")
+	// Test all required fields
+	for _, field := range suite.requiredFields {
+		// Missing a required field
+		json.Unmarshal(suite.confStubBlob, &testObj)
+		delete(testObj, field)
+		testObjJSON, _ = json.Marshal(testObj)
+		_, err = LoadConfig(testObjJSON)
+		suite.NotNil(err, "JSON with one of our required fields missing should fail: %s", field)
+
+		// Bad type for required field
+		json.Unmarshal(suite.confStubBlob, &testObj)
+		testObj[field] = false // basically guessing a wrong type
+		testObjJSON, _ = json.Marshal(testObj)
+		_, err = LoadConfig(testObjJSON)
+		suite.NotNil(err, "JSON with one of our required fields with the wrong type should fail: %s", field)
+
+		// One of our required fields is null
+		json.Unmarshal(suite.confStubBlob, &testObj)
+		testObj[field] = nil
+		testObjJSON, _ = json.Marshal(testObj)
+		_, err = LoadConfig(testObjJSON)
+		suite.NotNil(err, "JSON with one of our required fields set to null should fail: %s", field)
+
+		// One of our required fields is an empty string
+		json.Unmarshal(suite.confStubBlob, &testObj)
+		testObj[field] = ""
+		testObjJSON, _ = json.Marshal(testObj)
+		_, err = LoadConfig(testObjJSON)
+		suite.NotNil(err, "JSON with one of our required fields set to an empty string should fail: %s", field)
 	}
 
-	// Bad type for required field
-	json.Unmarshal(suite.confStubBlob, &testObj)
-	testObj[suite.requiredFields[0]] = false // basically guessing a wrong type
-	testObjJSON, _ = json.Marshal(testObj)
-	_, err = LoadConfig(testObjJSON)
-	suite.NotNil(err, "JSON with one of our required fields with the wrong type should fail")
-
-	// One of our required fields is null
-	json.Unmarshal(suite.confStubBlob, &testObj)
-	testObj[suite.requiredFields[0]] = nil
-	testObjJSON, _ = json.Marshal(testObj)
-	_, err = LoadConfig(testObjJSON)
-	suite.NotNil(err, "JSON with one of our required fields set to null should fail")
-
-	// One of our required fields is an empty string
-	json.Unmarshal(suite.confStubBlob, &testObj)
-	testObj[suite.requiredFields[0]] = ""
-	testObjJSON, _ = json.Marshal(testObj)
-	_, err = LoadConfig(testObjJSON)
-	suite.NotNil(err, "JSON with one of our required fields set to an empty string should fail")
-
-	// Has incorrect type for optional field
-	json.Unmarshal(suite.confStubBlob, &testObj)
-	testObj[suite.nonRequiredFields[0]] = false // basically guessing a wrong type
-	testObjJSON, _ = json.Marshal(testObj)
-	_, err = LoadConfig(testObjJSON)
-	suite.NotNil(err, "JSON with one of our optional fields with the wrong type should fail")
+	// Test optional fields
+	for _, field := range suite.nonRequiredFields {
+		// Has incorrect type for optional field
+		json.Unmarshal(suite.confStubBlob, &testObj)
+		testObj[field] = false // basically guessing a wrong type
+		testObjJSON, _ = json.Marshal(testObj)
+		_, err = LoadConfig(testObjJSON)
+		suite.NotNil(err, "JSON with one of our optional fields with the wrong type should fail: %s", field)
+	}
 }
 
 // Tests config file with JSON contents that don't match our structure

+ 2 - 0
psiphon/controller.go

@@ -229,6 +229,8 @@ func (controller *Controller) Run(shutdownBroadcast <-chan struct{}) {
 	controller.splitTunnelClassifier.Shutdown()
 
 	NoticeInfo("exiting controller")
+
+	NoticeExiting()
 }
 
 // SignalComponentFailure notifies the controller that an associated component has failed.

+ 7 - 2
psiphon/notice.go

@@ -302,7 +302,7 @@ func NoticeLocalProxyError(proxyType string, err error) {
 
 // NoticeConnectedMeekStats reports extra network details for a meek tunnel connection.
 func NoticeConnectedMeekStats(ipAddress string, meekStats *MeekStats) {
-	outputNotice("NoticeConnectedMeekStats", true, false,
+	outputNotice("ConnectedMeekStats", true, false,
 		"ipAddress", ipAddress,
 		"dialAddress", meekStats.DialAddress,
 		"resolvedIPAddress", meekStats.ResolvedIPAddress,
@@ -313,7 +313,7 @@ func NoticeConnectedMeekStats(ipAddress string, meekStats *MeekStats) {
 
 // NoticeBuildInfo reports build version info.
 func NoticeBuildInfo(buildDate, buildRepo, buildRev, goVersion, gomobileVersion string) {
-	outputNotice("NoticeBuildInfo", false, false,
+	outputNotice("BuildInfo", false, false,
 		"buildDate", buildDate,
 		"buildRepo", buildRepo,
 		"buildRev", buildRev,
@@ -321,6 +321,11 @@ func NoticeBuildInfo(buildDate, buildRepo, buildRev, goVersion, gomobileVersion
 		"gomobileVersion", gomobileVersion)
 }
 
+// NoticeExiting indicates that tunnel-core is exiting imminently.
+func NoticeExiting() {
+	outputNotice("Exiting", false, true)
+}
+
 type repetitiveNoticeState struct {
 	message string
 	repeats int