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

Function checkOTP

integration/crypto_test.go:279–310  ·  view source on GitHub ↗
(ts *testscript.TestScript, neg bool, args []string)

Source from the content-addressed store, hash-verified

277}
278
279func checkOTP(ts *testscript.TestScript, neg bool, args []string) {
280 out := strings.TrimSpace(ts.ReadFile(args[0]))
281
282 length, err := strconv.Atoi(args[1])
283 ts.Check(err)
284
285 if out == "" {
286 ts.Fatalf("expected OTP not be empty")
287 }
288
289 if length != -1 {
290 if len(out) != length {
291 ts.Fatalf("expected OTP to be %d characters long; got %d", length, len(out))
292 }
293 }
294
295 if strings.HasPrefix(out, "otpauth://") {
296 key, err := otp.NewKeyFromURL(out)
297 ts.Check(err)
298
299 switch {
300 case key.Type() != "totp":
301 ts.Fatalf("expected OTP to be type totp; got %s", key.Type())
302 case key.Issuer() != "example.com":
303 ts.Fatalf("expected issuer to be example.com; got %s", key.Issuer())
304 case key.AccountName() != "foo@example.com":
305 ts.Fatalf("expected account name to be foo@example.com; got %s", key.AccountName())
306 case len(key.Secret()) != 32:
307 ts.Fatalf("expected secret to be 32 bytes; got %d", len(key.Secret()))
308 }
309 }
310}
311
312func TestCryptoHelp(t *testing.T) {
313 testscript.Run(t, testscript.Params{

Callers

nothing calls this directly

Calls 1

TypeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…