Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Added ScannerSurfaceSecretConfigurator to configure ScannerWebServiceOptions using surface secrets. - Integrated ISurfaceSecretProvider to fetch and apply secrets for artifact store configuration. - Enhanced logging for secret retrieval and application processes. feat: Implement ScannerStorageSurfaceSecretConfigurator for worker options - Introduced ScannerStorageSurfaceSecretConfigurator to configure ScannerStorageOptions with surface secrets. - Utilized ISurfaceSecretProvider to retrieve and apply secrets for object store settings. - Improved logging for secret handling and configuration. feat: Create SurfaceManifestPublisher for publishing surface manifests - Developed SurfaceManifestPublisher to handle the creation and storage of surface manifests. - Implemented methods for serializing manifest documents and storing payloads in the object store. - Added dual write functionality for mirror storage of manifests. feat: Add SurfaceManifestStageExecutor for processing scan stages - Created SurfaceManifestStageExecutor to execute the manifest publishing stage in scan jobs. - Integrated with SurfaceManifestPublisher to publish manifests based on collected payloads. - Enhanced logging for job processing and manifest storage. feat: Define SurfaceManifest models for manifest structure - Established SurfaceManifestDocument, SurfaceManifestSource, SurfaceManifestArtifact, and SurfaceManifestStorage records. - Implemented serialization attributes for JSON handling of manifest models. feat: Implement CasAccessSecret and SurfaceSecretParser for secret handling - Created CasAccessSecret record to represent surface access secrets. - Developed SurfaceSecretParser to parse and validate surface secrets from JSON payloads. test: Add unit tests for CasAccessSecretParser - Implemented tests for parsing CasAccessSecret from JSON payloads and metadata fallbacks. - Verified expected values and behavior for secret parsing logic. test: Add unit tests for ScannerSurfaceSecretConfigurator - Created tests for ScannerSurfaceSecretConfigurator to ensure correct application of surface secrets to web service options. - Validated artifact store settings after configuration. test: Add unit tests for ScannerStorageSurfaceSecretConfigurator - Implemented tests for ScannerStorageSurfaceSecretConfigurator to verify correct application of surface secrets to storage options. - Ensured accurate configuration of object store settings.
66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using StellaOps.Scanner.Surface.Secrets;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Scanner.Surface.Secrets.Tests;
|
|
|
|
public sealed class CasAccessSecretParserTests
|
|
{
|
|
[Fact]
|
|
public void ParseCasAccessSecret_WithRustFsPayload_ReturnsExpectedValues()
|
|
{
|
|
const string json = """
|
|
{
|
|
"driver": "rustfs",
|
|
"endpoint": "https://surface.test.local",
|
|
"region": "us-gov-west-1",
|
|
"bucket": "stellaops-surface",
|
|
"rootPrefix": "scanner",
|
|
"apiKey": "secret-api-key",
|
|
"apiKeyHeader": "X-Api-Key",
|
|
"allowInsecureTls": true,
|
|
"headers": {
|
|
"X-Surface-Tenant": "tenant-a"
|
|
}
|
|
}
|
|
""";
|
|
|
|
using var handle = SurfaceSecretHandle.FromBytes(Encoding.UTF8.GetBytes(json));
|
|
var secret = SurfaceSecretParser.ParseCasAccessSecret(handle);
|
|
|
|
Assert.Equal("rustfs", secret.Driver);
|
|
Assert.Equal("https://surface.test.local", secret.Endpoint);
|
|
Assert.Equal("us-gov-west-1", secret.Region);
|
|
Assert.Equal("stellaops-surface", secret.Bucket);
|
|
Assert.Equal("scanner", secret.RootPrefix);
|
|
Assert.Equal("secret-api-key", secret.ApiKey);
|
|
Assert.Equal("X-Api-Key", secret.ApiKeyHeader);
|
|
Assert.True(secret.AllowInsecureTls);
|
|
Assert.Single(secret.Headers);
|
|
Assert.Equal("tenant-a", secret.Headers["X-Surface-Tenant"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseCasAccessSecret_UsesMetadataFallback_WhenFieldsMissing()
|
|
{
|
|
const string json = @"{ ""driver"": ""s3"" }";
|
|
var metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["endpoint"] = "https://s3.test.local",
|
|
["accessKeyId"] = "AKIA123",
|
|
["secretAccessKey"] = "s3-secret",
|
|
["header:X-Custom"] = "value"
|
|
};
|
|
|
|
using var handle = SurfaceSecretHandle.FromBytes(Encoding.UTF8.GetBytes(json), metadata);
|
|
var secret = SurfaceSecretParser.ParseCasAccessSecret(handle);
|
|
|
|
Assert.Equal("s3", secret.Driver);
|
|
Assert.Equal("https://s3.test.local", secret.Endpoint);
|
|
Assert.Equal("AKIA123", secret.AccessKeyId);
|
|
Assert.Equal("s3-secret", secret.SecretAccessKey);
|
|
Assert.Equal("value", secret.Headers["X-Custom"]);
|
|
}
|
|
}
|