Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.CLI.Tests/CredentialResolutionTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only:
- add summaries to ~10k test methods, fixtures, fakes and helpers
  (+ <param> on theories, <returns> on async Task methods,
  <inheritdoc/> on interface implementations the checker can resolve)
- strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N,
  #NN, Component-0NN) from comments, keeping the explanatory text;
  reword false positives in comments only
- real docs on fakes implementing BCL/library interfaces
  (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime)
- reword the last 5 src/ false positives (CWE-1236, failures-1,
  year-0001, M365)

Only non-comment edits: four one-line nested classes split across lines
so members can carry docs. Build 0 errors / 0 warnings.
2026-10-07 15:05:49 -04:00

75 lines
2.5 KiB
C#

using ZB.MOM.WW.ScadaBridge.CLI;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
/// <summary>
/// Regression tests for environment-based credential supply — credentials could only be supplied via the
/// <c>--password</c> command-line option, which leaks into process listings and
/// shell history. A <c>SCADABRIDGE_PASSWORD</c> / <c>SCADABRIDGE_USERNAME</c> environment
/// fallback gives CI/CD a safer alternative.
/// </summary>
[Collection("Environment")]
public class CredentialResolutionTests
{
/// <summary>Verifies that the password is loaded from the environment variable.</summary>
[Fact]
public void Load_Password_FromEnvironment()
{
var orig = Environment.GetEnvironmentVariable("SCADABRIDGE_PASSWORD");
try
{
Environment.SetEnvironmentVariable("SCADABRIDGE_PASSWORD", "s3cret");
var config = CliConfig.Load();
Assert.Equal("s3cret", config.Password);
}
finally
{
Environment.SetEnvironmentVariable("SCADABRIDGE_PASSWORD", orig);
}
}
/// <summary>Verifies that the username is loaded from the environment variable.</summary>
[Fact]
public void Load_Username_FromEnvironment()
{
var orig = Environment.GetEnvironmentVariable("SCADABRIDGE_USERNAME");
try
{
Environment.SetEnvironmentVariable("SCADABRIDGE_USERNAME", "ci-user");
var config = CliConfig.Load();
Assert.Equal("ci-user", config.Username);
}
finally
{
Environment.SetEnvironmentVariable("SCADABRIDGE_USERNAME", orig);
}
}
/// <summary>Verifies that loading with no credential environment variables leaves the credentials null.</summary>
[Fact]
public void Load_NoCredentialEnvVars_LeavesCredentialsNull()
{
var origUser = Environment.GetEnvironmentVariable("SCADABRIDGE_USERNAME");
var origPass = Environment.GetEnvironmentVariable("SCADABRIDGE_PASSWORD");
try
{
Environment.SetEnvironmentVariable("SCADABRIDGE_USERNAME", null);
Environment.SetEnvironmentVariable("SCADABRIDGE_PASSWORD", null);
var config = CliConfig.Load();
Assert.Null(config.Username);
Assert.Null(config.Password);
}
finally
{
Environment.SetEnvironmentVariable("SCADABRIDGE_USERNAME", origUser);
Environment.SetEnvironmentVariable("SCADABRIDGE_PASSWORD", origPass);
}
}
}