github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/pgp_keygen_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 "github.com/keybase/client/go/libkb" 8 keybase1 "github.com/keybase/client/go/protocol/keybase1" 9 "testing" 10 ) 11 12 func TestPGPKeyGenPush(t *testing.T) { 13 tc := SetupEngineTest(t, "pgpkeygen") 14 defer tc.Cleanup() 15 16 u := CreateAndSignupFakeUser(tc, "pgp") 17 pgpUI := &TestPgpUI{ShouldPush: true} 18 uis := libkb.UIs{ 19 LogUI: tc.G.UI.GetLogUI(), 20 SecretUI: u.NewSecretUI(), 21 PgpUI: pgpUI, 22 } 23 arg := keybase1.PGPKeyGenDefaultArg{ 24 CreateUids: keybase1.PGPCreateUids{ 25 UseDefault: true, 26 Ids: []keybase1.PGPIdentity{ 27 {Username: u.Username, Email: u.Email}, 28 }, 29 }, 30 } 31 eng := NewPGPKeyGen(tc.G, arg) 32 eng.genArg = &libkb.PGPGenArg{ 33 PrimaryBits: 768, 34 SubkeyBits: 768, 35 } 36 m := NewMetaContextForTest(tc).WithUIs(uis) 37 if err := RunEngine2(m, eng); err != nil { 38 t.Fatal(err) 39 } 40 41 xarg := keybase1.PGPExportArg{ 42 Options: keybase1.PGPQuery{ 43 Secret: true, 44 Query: pgpUI.Generated.Key.Fingerprint, 45 }, 46 } 47 xe := NewPGPKeyExportEngine(tc.G, xarg) 48 if err := RunEngine2(m, xe); err != nil { 49 t.Fatal(err) 50 } 51 if len(xe.Results()) != 1 { 52 t.Errorf("result keys: %d, expected 1", len(xe.Results())) 53 } 54 } 55 56 func TestPGPKeyGenNoPush(t *testing.T) { 57 tc := SetupEngineTest(t, "pgpkeygen") 58 defer tc.Cleanup() 59 60 u := CreateAndSignupFakeUser(tc, "pgp") 61 pgpUI := &TestPgpUI{ShouldPush: false} 62 uis := libkb.UIs{ 63 LogUI: tc.G.UI.GetLogUI(), 64 SecretUI: u.NewSecretUI(), 65 PgpUI: pgpUI, 66 } 67 arg := keybase1.PGPKeyGenDefaultArg{ 68 CreateUids: keybase1.PGPCreateUids{ 69 UseDefault: true, 70 Ids: []keybase1.PGPIdentity{ 71 {Username: u.Username, Email: u.Email}, 72 }, 73 }, 74 } 75 eng := NewPGPKeyGen(tc.G, arg) 76 eng.genArg = &libkb.PGPGenArg{ 77 PrimaryBits: 768, 78 SubkeyBits: 768, 79 } 80 m := NewMetaContextForTest(tc).WithUIs(uis) 81 if err := RunEngine2(m, eng); err != nil { 82 t.Fatal(err) 83 } 84 85 xarg := keybase1.PGPExportArg{ 86 Options: keybase1.PGPQuery{ 87 Secret: true, 88 Query: pgpUI.Generated.Key.Fingerprint, 89 }, 90 } 91 xe := NewPGPKeyExportEngine(tc.G, xarg) 92 if err := RunEngine2(m, xe); err != nil { 93 t.Fatal(err) 94 } 95 if len(xe.Results()) != 1 { 96 t.Errorf("result keys: %d, expected 1", len(xe.Results())) 97 } 98 }