github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/systests/device_test.go (about) 1 package systests 2 3 import ( 4 "fmt" 5 "github.com/keybase/client/go/client" 6 "github.com/keybase/client/go/libkb" 7 keybase1 "github.com/keybase/client/go/protocol/keybase1" 8 context "golang.org/x/net/context" 9 "strings" 10 "testing" 11 ) 12 13 func TestRevokeDevices(t *testing.T) { 14 set := newTestDeviceSet(t, nil) 15 defer set.cleanup() 16 17 // Set up first device 18 dev1 := set.newDevice("primary").start(4) 19 20 // Signup the new user for this device 21 set.signupUser(dev1) 22 23 // Provision a new device 24 dev2 := set.provisionNewDevice("secondary", 1) 25 26 alice := tlfUser{ 27 keybase1.UID("295a7eea607af32040647123732bc819"), 28 []keybase1.KID{}, 29 } 30 mike := tlfUser{ 31 keybase1.UID("ff261e3b26543a24ba6c0693820ead19"), 32 []keybase1.KID{keybase1.KID("012073f26b5996912393f7d2961ca90968e4e83d6140e9771ba890ff8ba6ea97777e0a")}, 33 } 34 35 // Add a new TLF (private/tester#alice) that's fully keyed 36 dev1.keyNewTLF(set.uid, 37 []tlfUser{{set.uid, []keybase1.KID{dev1.KID(), dev2.KID(), set.backupKeys[0].KID}}}, 38 []tlfUser{alice}, 39 ) 40 41 // Add a new TLF (private/tester#mike) that isn't keyed for the current 42 // device 43 tlf2 := dev1.keyNewTLF(set.uid, 44 []tlfUser{{set.uid, []keybase1.KID{dev2.KID(), set.backupKeys[0].KID}}}, 45 []tlfUser{mike}, 46 ) 47 48 // Call the server and process the API call. Make sure we get a list of 49 // "endangered" TLFs that includes private/tester#mike 50 cli := keybase1.RekeyClient{Cli: dev1.cli} 51 res, err := cli.GetRevokeWarning(context.TODO(), keybase1.GetRevokeWarningArg{ 52 ActingDevice: dev1.deviceID, 53 TargetDevice: dev2.deviceID, 54 }) 55 56 if err != nil { 57 t.Fatalf("Bad answer from RPC: %s", err) 58 } 59 60 if n := len(res.EndangeredTLFs); n != 1 { 61 t.Fatalf("Expected 1 endangered TLF: got %d", n) 62 } 63 64 if id := res.EndangeredTLFs[0].Id; id != tlf2.id { 65 t.Fatalf("Got wrong TLF ID; wanted %s; but got %s", tlf2.id, id) 66 } 67 68 expectedName := fmt.Sprintf("private/%s#%s", set.username, "t_mike") 69 if nm := res.EndangeredTLFs[0].Name; nm != expectedName { 70 t.Fatalf("Got wrong TLF name; wanted %q; but got %q", expectedName, nm) 71 } 72 73 run := func(accept bool) { 74 g := dev1.popClone().G 75 ui := newTestUI(g) 76 g.SetUI(ui) 77 78 var prompt string 79 ui.outputDescHook = func(d libkb.OutputDescriptor, s string) (err error) { 80 if d == client.OutputDescriptorEndageredTLFs { 81 prompt = s 82 } 83 return nil 84 } 85 86 ui.promptYesNoHook = func(libkb.PromptDescriptor, string, libkb.PromptDefault) (bool, error) { 87 return accept, nil 88 } 89 90 runner := client.NewCmdDeviceRemoveRunner(g) 91 runner.SetIDOrName(dev2.deviceName) 92 err = runner.Run() 93 94 if (err == nil) != accept { 95 t.Fatalf("With accept=%v, got unexpected error: %v", accept, err) 96 } 97 98 if !strings.Contains(prompt, expectedName) { 99 t.Fatalf("didn't find expected TLF name %q", expectedName) 100 } 101 } 102 run(false) 103 run(true) 104 }