package qr import "testing" func TestParseOtpAuth_TOTP(t *testing.T) { uri := "otpauth://totp/Example:alice@example.com?" + "secret=JBSWY3DPEHPK3PXP&issuer=Example&algorithm=SHA1&digits=6&period=30" got, err := ParseOtpAuth(uri) if err != nil { t.Fatalf("ParseOtpAuth: %v", err) } if got.Type != "totp" { t.Errorf("Type = %q, want totp", got.Type) } if got.SecretBase32 != "JBSWY3DPEHPK3PXP" { t.Errorf("SecretBase32 = %q", got.SecretBase32) } if got.Issuer != "Example" { t.Errorf("Issuer = %q", got.Issuer) } if got.Label != "Example:alice@example.com" { t.Errorf("Label = %q", got.Label) } if got.Digits != 6 || got.Period != 30 { t.Errorf("Digits/Period = %d/%d", got.Digits, got.Period) } } func TestParseOtpAuth_HOTP(t *testing.T) { uri := "otpauth://hotp/Account?secret=AAAAAA&counter=42" got, err := ParseOtpAuth(uri) if err != nil { t.Fatalf("ParseOtpAuth: %v", err) } if got.Type != "hotp" || got.Counter != 42 { t.Errorf("got %+v", got) } } func TestParseOtpAuth_RejectsNonOtp(t *testing.T) { if _, err := ParseOtpAuth("https://example.com/?secret=x"); err != ErrNotOtpAuth { t.Errorf("want ErrNotOtpAuth, got %v", err) } } func TestParseOtpAuth_MissingSecret(t *testing.T) { if _, err := ParseOtpAuth("otpauth://totp/foo"); err == nil { t.Errorf("expected error for missing secret") } }