github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/pgp_purge_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package engine 5 6 import ( 7 "testing" 8 9 "github.com/keybase/client/go/libkb" 10 keybase1 "github.com/keybase/client/go/protocol/keybase1" 11 ) 12 13 // Test the export of the keys. 14 func TestPGPPurgeLksec(t *testing.T) { 15 tc := SetupEngineTest(t, "purge") 16 defer tc.Cleanup() 17 18 createFakeUserWithPGPSibkeyPaper(tc) 19 20 idUI := &FakeIdentifyUI{ 21 Proofs: make(map[string]string), 22 } 23 uis := libkb.UIs{ 24 SecretUI: &libkb.TestSecretUI{}, // empty on purpose...shouldn't be necessary 25 SaltpackUI: &fakeSaltpackUI{}, 26 IdentifyUI: idUI, 27 } 28 eng := NewPGPPurge(tc.G, keybase1.PGPPurgeArg{}) 29 m := NewMetaContextForTest(tc).WithUIs(uis) 30 if err := RunEngine2(m, eng); err != nil { 31 t.Fatal(err) 32 } 33 34 if len(eng.KeyFiles()) != 1 { 35 t.Fatalf("number of exported key files: %d, expected 1", len(eng.KeyFiles())) 36 } 37 } 38 39 // Test the removal of the keys. 40 func TestPGPPurgeRemove(t *testing.T) { 41 tc := SetupEngineTest(t, "purge") 42 defer tc.Cleanup() 43 44 u := createFakeUserWithPGPSibkey(tc) 45 46 idUI := &FakeIdentifyUI{ 47 Proofs: make(map[string]string), 48 } 49 uis := libkb.UIs{ 50 SecretUI: &libkb.TestSecretUI{}, // empty on purpose...shouldn't be necessary 51 SaltpackUI: &fakeSaltpackUI{}, 52 IdentifyUI: idUI, 53 } 54 eng := NewPGPPurge(tc.G, keybase1.PGPPurgeArg{DoPurge: true}) 55 m := NewMetaContextForTest(tc).WithUIs(uis) 56 if err := RunEngine2(m, eng); err != nil { 57 t.Fatal(err) 58 } 59 60 if len(eng.KeyFiles()) != 1 { 61 t.Fatalf("number of exported key files: %d, expected 1", len(eng.KeyFiles())) 62 } 63 64 kr := libkb.NewSKBKeyringFile(tc.G, libkb.NewNormalizedUsername(u.Username)) 65 if err := kr.LoadAndIndex(m.Ctx()); err != nil { 66 t.Fatal(err) 67 } 68 if kr.HasPGPKeys() { 69 t.Fatal("after purge, keyring has pgp keys") 70 } 71 72 // redo, should purge 0 files 73 74 eng = NewPGPPurge(tc.G, keybase1.PGPPurgeArg{DoPurge: true}) 75 if err := RunEngine2(m, eng); err != nil { 76 t.Fatal(err) 77 } 78 79 if len(eng.KeyFiles()) != 0 { 80 t.Fatalf("number of exported key files: %d, expected 0", len(eng.KeyFiles())) 81 } 82 83 } 84 85 // Create a user with a synced PGP key. PGPPurge shouldn't touch it. 86 func TestPGPPurgeSync(t *testing.T) { 87 tc := SetupEngineTest(t, "purge") 88 u1 := createFakeUserWithPGPOnly(t, tc) 89 Logout(tc) 90 tc.Cleanup() 91 92 tc = SetupEngineTest(t, "purge") 93 defer tc.Cleanup() 94 95 uis := libkb.UIs{ 96 ProvisionUI: newTestProvisionUIPassphrase(), 97 LoginUI: &libkb.TestLoginUI{Username: u1.Username}, 98 LogUI: tc.G.UI.GetLogUI(), 99 SecretUI: u1.NewSecretUI(), 100 GPGUI: &gpgtestui{}, 101 } 102 leng := NewLogin(tc.G, keybase1.DeviceTypeV2_DESKTOP, "", keybase1.ClientType_CLI) 103 m := NewMetaContextForTest(tc).WithUIs(uis) 104 if err := RunEngine2(m, leng); err != nil { 105 t.Fatal(err) 106 } 107 108 // user has device keys + synced 3sec pgp key 109 110 idUI := &FakeIdentifyUI{ 111 Proofs: make(map[string]string), 112 } 113 uis = libkb.UIs{ 114 SecretUI: &libkb.TestSecretUI{}, // empty on purpose...shouldn't be necessary 115 SaltpackUI: &fakeSaltpackUI{}, 116 IdentifyUI: idUI, 117 } 118 eng := NewPGPPurge(tc.G, keybase1.PGPPurgeArg{}) 119 m = NewMetaContextForTest(tc).WithUIs(uis) 120 if err := RunEngine2(m, eng); err != nil { 121 t.Fatal(err) 122 } 123 124 if len(eng.KeyFiles()) != 0 { 125 t.Fatalf("number of exported key files: %d, expected 0", len(eng.KeyFiles())) 126 } 127 }