Prechádzať zdrojové kódy

lib/protocol: Set invalid flag on encrypted file infos (fixes #7466) (#7467)

Simon Frei 4 rokov pred
rodič
commit
f80ee472c2

+ 1 - 0
lib/protocol/encryption.go

@@ -314,6 +314,7 @@ func encryptFileInfo(fi FileInfo, folderKey *[keySize]byte) FileInfo {
 		Permissions:  0644,
 		ModifiedS:    1234567890, // Sat Feb 14 00:31:30 CET 2009
 		Deleted:      fi.Deleted,
+		RawInvalid:   fi.IsInvalid(),
 		Version:      version,
 		Sequence:     fi.Sequence,
 		RawBlockSize: fi.RawBlockSize + blockOverhead,

+ 22 - 3
lib/protocol/encryption_test.go

@@ -113,9 +113,8 @@ func TestEnDecryptBytes(t *testing.T) {
 	}
 }
 
-func TestEnDecryptFileInfo(t *testing.T) {
-	var key [32]byte
-	fi := FileInfo{
+func encFileInfo() FileInfo {
+	return FileInfo{
 		Name:        "hello",
 		Size:        45,
 		Permissions: 0755,
@@ -133,6 +132,11 @@ func TestEnDecryptFileInfo(t *testing.T) {
 			},
 		},
 	}
+}
+
+func TestEnDecryptFileInfo(t *testing.T) {
+	var key [32]byte
+	fi := encFileInfo()
 
 	enc := encryptFileInfo(fi, &key)
 	if bytes.Equal(enc.Blocks[0].Hash, enc.Blocks[1].Hash) {
@@ -155,6 +159,21 @@ func TestEnDecryptFileInfo(t *testing.T) {
 	}
 }
 
+func TestEncryptedFileInfoConsistency(t *testing.T) {
+	var key [32]byte
+	files := []FileInfo{
+		encFileInfo(),
+		encFileInfo(),
+	}
+	files[1].SetIgnored()
+	for i, f := range files {
+		enc := encryptFileInfo(f, &key)
+		if err := checkFileInfoConsistency(enc); err != nil {
+			t.Errorf("%v: %v", i, err)
+		}
+	}
+}
+
 func TestIsEncryptedParent(t *testing.T) {
 	comp := rand.String(maxPathComponent)
 	cases := []struct {