public void ShouldGenerateOTPForAGivenUserId() { var userId = Guid.NewGuid().ToString(); var generatedOtp = "321382113asjd72131"; var generateOtpRequest = new GenerateOTPRequest { UserId = userId }; var movingFactor = 87302; _movingFactorAlgorithm.Expect(algorithm => algorithm.GetMovingFactor()).Return(movingFactor); _otpAlgorithm.Expect( algorithm => algorithm.GenerateOTP(userId, _otpConfiguration.PrivateKey, movingFactor, _otpConfiguration.NumberOfDigitsInOTP)).Return(generatedOtp); var generateOTPResponse = _otpService.GenerateOtp(generateOtpRequest); Assert.That(generateOTPResponse, Is.Not.Null); Assert.That(generateOTPResponse.UserId, Is.EqualTo(userId)); Assert.That(generateOTPResponse.OTP, Is.EqualTo(generatedOtp)); }
public void ShouldNotValidateOutsideExpiryLimit() { var otpConfiguration = new OTPConfiguration { OTPExpiryInSeconds = 2, NumberOfDigitsInOTP = 6, PrivateKey = "as9121jd623ms23h232k3" }; _otpService = new OTPService(new HmacBasedOTPAlgorithm(), new ExpiryBasedMovingFactorAlgorithm(otpConfiguration), new ErrorFactory(), otpConfiguration); string userId = "2j32jk432m23482394jkddsd"; var generateOTPResponse = _otpService.GenerateOtp(new GenerateOTPRequest { UserId = userId }); Assert.That(generateOTPResponse, Is.Not.Null); Assert.That(generateOTPResponse.UserId, Is.EqualTo(userId)); Assert.That(generateOTPResponse.OTP, Is.Not.Empty); Thread.Sleep(5000); var validateOTPResponse = _otpService.ValidateOtp(new ValidateOTPRequest { OTP = generateOTPResponse.OTP, UserId = userId }); Assert.That(validateOTPResponse, Is.Not.Null); Assert.That(validateOTPResponse.UserId, Is.EqualTo(userId)); Assert.That(validateOTPResponse.Success, Is.False); }
public GenerateModule(IOTPService otpService) { Get["/Generate"] = parameters => { return(View["Generate"]); }; Post["/Generate"] = parameters => { var generateOTPRequest = this.Bind <GenerateOTPRequest>(); var generateOTPResponse = otpService.GenerateOtp(generateOTPRequest); return(View["Generate", generateOTPResponse]); }; }
public GenerateModule(IOTPService otpService) { Get["/Generate"] = parameters => {return View["Generate"]; }; Post["/Generate"] = parameters => { var generateOTPRequest = this.Bind<GenerateOTPRequest>(); var generateOTPResponse = otpService.GenerateOtp(generateOTPRequest); return View["Generate", generateOTPResponse]; }; }
public void GenerateAndValidateOTP(string userId) { var generateOTPResponse = _otpService.GenerateOtp(new GenerateOTPRequest { UserId = userId }); Assert.That(generateOTPResponse, Is.Not.Null); Assert.That(generateOTPResponse.UserId, Is.EqualTo(userId)); Assert.That(generateOTPResponse.OTP, Is.Not.Empty); Assert.That(IsValidNumberFormat(generateOTPResponse.OTP), Is.True); var validateOTPResponse = _otpService.ValidateOtp(new ValidateOTPRequest { OTP = generateOTPResponse.OTP, UserId = userId }); Assert.That(validateOTPResponse, Is.Not.Null); Assert.That(validateOTPResponse.UserId, Is.EqualTo(userId)); Assert.That(validateOTPResponse.Success, Is.True); }