MCPcopy
hub / github.com/smallstep/cli / TestGenerateKeyID

Function TestGenerateKeyID

token/token_test.go:186–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

184}
185
186func TestGenerateKeyID(t *testing.T) {
187 type args struct {
188 priv interface{}
189 }
190
191 rsaKey, err := pemutil.Read("testdata/openssl.rsa1024.pem")
192 if err != nil {
193 t.Fatal(err)
194 }
195
196 esKey, err := pemutil.Read("testdata/openssl.p256.pem")
197 if err != nil {
198 t.Fatal(err)
199 }
200
201 b, err := randutil.Salt(64)
202 if err != nil {
203 t.Fatal(err)
204 }
205 badKey := ed25519.PublicKey(b)
206
207 tests := []struct {
208 name string
209 args args
210 want string
211 wantErr bool
212 }{
213 {"ok rsa", args{rsaKey}, "ntSigdQY4tK8YfL7GB6c4dng8oHeF9NU2ItAIU8kGdg", false},
214 {"ok es", args{esKey}, "COu8GPmatXsngf8XdSj5J3aqQotmjs7QR1lll517DxM", false},
215 {"fail with unsupported", args{[]byte("the-key")}, "", true},
216 {"fail with bad key", args{badKey}, "", true},
217 }
218 for _, tt := range tests {
219 t.Run(tt.name, func(t *testing.T) {
220 got, err := GenerateKeyID(tt.args.priv)
221 if (err != nil) != tt.wantErr {
222 t.Errorf("GenerateKeyID() error = %v, wantErr %v", err, tt.wantErr)
223 return
224 }
225 if got != tt.want {
226 t.Errorf("GenerateKeyID() = %v, want %v", got, tt.want)
227 }
228 })
229 }
230}

Callers

nothing calls this directly

Calls 3

GenerateKeyIDFunction · 0.85
RunMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…