commit 6d0bab6b9ba60c2e942e088b6dcf2b470dd5f033
parent c292a487e65b7dab59192ab36efb7efdc448b7e3
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 2 Oct 2022 16:20:18 -0400
format totp token tests
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/internal/inputs/env_test.go b/internal/inputs/env_test.go
@@ -7,6 +7,27 @@ import (
"github.com/enckse/lockbox/internal/inputs"
)
+func TestFormatTOTP(t *testing.T) {
+ otp := inputs.FormatTOTP("otpauth://abc")
+ if otp != "otpauth://abc" {
+ t.Errorf("invalid totp token: %s", otp)
+ }
+ otp = inputs.FormatTOTP("abc")
+ if otp != "otpauth://totp/lbissuer:lbaccount?algorithm=SHA1&digits=6&issuer=lbissuer&period=30&secret=abc" {
+ t.Errorf("invalid totp token: %s", otp)
+ }
+ os.Setenv("LOCKBOX_TOTP_FORMAT", "test/%s")
+ otp = inputs.FormatTOTP("abc")
+ if otp != "test/abc" {
+ t.Errorf("invalid totp token: %s", otp)
+ }
+ os.Setenv("LOCKBOX_TOTP_FORMAT", "")
+ otp = inputs.FormatTOTP("abc")
+ if otp != "otpauth://totp/lbissuer:lbaccount?algorithm=SHA1&digits=6&issuer=lbissuer&period=30&secret=abc" {
+ t.Errorf("invalid totp token: %s", otp)
+ }
+}
+
func TestColorSetting(t *testing.T) {
os.Setenv("LOCKBOX_NOCOLOR", "yes")
c, err := inputs.IsNoColorEnabled()