Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Manifest Integrity / Audit SHA256SUMS Files (push) Has been cancelled
Manifest Integrity / Validate Schema Integrity (push) Has been cancelled
Manifest Integrity / Validate Contract Documents (push) Has been cancelled
Manifest Integrity / Validate Pack Fixtures (push) Has been cancelled
Manifest Integrity / Verify Merkle Roots (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
- Introduced `NativeTestBase` class for ELF, PE, and Mach-O binary parsing helpers and assertions. - Created `TestCryptoFactory` for SM2 cryptographic provider setup and key generation. - Implemented `Sm2SigningTests` to validate signing functionality with environment gate checks. - Developed console export service and store with comprehensive unit tests for export status management.
227 lines
6.1 KiB
C#
227 lines
6.1 KiB
C#
using StellaOps.Scanner.Analyzers.Lang.Bun.Internal;
|
|
|
|
namespace StellaOps.Scanner.Analyzers.Lang.Bun.Tests.Parsers;
|
|
|
|
public sealed class BunConfigHelperTests : IDisposable
|
|
{
|
|
private readonly string _tempDir;
|
|
|
|
public BunConfigHelperTests()
|
|
{
|
|
_tempDir = Path.Combine(Path.GetTempPath(), $"bun-config-test-{Guid.NewGuid():N}");
|
|
Directory.CreateDirectory(_tempDir);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Directory.Exists(_tempDir))
|
|
{
|
|
Directory.Delete(_tempDir, recursive: true);
|
|
}
|
|
}
|
|
|
|
#region ParseConfig Tests
|
|
|
|
[Fact]
|
|
public void ParseConfig_MissingFile_ReturnsEmpty()
|
|
{
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Null(result.DefaultRegistry);
|
|
Assert.Empty(result.ScopeRegistries);
|
|
Assert.False(result.HasCustomRegistry);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseConfig_DefaultRegistry_ReturnsUrl()
|
|
{
|
|
var bunfig = """
|
|
[install]
|
|
registry = "https://npm.company.com/"
|
|
""";
|
|
File.WriteAllText(Path.Combine(_tempDir, "bunfig.toml"), bunfig);
|
|
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Equal("https://npm.company.com/", result.DefaultRegistry);
|
|
Assert.True(result.HasCustomRegistry);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseConfig_ScopedRegistries_ReturnsMappings()
|
|
{
|
|
var bunfig = """
|
|
[install.scopes]
|
|
"@company" = "https://npm.company.com/"
|
|
"@internal" = "https://internal.registry.com/"
|
|
""";
|
|
File.WriteAllText(Path.Combine(_tempDir, "bunfig.toml"), bunfig);
|
|
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Equal(2, result.ScopeRegistries.Count);
|
|
Assert.Equal("https://npm.company.com/", result.ScopeRegistries["@company"]);
|
|
Assert.Equal("https://internal.registry.com/", result.ScopeRegistries["@internal"]);
|
|
Assert.True(result.HasCustomRegistry);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseConfig_InlineTableFormat_ExtractsUrl()
|
|
{
|
|
var bunfig = """
|
|
[install.scopes]
|
|
"@company" = { url = "https://npm.company.com/" }
|
|
""";
|
|
File.WriteAllText(Path.Combine(_tempDir, "bunfig.toml"), bunfig);
|
|
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Single(result.ScopeRegistries);
|
|
Assert.Equal("https://npm.company.com/", result.ScopeRegistries["@company"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseConfig_Comments_IgnoresComments()
|
|
{
|
|
var bunfig = """
|
|
# This is a comment
|
|
[install]
|
|
# registry for npm packages
|
|
registry = "https://npm.company.com/"
|
|
""";
|
|
File.WriteAllText(Path.Combine(_tempDir, "bunfig.toml"), bunfig);
|
|
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Equal("https://npm.company.com/", result.DefaultRegistry);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseConfig_EmptyFile_ReturnsEmpty()
|
|
{
|
|
File.WriteAllText(Path.Combine(_tempDir, "bunfig.toml"), "");
|
|
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Null(result.DefaultRegistry);
|
|
Assert.Empty(result.ScopeRegistries);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseConfig_BothDefaultAndScoped_ReturnsBoth()
|
|
{
|
|
var bunfig = """
|
|
[install]
|
|
registry = "https://default.registry.com/"
|
|
|
|
[install.scopes]
|
|
"@company" = "https://npm.company.com/"
|
|
""";
|
|
File.WriteAllText(Path.Combine(_tempDir, "bunfig.toml"), bunfig);
|
|
|
|
var result = BunConfigHelper.ParseConfig(_tempDir);
|
|
|
|
Assert.Equal("https://default.registry.com/", result.DefaultRegistry);
|
|
Assert.Single(result.ScopeRegistries);
|
|
Assert.Equal("https://npm.company.com/", result.ScopeRegistries["@company"]);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StripQuotes Tests
|
|
|
|
[Fact]
|
|
public void StripQuotes_DoubleQuotes_RemovesQuotes()
|
|
{
|
|
var result = BunConfigHelper.StripQuotes("\"hello world\"");
|
|
|
|
Assert.Equal("hello world", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripQuotes_SingleQuotes_RemovesQuotes()
|
|
{
|
|
var result = BunConfigHelper.StripQuotes("'hello world'");
|
|
|
|
Assert.Equal("hello world", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripQuotes_NoQuotes_ReturnsUnchanged()
|
|
{
|
|
var result = BunConfigHelper.StripQuotes("hello world");
|
|
|
|
Assert.Equal("hello world", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripQuotes_MismatchedQuotes_ReturnsUnchanged()
|
|
{
|
|
var result = BunConfigHelper.StripQuotes("\"hello world'");
|
|
|
|
Assert.Equal("\"hello world'", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripQuotes_EmptyString_ReturnsEmpty()
|
|
{
|
|
var result = BunConfigHelper.StripQuotes("");
|
|
|
|
Assert.Equal("", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void StripQuotes_SingleCharacter_ReturnsUnchanged()
|
|
{
|
|
var result = BunConfigHelper.StripQuotes("a");
|
|
|
|
Assert.Equal("a", result);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ExtractRegistryUrl Tests
|
|
|
|
[Fact]
|
|
public void ExtractRegistryUrl_DirectUrl_ReturnsUrl()
|
|
{
|
|
var result = BunConfigHelper.ExtractRegistryUrl("https://npm.company.com/");
|
|
|
|
Assert.Equal("https://npm.company.com/", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExtractRegistryUrl_InlineTable_ExtractsUrl()
|
|
{
|
|
var result = BunConfigHelper.ExtractRegistryUrl("{ url = \"https://npm.company.com/\" }");
|
|
|
|
Assert.Equal("https://npm.company.com/", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExtractRegistryUrl_InlineTableSingleQuotes_ExtractsUrl()
|
|
{
|
|
var result = BunConfigHelper.ExtractRegistryUrl("{ url = 'https://npm.company.com/' }");
|
|
|
|
Assert.Equal("https://npm.company.com/", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExtractRegistryUrl_InvalidFormat_ReturnsNull()
|
|
{
|
|
var result = BunConfigHelper.ExtractRegistryUrl("not-a-url");
|
|
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExtractRegistryUrl_HttpUrl_ReturnsUrl()
|
|
{
|
|
var result = BunConfigHelper.ExtractRegistryUrl("http://internal.registry.local/");
|
|
|
|
Assert.Equal("http://internal.registry.local/", result);
|
|
}
|
|
|
|
#endregion
|
|
}
|