예제 #1
0
    public void Too_Late_Returns_False()
    {
        // Arrange
        var key      = Rnd.ByteF.Get(8);
        var interval = TotpF.GetCurrentInterval(30) - 1;
        var code     = TotpF.GenerateCode(key, interval, 6);

        // Act
        var result = TotpF.VerifyCode(key, code, TotpSettings.Default with {
            IntervalTolerance = false
        });
예제 #2
0
    public void Incorrect_Key_Returns_False()
    {
        // Arrange
        var key  = Rnd.ByteF.Get(8);
        var code = TotpF.GenerateCode(key, TotpSettings.Default);

        // Act
        var result = TotpF.VerifyCode(Rnd.ByteF.Get(8), code, TotpSettings.Default);

        // Assert
        Assert.False(result);
    }
예제 #3
0
    public void Uses_Correct_Period()
    {
        // Arrange
        var key      = Rnd.ByteF.Get(8);
        var period   = Rnd.Int;
        var settings = TotpSettings.Default with {
            PeriodSeconds = period
        };
        var interval = TotpF.GetCurrentInterval(period);
        var expected = TotpF.GenerateCode(key, interval, TotpSettings.Default.CodeLength);

        // Act
        var result = TotpF.GenerateCode(key, settings);

        // Assert
        Assert.Equal(expected, result);
    }
예제 #4
0
    public void Uses_Correct_Code_Length(int length)
    {
        // Arrange
        var key      = Rnd.ByteF.Get(8);
        var settings = TotpSettings.Default with {
            CodeLength = length
        };
        var interval = TotpF.GetCurrentInterval(TotpSettings.Default.PeriodSeconds);
        var expected = TotpF.GenerateCode(key, interval, length);

        // Act
        var result = TotpF.GenerateCode(key, settings);

        // Assert
        Assert.Equal(expected, result);
    }
}