public void FromTotpUrl_Sha512AndStepSizeFifteenDigitsEight() { var url = string.Format("otpauth://totp/user/?secret={0}&algorithm=Sha512&period=15&digits=8", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); var otp = KeyUrl.FromUrl(url); Assert.IsTrue(otp is Totp); var totp = (Totp)otp; CollectionAssert.AreEqual(OtpCalculationTests.RfcTestKey, totp.GetKey(), "Key's don't match"); Assert.AreEqual(8, totp.GetDigitLength(), "Digits don't match"); Assert.AreEqual(15, totp.GetTimeStep(), "Step size doesn't match"); Assert.AreEqual(OtpHashMode.Sha512, totp.GetHashMode(), "Hash mode doesn't match"); }
public void FromTotpUrl_Sha256() { var url = string.Format("otpauth://totp/user?secret={0}&algorithm=Sha256", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); var otp = KeyUrl.FromUrl(url); Assert.IsTrue(otp is Totp); var totp = (Totp)otp; CollectionAssert.AreEqual(OtpCalculationTests.RfcTestKey, totp.GetKey(), "Key's don't match"); Assert.AreEqual(6, totp.GetDigitLength(), "Digits don't match"); Assert.AreEqual(30, totp.GetTimeStep(), "Step size doesn't match"); Assert.AreEqual(OtpHashMode.Sha256, totp.GetHashMode(), "Hash mode doesn't match"); }
void SetupTotp() { if (this.CustomData != null && this.CustomData.Exists(PassXYZLib.PxDefs.PxCustomDataOtpUrl)) { var rawUrl = this.CustomData.Get(PassXYZLib.PxDefs.PxCustomDataOtpUrl); var otp = KeyUrl.FromUrl(rawUrl); if (otp is Totp totp) { var url = new Uri(rawUrl); m_TotpDescription = url.LocalPath.Substring(1); Totp = totp; Token = totp.ComputeTotp(); } } }
public void FromUrl_InvalidProtocol() { var url = string.Format("otp://totp/user?secret={0}", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("invalid scheme otp. Must be otpauth://"); }
public void FromUrl_InvalidType() { var url = string.Format("otpauth://sotp/user?secret={0}", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("rawUrl contains an invalid operation sotp. Must be hotp or totp"); }
public void FromHotpUrl_WithPeriod() { var url = string.Format("otpauth://Hotp/user?secret={0}&period=15", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid parameter in query string"); }
public void FromTotpUrl_NoQueryString() { var url = "otpauth://totp/user"; new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Must have a query string"); }
public void FromTotpUrl_NoSecret() { var url = "otpauth://totp/user?period=30"; new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("must contain secret"); }
public void FromTotpUrl_InvalidScheme() { var url = string.Format("otp://totp/user?secret={0}&algorithm=Sha512&period=15&digits=8", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("invalid scheme otp. Must be otpauth://"); }
public void FromTotpUrl_MalFormattedUrl_ExtraArgumentWithSlash() { var url = string.Format("otpauth://totp/user/extra/?secret={0}&algorithm=Sha512&period=15&digits=8", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("rawUrl is invalid"); }
public void FromTotpUrl_InvalidQueryString() { var url = string.Format("otpauth://totp/user?secret={0}&algorithm=Sha512&period=15&digits=8&blah=b", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid parameter in query string"); }
public void FromTotpUrl_NullUrl() { new Action(() => KeyUrl.FromUrl(null)).ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: rawUrl"); }
public void FromTotpUrl_DigitsInvalid() { var url = string.Format("otpauth://totp/user?secret={0}&digits=a", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid digits a, must be a number"); }
public void FromTotpUrl_ExplicitHashModeInvalid() { var url = string.Format("otpauth://totp/user?secret={0}&algorithm=Garbage", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid Algorithm Garbage"); }
public void FromTotpUrl_ZeroStep() { var url = string.Format("otpauth://totp/user?secret={0}&period=0", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey)); new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid Period 0, must be at least 1"); }