github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/test/example_test.go (about) 1 // Copyright 2016 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package test 6 7 import "testing" 8 9 // 1) alice writes 10 // 2) bob reads 11 // 3) alice reads 12 // 4) eve reads & tries to write(w/o permission), 13 func TestWriteReadWriteFail(t *testing.T) { 14 test(t, 15 skip("dokan", "Does not work with Dokan."), 16 users("alice", "bob", "eve"), inPrivateTlf("alice,bob#eve"), 17 as(alice, 18 mkfile("foo.txt", "hello world"), 19 ), 20 as(bob, 21 read("foo.txt", "hello world"), 22 ), 23 as(alice, 24 read("foo.txt", "hello world"), 25 ), 26 as(eve, 27 read("foo.txt", "hello world"), 28 expectError(rm("foo.txt"), "eve does not have write access to directory /keybase/private/alice,bob#eve"), 29 ), 30 ) 31 } 32 33 // 1) alice creates a directory, creates a file, writes more to the file w/o sync 34 // 2) bob writes to the same file and syncs 35 // 3) alice syncs 36 func TestConflict(t *testing.T) { 37 test(t, 38 users("alice", "bob"), 39 as(alice, 40 mkfile("a/b", "hello"), 41 ), 42 as(bob, 43 disableUpdates(), 44 ), 45 as(alice, 46 write("a/b", "world"), 47 ), 48 as(bob, noSync(), 49 write("a/b", "uh oh"), 50 reenableUpdates(), 51 lsdir("a/", m{"b$": "FILE", "b.conflict.*": "FILE"}), 52 read("a/b", "world"), 53 ), 54 as(alice, 55 lsdir("a/", m{"b$": "FILE", "b.conflict.*": "FILE"}), 56 read("a/b", "world"), 57 ), 58 ) 59 } 60 61 // create a file, create a dir, link(to the file, rename a file, remove it, remove its parent directory), 62 // and create an executable file. 63 func TestLinkLsRenameRmRmdirSetex(t *testing.T) { 64 test(t, 65 skip("dokan", "Does not work with Dokan."), 66 users("alice", "bob"), 67 as(alice, 68 mkfile("a/b", "hello world"), 69 mkdir("a/e"), 70 link("a/e/b.link", "../b"), 71 link("a/f", "e"), 72 lsdir("a/", m{"b": "FILE", "e": "DIR", "f": "SYM"}), 73 expectError(lsdir("a/", m{"b": "DIR", "e": "DIR", "f": "SYM"}), "b of type DIR not found"), 74 // lsdir(looks for files in the directory that match regexs from left to right in this hash.), 75 // if it finds a match for the regex and the expected type it considers the file expected. 76 // if it doesn't find a match it throws an error. also, if any files remain that weren't 77 // matched an error is also thrown. 78 lsdir("a/", m{".": "FILE", "[a-z]{1}": "DIR", "[a-f]{1}": "SYM"}), 79 expectError(lsdir("a/", m{"b": "FILE", "e": "DIR"}), "unexpected f of type SYM found in a/"), 80 lsdir("a/e", m{"b.link": "SYM"}), 81 lsdir("a/f", m{"b.link": "SYM"}), 82 ), 83 as(bob, 84 read("a/e/b.link", "hello world"), 85 rename("a/b", "c/d"), 86 expectError(read("a/e/b.link", "hello world"), "b doesn't exist"), 87 rm("a/e/b.link"), 88 exists("c/d"), 89 ), 90 as(alice, 91 notExists("a/b"), 92 notExists("a/e/b.link"), 93 expectError(read("a/b", "hello world"), "b doesn't exist"), 94 read("c/d", "hello world"), 95 rm("c/d"), 96 notExists("c/d"), 97 rmdir("c"), 98 ), 99 as(bob, 100 notExists("c"), 101 mkfile("a/foo.exe", "bits and bytes etc"), 102 setex("a/foo.exe", true), 103 ), 104 as(alice, 105 rmdir("a/e"), 106 rm("a/f"), 107 lsdir("a", m{"foo.exe": "EXEC"}), 108 rm("a/foo.exe"), 109 ), 110 ) 111 }