github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/gpg_fallback_test.go (about) 1 package libkb 2 3 import ( 4 "testing" 5 6 keybase1 "github.com/keybase/client/go/protocol/keybase1" 7 ) 8 9 type TestGenericKey struct { 10 GenericKey 11 } 12 13 func (k *TestGenericKey) SignToString(msg []byte) (sig string, id keybase1.SigIDBase, err error) { 14 sig = "TestSignature" 15 return 16 } 17 18 func InitTestKey(k *PGPKeyBundle) { 19 k.GPGFallbackKey = &TestGenericKey{k} 20 } 21 22 var gpgDummyKey = `-----BEGIN PGP PRIVATE KEY BLOCK----- 23 Version: GnuPG v2 24 25 lQEmBFbrFrABCACtotjyxawLQWE8p0OdrK+tE4bZLM3evuyqtL1MUk4NTR1+VRYL 26 LY1Ls9tFil15k+8kT54F+M+0km6LgZyIDTPQw0UtEZI4zNEFaXkFnNZaR0YIjApr 27 7YFBbYgSDcCzW/ChS10af0BxwGCRHJAVzgPrmfzFXKT98FNDxmN9e/lZpmsuu1iJ 28 mt9B13K/yYvFDraaXBlpDxNZM2WREEiTs93GCsAO9UHE/EpW1Lu4aRYJWuUuarsH 29 SujRtIy9CKdDFJeDI7MidSUk4a5yIOWHMIpkZbJWOjPeMXsZEBKHepKaOaqWahHH 30 92l8XxjyzFzOlZKBV+0zzkBPejglfdVMmGbRABEBAAH/AGUAR05VAhDSdgABJAEC 31 AAAGA4KXcwAAtCBKYWNvYiBILiBIYXZlbiA8amFjb2JAamhhdmVuLm1lPokBNwQT 32 AQgAIQUCVusWsAIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRAT2+L3inJJ 33 Yc9nCACZ+Wtoq4i06vW1j6rK6DYw54WNfQy2vPXEmD8iTpeipuNIX/Yq7sMtCn0x 34 bkZULzYuvEkUMQ/IpO5L25CvB5r7hAx73p/3xT0h5z2KtpLYNl9OHkonOojU6cq1 35 l1Taep/CkJusiFBBj35D7Qbd38OsI/KgOzjT1h/60HJ4D03QseYQFEjXse6Cuwbt 36 z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 M98xaPBdv9bID4/tTeFzdVdy1du5+Buc/ZMefDFt65fYt2++gaOj3+FK9Fps+tz2 53 bsbSlifLRoWf77ILxrdaAo0zah/Lez8/3gqbOIjBjqDFySwrU6MWCwZVmzAgfB0V 54 1iPHfZ8o7LomcnrG3DRQCznXyyey1Obd4ylhle0Ut8cVYUhTFOOCLVpeq8huFz6V 55 AAw7dktc1x6kj7dHmrRWmIyX/1f2slvZ/8wbIaSuIBUdrDTqhDP9h7iNP3+0FkW5 56 PomeoBljYlwrRUkAEQEAAf8AZQBHTlUCENJ2AAEkAQIAAAYDgpdzAACJAR8EGAEI 57 AAkFAlbrFrACGwwACgkQE9vi94pySWHm4wf/aA1miP1tn4DJ+0hyd8IOzSW0/j48 58 1ddMJsiAK/zV8rpduRzfvEjapiY39Uj4UKmRAHdn79ZSKVW91lhOjXzz0RknFvNO 59 h2uLG10e3LaNf36luJhd8LeNdrrAREPPU8ZqAgfVIMcMp05bBdpCfSIyWM462Kxp 60 vs+tlmFx2zyF4Yk8c6S8dJ4G4sah346FaEDbwtWvGT9twHYNaa0beK+RwbExsjZ4 61 C9jiHmNZtcINiyKseAVo0zxsjWib+B2G7PjPxFjapX5mz7W5ZTs/S5E/h8AbpikU 62 k8D1sZpooxcnL2NlRGWwYmOJWNq+qcmEJn+w6qAWgxTSggPEOEkIrkaUcA== 63 =jcas 64 -----END PGP PRIVATE KEY BLOCK----- 65 ` 66 67 var msg = []byte("test") 68 69 func TestSignWithTestKey(t *testing.T) { 70 k, _, err := ReadOneKeyFromString(gpgDummyKey) 71 if err != nil { 72 t.Fatal(err) 73 } 74 75 if _, _, err := k.SignToString(msg); err == nil { 76 t.Fatal("was able to sign with dummy skey") 77 } 78 79 // Set a fallback key to use when SimpleSign fails. 80 InitTestKey(k) 81 if _, _, err := k.SignToString(msg); err != nil { 82 t.Fatal(err) 83 } 84 }