|
|
@@ -1334,3 +1334,67 @@ func TestRequestIndexSenderClusterConfigBeforeStart(t *testing.T) {
|
|
|
case <-indexChan:
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestRequestReceiveEncryptedLocalNoSend(t *testing.T) {
|
|
|
+ w, fcfg := tmpDefaultWrapper()
|
|
|
+ tfs := fcfg.Filesystem()
|
|
|
+ fcfg.Type = config.FolderTypeReceiveEncrypted
|
|
|
+ waiter, err := w.SetFolder(fcfg)
|
|
|
+ must(t, err)
|
|
|
+ waiter.Wait()
|
|
|
+
|
|
|
+ encToken := protocol.PasswordToken(fcfg.ID, "pw")
|
|
|
+ must(t, tfs.Mkdir(config.DefaultMarkerName, 0777))
|
|
|
+ must(t, writeEncryptionToken(encToken, fcfg))
|
|
|
+
|
|
|
+ m := setupModel(w)
|
|
|
+ defer cleanupModelAndRemoveDir(m, tfs.URI())
|
|
|
+
|
|
|
+ fc := &fakeConnection{id: device1, model: m}
|
|
|
+ m.AddConnection(fc, protocol.Hello{})
|
|
|
+ m.ClusterConfig(device1, protocol.ClusterConfig{
|
|
|
+ Folders: []protocol.Folder{
|
|
|
+ {
|
|
|
+ ID: "default",
|
|
|
+ Devices: []protocol.Device{
|
|
|
+ {
|
|
|
+ ID: myID,
|
|
|
+ EncryptionPasswordToken: encToken,
|
|
|
+ },
|
|
|
+ {ID: device1},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ indexChan := make(chan []protocol.FileInfo, 1)
|
|
|
+ done := make(chan struct{})
|
|
|
+ defer close(done)
|
|
|
+ fc.mut.Lock()
|
|
|
+ fc.indexFn = func(_ context.Context, _ string, fs []protocol.FileInfo) {
|
|
|
+ select {
|
|
|
+ case indexChan <- fs:
|
|
|
+ case <-done:
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fc.mut.Unlock()
|
|
|
+
|
|
|
+ files := genFiles(2)
|
|
|
+ files[1].LocalFlags = protocol.FlagLocalReceiveOnly
|
|
|
+ m.fmut.RLock()
|
|
|
+ fset := m.folderFiles[fcfg.ID]
|
|
|
+ m.fmut.RUnlock()
|
|
|
+ fset.Update(protocol.LocalDeviceID, files)
|
|
|
+
|
|
|
+ select {
|
|
|
+ case fs := <-indexChan:
|
|
|
+ if len(fs) != 1 {
|
|
|
+ t.Error("Expected index with one file, got", fs)
|
|
|
+ }
|
|
|
+ if got := fs[0].Name; got != files[0].Name {
|
|
|
+ t.Errorf("Expected file %v, got %v", got, files[0].Name)
|
|
|
+ }
|
|
|
+ case <-time.After(5 * time.Second):
|
|
|
+ t.Fatal("timed out before receiving index")
|
|
|
+ }
|
|
|
+}
|