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

Add test cases for seeding SLOKs across multiple
schemes concurrently.

Rod Hynes 9 лет назад
Родитель
Сommit
cbb0ab4252
3 измененных файлов с 80 добавлено и 3 удалено
  1. 19 2
      psiphon/common/osl/osl_test.go
  2. 23 0
      psiphon/dataStore.go
  3. 38 1
      psiphon/server/server_test.go

+ 19 - 2
psiphon/common/osl/osl_test.go

@@ -40,7 +40,7 @@ func TestOSL(t *testing.T) {
 
       "Regions" : ["US", "CA"],
 
-      "PropagationChannelIDs" : ["2995DB0C968C59C4F23E87988D9C0D41", "E742C25A6D8BA8C17F37E725FA628569"],
+      "PropagationChannelIDs" : ["2995DB0C968C59C4F23E87988D9C0D41", "E742C25A6D8BA8C17F37E725FA628569", "B4A780E67695595FA486E9B900EA7335"],
 
       "MasterKey" : "wFuSbqU/pJ/35vRmoM8T9ys1PgDa8uzJps1Y+FNKa5U=",
 
@@ -100,7 +100,7 @@ func TestOSL(t *testing.T) {
 
       "Regions" : ["US", "CA"],
 
-      "PropagationChannelIDs" : ["36F1CF2DF1250BF0C7BA0629CE3DC657"],
+      "PropagationChannelIDs" : ["36F1CF2DF1250BF0C7BA0629CE3DC657", "B4A780E67695595FA486E9B900EA7335"],
 
       "MasterKey" : "fcyQy8JSxLXHt/Iom9Qj9wMnSjrsccTiiSPEsJicet4=",
 
@@ -296,6 +296,23 @@ func TestOSL(t *testing.T) {
 		}
 	})
 
+	t.Run("concurrent schemes", func(t *testing.T) {
+
+		rolloverToNextSLOKTime()
+
+		clientSeedState := config.NewClientSeedState("US", "B4A780E67695595FA486E9B900EA7335", nil)
+
+		clientSeedPortForward := clientSeedState.NewClientSeedPortForward(net.ParseIP("192.168.0.1"))
+
+		clientSeedPortForward.UpdateProgress(5, 5, 5)
+
+		clientSeedPortForward.UpdateProgress(5, 5, 5)
+
+		if len(clientSeedState.GetSeedPayload().SLOKs) != 5 {
+			t.Fatalf("expected 5 SLOKs, got %d", len(clientSeedState.GetSeedPayload().SLOKs))
+		}
+	})
+
 	signingPublicKey, signingPrivateKey, err := common.GenerateAuthenticatedDataPackageKeys()
 	if err != nil {
 		t.Fatalf("GenerateAuthenticatedDataPackageKeys failed: %s", err)

+ 23 - 0
psiphon/dataStore.go

@@ -1101,6 +1101,29 @@ func resetAllPersistentStatsToUnreported() error {
 	return nil
 }
 
+// CountSLOKs returns the total number of SLOK records.
+func CountSLOKs() int {
+	checkInitDataStore()
+
+	count := 0
+
+	err := singleton.db.View(func(tx *bolt.Tx) error {
+		bucket := tx.Bucket([]byte(slokBucket))
+		cursor := bucket.Cursor()
+		for key, _ := cursor.First(); key != nil; key, _ = cursor.Next() {
+			count++
+		}
+		return nil
+	})
+
+	if err != nil {
+		NoticeAlert("CountSLOKs failed: %s", err)
+		return 0
+	}
+
+	return count
+}
+
 // DeleteSLOKs deletes all SLOK records.
 func DeleteSLOKs() error {
 	checkInitDataStore()

+ 38 - 1
psiphon/server/server_test.go

@@ -414,6 +414,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 	if err != nil {
 		t.Fatalf("error initializing client datastore: %s", err)
 	}
+	psiphon.DeleteSLOKs()
 
 	controller, err := psiphon.NewController(clientConfig)
 	if err != nil {
@@ -544,8 +545,14 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 	// Test: await SLOK payload
 
 	if !runConfig.denyTrafficRules {
+
 		time.Sleep(1 * time.Second)
 		waitOnNotification(t, slokSeeded, timeoutSignal, "SLOK seeded timeout exceeded")
+
+		numSLOKs := psiphon.CountSLOKs()
+		if numSLOKs != expectedNumSLOKs {
+			t.Fatalf("unexpected number of SLOKs: %d", numSLOKs)
+		}
 	}
 }
 
@@ -871,6 +878,8 @@ func paveTrafficRulesFile(
 	}
 }
 
+var expectedNumSLOKs = 3
+
 func paveOSLConfigFile(t *testing.T, oslConfigFilename string) string {
 
 	oslConfigJSONFormat := `
@@ -911,6 +920,32 @@ func paveOSLConfigFile(t *testing.T, oslConfigFilename string) string {
               "Threshold": 2
             }
           ]
+        },
+        {
+          "Epoch" : "%s",
+          "Regions" : [],
+          "PropagationChannelIDs" : ["%s"],
+          "MasterKey" : "HDc/mvd7e+lKDJD0fMpJW66YJ/VW4iqDRjeclEsMnro=",
+          "SeedSpecs" : [
+            {
+              "ID" : "/M0vsT0IjzmI0MvTI9IYe8OVyeQGeaPZN2xGxfLw/UQ=",
+              "UpstreamSubnets" : ["0.0.0.0/0"],
+              "Targets" :
+              {
+                  "BytesRead" : 1,
+                  "BytesWritten" : 1,
+                  "PortForwardDurationNanoseconds" : 1
+              }
+            }
+          ],
+          "SeedSpecThreshold" : 1,
+          "SeedPeriodNanoseconds" : 10000000000,
+          "SeedPeriodKeySplits": [
+            {
+              "Total": 1,
+              "Threshold": 1
+            }
+          ]
         }
       ]
     }
@@ -923,7 +958,9 @@ func paveOSLConfigFile(t *testing.T, oslConfigFilename string) string {
 	epochStr := epoch.Format(time.RFC3339Nano)
 
 	oslConfigJSON := fmt.Sprintf(
-		oslConfigJSONFormat, epochStr, propagationChannelID)
+		oslConfigJSONFormat,
+		epochStr, propagationChannelID,
+		epochStr, propagationChannelID)
 
 	err := ioutil.WriteFile(oslConfigFilename, []byte(oslConfigJSON), 0600)
 	if err != nil {