48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Types.Deployment;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests;
|
|
|
|
public class DeploymentFetchTokenTests
|
|
{
|
|
[Fact]
|
|
public void Generate_ReturnsUrlSafeTokenOfAdequateLength()
|
|
{
|
|
var token = DeploymentFetchToken.Generate();
|
|
|
|
Assert.True(token.Length >= 32, $"Expected length >= 32 but got {token.Length}");
|
|
Assert.DoesNotContain('+', token);
|
|
Assert.DoesNotContain('/', token);
|
|
}
|
|
|
|
[Fact]
|
|
public void Generate_TwoCallsReturnDifferentValues()
|
|
{
|
|
var a = DeploymentFetchToken.Generate();
|
|
var b = DeploymentFetchToken.Generate();
|
|
|
|
Assert.NotEqual(a, b);
|
|
}
|
|
|
|
[Fact]
|
|
public void ConstantTimeEquals_SameToken_ReturnsTrue()
|
|
{
|
|
var token = DeploymentFetchToken.Generate();
|
|
|
|
Assert.True(DeploymentFetchToken.ConstantTimeEquals(token, token));
|
|
}
|
|
|
|
[Fact]
|
|
public void ConstantTimeEquals_TokenWithSuffix_ReturnsFalse()
|
|
{
|
|
var token = DeploymentFetchToken.Generate();
|
|
|
|
Assert.False(DeploymentFetchToken.ConstantTimeEquals(token, token + "x"));
|
|
}
|
|
|
|
[Fact]
|
|
public void ConstantTimeEquals_BothEmpty_ReturnsTrue()
|
|
{
|
|
Assert.True(DeploymentFetchToken.ConstantTimeEquals("", ""));
|
|
}
|
|
}
|