Jelajahi Sumber

Fix: proper ETag format with quotes
- In Go 1.8, http.ServeContent supports "If-Match" and
the mock remote server list host implemented with
http.ServeContent rejects the malformed ETags. This
causes TestObfuscatedRemoteServerLists to fail as the
interrupted download is always reset instead of
resuming.
- The sourceETag optimization in downloadRemoteServerListFile
never occurs as the malformed sourceETag will never match
lastETag.

Rod Hynes 9 tahun lalu
induk
melakukan
bd348635e9
2 mengubah file dengan 6 tambahan dan 6 penghapusan
  1. 4 4
      psiphon/remoteServerList.go
  2. 2 2
      psiphon/remoteServerList_test.go

+ 4 - 4
psiphon/remoteServerList.go

@@ -219,11 +219,11 @@ func FetchObfuscatedServerLists(
 		hexID := hex.EncodeToString(oslID)
 
 		// Note: the MD5 checksum step assumes the remote server list host's ETag uses MD5
-		// with a hex encoding. If this is not the case, the remoteETag should be left blank.
-		remoteETag := ""
+		// with a hex encoding. If this is not the case, the sourceETag should be left blank.
+		sourceETag := ""
 		md5sum, err := oslRegistry.GetOSLMD5Sum(oslID)
 		if err == nil {
-			remoteETag = hex.EncodeToString(md5sum)
+			sourceETag = fmt.Sprintf("\"%s\"", hex.EncodeToString(md5sum))
 		}
 
 		// TODO: store ETags in OSL registry to enable skipping requests entirely
@@ -235,7 +235,7 @@ func FetchObfuscatedServerLists(
 			downloadURL,
 			canonicalURL,
 			skipVerify,
-			remoteETag,
+			sourceETag,
 			downloadFilename)
 		if err != nil {
 			failed = true

+ 2 - 2
psiphon/remoteServerList_test.go

@@ -215,7 +215,7 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
 				serveMux.HandleFunc("/"+file.Name, func(w http.ResponseWriter, req *http.Request) {
 					md5sum := md5.Sum(file.Contents)
 					w.Header().Add("Content-Type", "application/octet-stream")
-					w.Header().Add("ETag", hex.EncodeToString(md5sum[:]))
+					w.Header().Add("ETag", fmt.Sprintf("\"%s\"", hex.EncodeToString(md5sum[:])))
 					http.ServeContent(w, req, file.Name, startTime, bytes.NewReader(file.Contents))
 				})
 			}
@@ -382,7 +382,7 @@ func TestObfuscatedRemoteServerLists(t *testing.T) {
 		u.Path = path.Join(u.Path, paveFile.Name)
 		etag, _ := GetUrlETag(u.String())
 		md5sum := md5.Sum(paveFile.Contents)
-		if etag != hex.EncodeToString(md5sum[:]) {
+		if etag != fmt.Sprintf("\"%s\"", hex.EncodeToString(md5sum[:])) {
 			t.Fatalf("unexpected ETag for %s", u)
 		}
 	}