Просмотр исходного кода

Fix: applyTacticsPayload retained old parameters

Rod Hynes 7 лет назад
Родитель
Сommit
afb7e7aa39
2 измененных файлов с 19 добавлено и 4 удалено
  1. 1 0
      psiphon/common/tactics/tactics.go
  2. 18 4
      psiphon/common/tactics/tactics_test.go

+ 1 - 0
psiphon/common/tactics/tactics.go

@@ -1582,6 +1582,7 @@ func applyTacticsPayload(
 
 	if payload.Tag != record.Tag {
 		record.Tag = payload.Tag
+		record.Tactics = Tactics{}
 		err := json.Unmarshal(payload.Tactics, &record.Tactics)
 		if err != nil {
 			return common.ContextError(err)

+ 18 - 4
psiphon/common/tactics/tactics_test.go

@@ -22,7 +22,6 @@ package tactics
 import (
 	"bytes"
 	"context"
-	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"net"
@@ -85,7 +84,7 @@ func TestTactics(t *testing.T) {
           },
           "Tactics" : {
             "Parameters" : {
-              "LimitTunnelProtocols" : %s
+              %s
             }
           }
         },
@@ -125,7 +124,9 @@ func TestTactics(t *testing.T) {
 	tacticsNetworkLatencyMultiplier := 2.0
 	tacticsConnectionWorkerPoolSize := 5
 	tacticsLimitTunnelProtocols := protocol.TunnelProtocols{"OSSH", "SSH"}
-	jsonTacticsLimitTunnelProtocols, _ := json.Marshal(tacticsLimitTunnelProtocols)
+	jsonTacticsLimitTunnelProtocols := `"LimitTunnelProtocols" : ["OSSH", "SSH"]`
+
+	expectedApplyCount := 3
 
 	listenerProtocol := "OSSH"
 	listenerProhibitedGeoIP := func(string) common.GeoIPData { return common.GeoIPData{Country: "R7"} }
@@ -304,7 +305,7 @@ func TestTactics(t *testing.T) {
 			t.Fatalf("Apply failed: %s", err)
 		}
 
-		if counts[0] != 3 {
+		if counts[0] != expectedApplyCount {
 			t.Fatalf("Unexpected apply count: %d", counts[0])
 		}
 
@@ -439,6 +440,19 @@ func TestTactics(t *testing.T) {
 
 	tacticsConnectionWorkerPoolSize = 6
 
+	// Omitting LimitTunnelProtocols entirely tests this bug fix: When a new
+	// tactics payload is obtained, all previous parameters should be cleared.
+	//
+	// In the bug, any previous parameters not in the new tactics were
+	// incorrectly retained. In this test case, LimitTunnelProtocols is
+	// omitted in the new tactics; if FetchTactics fails to clear the old
+	// LimitTunnelProtocols then the test will fail.
+
+	tacticsLimitTunnelProtocols = protocol.TunnelProtocols{}
+	jsonTacticsLimitTunnelProtocols = ``
+
+	expectedApplyCount = 2
+
 	tacticsConfig = fmt.Sprintf(
 		tacticsConfigTemplate,
 		encodedRequestPublicKey,