(ts *testscript.TestScript, neg bool, args []string)
| 277 | } |
| 278 | |
| 279 | func 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 | |
| 312 | func TestCryptoHelp(t *testing.T) { |
| 313 | testscript.Run(t, testscript.Params{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…