Initial commit: scadaproj umbrella — sister-project index, auth component normalization (design + GAPS), and the built ZB.MOM.WW.Auth shared library (0.1.0, flattened in).

This commit is contained in:
dohertj2
2026-06-01 03:59:23 -04:00
commit 37e23cf9f2
73 changed files with 6836 additions and 0 deletions
@@ -0,0 +1,68 @@
using ZB.MOM.WW.Auth.ApiKeys;
namespace ZB.MOM.WW.Auth.ApiKeys.Tests;
public class ApiKeySecretGeneratorTests
{
[Fact]
public void NewSecret_ReturnsNonEmpty()
{
var secret = ApiKeySecretGenerator.NewSecret();
Assert.NotEmpty(secret);
}
[Fact]
public void NewSecret_TwoCallsDiffer()
{
var first = ApiKeySecretGenerator.NewSecret();
var second = ApiKeySecretGenerator.NewSecret();
Assert.NotEqual(first, second);
}
[Fact]
public void NewSecret_DecodesToThirtyTwoBytes()
{
var secret = ApiKeySecretGenerator.NewSecret();
// Restore URL-safe base64 to standard before decoding
string standard = secret.Replace('-', '+').Replace('_', '/');
// Add padding if needed
int pad = standard.Length % 4;
if (pad == 2) standard += "==";
else if (pad == 3) standard += "=";
byte[] bytes = Convert.FromBase64String(standard);
Assert.Equal(32, bytes.Length);
}
[Fact]
public void NewSecret_IsUrlSafe_NoPlus()
{
// Run many iterations to make collisions with '+' unlikely to be missed
for (int i = 0; i < 200; i++)
{
Assert.DoesNotContain('+', ApiKeySecretGenerator.NewSecret());
}
}
[Fact]
public void NewSecret_IsUrlSafe_NoSlash()
{
for (int i = 0; i < 200; i++)
{
Assert.DoesNotContain('/', ApiKeySecretGenerator.NewSecret());
}
}
[Fact]
public void NewSecret_IsUrlSafe_NoPaddingEquals()
{
for (int i = 0; i < 200; i++)
{
Assert.DoesNotContain('=', ApiKeySecretGenerator.NewSecret());
}
}
}