test/test_uri.rb in otp-0.0.8 vs test/test_uri.rb in otp-0.0.9
- old
+ new
@@ -1,9 +1,25 @@
-require "test/unit"
-require "otp"
+require_relative "helper"
class TestURI < Test::Unit::TestCase
+ def test_parse
+ uri = "otpauth://totp/account@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
+ otp = OTP::URI.parse(uri)
+ assert_equal("account@example.com", otp.accountname)
+ assert_equal(nil, otp.issuer)
+
+ uri = "otpauth://totp/My%20Company:%20%20account@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
+ otp = OTP::URI.parse(uri)
+ assert_equal("account@example.com", otp.accountname)
+ assert_equal("My Company", otp.issuer)
+
+ uri = "otpauth://totp/My%20Company:%20%20account@example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
+ otp = OTP::URI.parse(uri)
+ assert_equal("account@example.com", otp.accountname)
+ assert_equal("My Company", otp.issuer)
+ end
+
def test_totp
secret = OTP::Base32.encode("12345678901234567890")
totp = OTP::TOTP.new
totp.secret = secret
totp.algorithm = "SHA256"
@@ -43,7 +59,12 @@
assert_equal(8, otp.digits)
assert_equal(1234, otp.count)
assert_equal("account@example.com", otp.accountname)
assert_equal("My Company", otp.issuer)
assert_equal(otp.password, hotp.password)
+ end
+
+ def test_parse_invalid
+ assert_raise(RuntimeError){ OTP::URI.parse("http://www.netlab.jp") }
+ assert_raise(RuntimeError){ OTP::URI.parse("otpauth://foo") }
end
end