Restructure solution layout by module

This commit is contained in:
master
2025-10-28 15:10:40 +02:00
parent 95daa159c4
commit d870da18ce
4103 changed files with 192899 additions and 187024 deletions

View File

@@ -0,0 +1,118 @@
[
{
"analyzerId": "golang",
"componentKey": "purl::pkg:golang/example.com/app@v1.2.3",
"purl": "pkg:golang/example.com/app@v1.2.3",
"name": "example.com/app",
"version": "v1.2.3",
"type": "golang",
"usedByEntrypoint": false,
"metadata": {
"binaryPath": "app",
"build.GOARCH": "amd64",
"build.GOOS": "linux",
"build.vcs": "git",
"build.vcs.modified": "false",
"build.vcs.revision": "1234567890abcdef1234567890abcdef12345678",
"build.vcs.time": "2025-09-14T12:34:56Z",
"go.version": "go1.22.5",
"modulePath": "example.com/app",
"modulePath.main": "example.com/app",
"moduleSum": "h1:mainchecksum",
"moduleVersion": "v1.2.3"
},
"evidence": [
{
"kind": "metadata",
"source": "go.buildinfo.setting",
"locator": "GOARCH",
"value": "amd64"
},
{
"kind": "metadata",
"source": "go.buildinfo.setting",
"locator": "GOOS",
"value": "linux"
},
{
"kind": "metadata",
"source": "go.buildinfo.setting",
"locator": "vcs.modified",
"value": "false"
},
{
"kind": "metadata",
"source": "go.buildinfo.setting",
"locator": "vcs.revision",
"value": "1234567890abcdef1234567890abcdef12345678"
},
{
"kind": "metadata",
"source": "go.buildinfo.setting",
"locator": "vcs.time",
"value": "2025-09-14T12:34:56Z"
},
{
"kind": "metadata",
"source": "go.buildinfo.setting",
"locator": "vcs",
"value": "git"
},
{
"kind": "metadata",
"source": "go.buildinfo",
"locator": "module:example.com/app",
"value": "v1.2.3",
"sha256": "h1:mainchecksum"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs.modified",
"value": "false"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs.revision",
"value": "1234567890abcdef1234567890abcdef12345678"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs.time",
"value": "2025-09-14T12:34:56Z"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs",
"value": "git"
}
]
},
{
"analyzerId": "golang",
"componentKey": "purl::pkg:golang/example.com/lib@v1.0.0",
"purl": "pkg:golang/example.com/lib@v1.0.0",
"name": "example.com/lib",
"version": "v1.0.0",
"type": "golang",
"usedByEntrypoint": false,
"metadata": {
"binaryPath": "app",
"modulePath": "example.com/lib",
"moduleSum": "h1:depchecksum",
"moduleVersion": "v1.0.0"
},
"evidence": [
{
"kind": "metadata",
"source": "go.buildinfo",
"locator": "module:example.com/lib",
"value": "v1.0.0",
"sha256": "h1:depchecksum"
}
]
}
]

View File

@@ -0,0 +1,80 @@
[
{
"analyzerId": "golang",
"componentKey": "purl::pkg:golang/example.com/app@v0.0.0",
"purl": "pkg:golang/example.com/app@v0.0.0",
"name": "example.com/app",
"version": "v0.0.0",
"type": "golang",
"usedByEntrypoint": false,
"metadata": {
"binaryPath": "app",
"build.vcs": "git",
"build.vcs.modified": "true",
"build.vcs.revision": "abcdef0123456789abcdef0123456789abcdef01",
"build.vcs.time": "2025-01-02T03:04:05Z",
"go.version": "go1.20.3",
"modulePath": "example.com/app",
"modulePath.main": "example.com/app",
"moduleSum": "h1:dwarfchecksum",
"moduleVersion": "v0.0.0"
},
"evidence": [
{
"kind": "metadata",
"source": "go.buildinfo",
"locator": "module:example.com/app",
"value": "v0.0.0",
"sha256": "h1:dwarfchecksum"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs.modified",
"value": "true"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs.revision",
"value": "abcdef0123456789abcdef0123456789abcdef01"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs.time",
"value": "2025-01-02T03:04:05Z"
},
{
"kind": "metadata",
"source": "go.dwarf",
"locator": "vcs",
"value": "git"
}
]
},
{
"analyzerId": "golang",
"componentKey": "purl::pkg:golang/example.com/lib@v0.1.0",
"purl": "pkg:golang/example.com/lib@v0.1.0",
"name": "example.com/lib",
"version": "v0.1.0",
"type": "golang",
"usedByEntrypoint": false,
"metadata": {
"binaryPath": "app",
"modulePath": "example.com/lib",
"moduleSum": "h1:libchecksum",
"moduleVersion": "v0.1.0"
},
"evidence": [
{
"kind": "metadata",
"source": "go.buildinfo",
"locator": "module:example.com/lib",
"value": "v0.1.0",
"sha256": "h1:libchecksum"
}
]
}
]

View File

@@ -0,0 +1,5 @@
MZfakebinaryheader
Go build ID: "random-go-build-id"
....gopclntab....
runtime.buildVersion=go1.22.8
padding0000000000000000000000000000000000000000000000000000000000000000

View File

@@ -0,0 +1,30 @@
[
{
"analyzerId": "golang",
"componentKey": "golang::bin::sha256:7125d65230b913faa744a33acd884899c81a1dbc6d88cbf251a74b19621cde99",
"name": "app",
"type": "bin",
"usedByEntrypoint": false,
"metadata": {
"binary.sha256": "7125d65230b913faa744a33acd884899c81a1dbc6d88cbf251a74b19621cde99",
"binaryPath": "app",
"go.version.hint": "go1.22.8",
"languageHint": "golang",
"provenance": "binary"
},
"evidence": [
{
"kind": "file",
"source": "binary",
"locator": "app",
"sha256": "7125d65230b913faa744a33acd884899c81a1dbc6d88cbf251a74b19621cde99"
},
{
"kind": "metadata",
"source": "go.heuristic",
"locator": "classification",
"value": "build-id"
}
]
}
]

View File

@@ -0,0 +1,134 @@
using System;
using System.Diagnostics.Metrics;
using System.IO;
using System.Linq;
using StellaOps.Scanner.Analyzers.Lang.Go;
using StellaOps.Scanner.Analyzers.Lang.Tests.Harness;
using StellaOps.Scanner.Analyzers.Lang.Tests.TestUtilities;
namespace StellaOps.Scanner.Analyzers.Lang.Go.Tests;
public sealed class GoLanguageAnalyzerTests
{
[Fact]
public async Task BuildInfoFixtureProducesDeterministicOutputAsync()
{
var cancellationToken = TestContext.Current.CancellationToken;
var fixturePath = TestPaths.ResolveFixture("lang", "go", "basic");
var goldenPath = Path.Combine(fixturePath, "expected.json");
var analyzers = new ILanguageAnalyzer[]
{
new GoLanguageAnalyzer(),
};
await LanguageAnalyzerTestHarness.AssertDeterministicAsync(
fixturePath,
goldenPath,
analyzers,
cancellationToken);
}
[Fact]
public async Task DwarfOnlyFixtureFallsBackToMetadataAsync()
{
var cancellationToken = TestContext.Current.CancellationToken;
var fixturePath = TestPaths.ResolveFixture("lang", "go", "dwarf-only");
var goldenPath = Path.Combine(fixturePath, "expected.json");
var analyzers = new ILanguageAnalyzer[]
{
new GoLanguageAnalyzer(),
};
await LanguageAnalyzerTestHarness.AssertDeterministicAsync(
fixturePath,
goldenPath,
analyzers,
cancellationToken);
}
[Fact]
public async Task StrippedBinaryFallsBackToHeuristicBinHashAsync()
{
var cancellationToken = TestContext.Current.CancellationToken;
var fixturePath = TestPaths.ResolveFixture("lang", "go", "stripped");
var goldenPath = Path.Combine(fixturePath, "expected.json");
var analyzers = new ILanguageAnalyzer[]
{
new GoLanguageAnalyzer(),
};
await LanguageAnalyzerTestHarness.AssertDeterministicAsync(
fixturePath,
goldenPath,
analyzers,
cancellationToken);
}
[Fact]
public async Task ParallelRunsRemainDeterministicAsync()
{
var cancellationToken = TestContext.Current.CancellationToken;
var fixturePath = TestPaths.ResolveFixture("lang", "go", "basic");
var goldenPath = Path.Combine(fixturePath, "expected.json");
var analyzers = new ILanguageAnalyzer[]
{
new GoLanguageAnalyzer(),
};
var tasks = Enumerable
.Range(0, Environment.ProcessorCount)
.Select(_ => LanguageAnalyzerTestHarness.AssertDeterministicAsync(
fixturePath,
goldenPath,
analyzers,
cancellationToken));
await Task.WhenAll(tasks);
}
[Fact]
public async Task HeuristicMetricCounterIncrementsAsync()
{
var cancellationToken = TestContext.Current.CancellationToken;
var fixturePath = TestPaths.ResolveFixture("lang", "go", "stripped");
var analyzers = new ILanguageAnalyzer[]
{
new GoLanguageAnalyzer(),
};
var total = 0L;
using var listener = new MeterListener
{
InstrumentPublished = (instrument, meterListener) =>
{
if (instrument.Meter.Name == "StellaOps.Scanner.Analyzers.Lang.Go"
&& instrument.Name == "scanner_analyzer_golang_heuristic_total")
{
meterListener.EnableMeasurementEvents(instrument);
}
}
};
listener.SetMeasurementEventCallback<long>((_, measurement, _, _) =>
{
Interlocked.Add(ref total, measurement);
});
listener.Start();
await LanguageAnalyzerTestHarness.RunToJsonAsync(
fixturePath,
analyzers,
cancellationToken: cancellationToken).ConfigureAwait(false);
listener.Dispose();
Assert.Equal(1, Interlocked.Read(ref total));
}
}

View File

@@ -0,0 +1,46 @@
<?xml version='1.0' encoding='utf-8'?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Remove="Microsoft.NET.Test.Sdk" />
<PackageReference Remove="xunit" />
<PackageReference Remove="xunit.runner.visualstudio" />
<PackageReference Remove="Microsoft.AspNetCore.Mvc.Testing" />
<PackageReference Remove="Mongo2Go" />
<PackageReference Remove="coverlet.collector" />
<PackageReference Remove="Microsoft.Extensions.TimeProvider.Testing" />
<ProjectReference Remove="..\StellaOps.Concelier.Testing\StellaOps.Concelier.Testing.csproj" />
<Compile Remove="$(MSBuildThisFileDirectory)..\StellaOps.Concelier.Tests.Shared\AssemblyInfo.cs" />
<Compile Remove="$(MSBuildThisFileDirectory)..\StellaOps.Concelier.Tests.Shared\MongoFixtureCollection.cs" />
<Using Remove="StellaOps.Concelier.Testing" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit.v3" Version="3.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StellaOps.Scanner.Analyzers.Lang.Tests\StellaOps.Scanner.Analyzers.Lang.Tests.csproj" />
<ProjectReference Include="../../__Libraries/StellaOps.Scanner.Analyzers.Lang/StellaOps.Scanner.Analyzers.Lang.csproj" />
<ProjectReference Include="../../__Libraries/StellaOps.Scanner.Analyzers.Lang.Go/StellaOps.Scanner.Analyzers.Lang.Go.csproj" />
<ProjectReference Include="../../__Libraries/StellaOps.Scanner.Core/StellaOps.Scanner.Core.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="Fixtures\**\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>