Skip to content

Commit 8d92906

Browse files
Merge pull request #1185 from Checkmarx/other/elchanan/oss-realtime-location-structure
Convert OssPackage to use Locations array instead of individual line fields (AST-99444)
2 parents c4be2e5 + 095c502 commit 8d92906

File tree

6 files changed

+134
-25
lines changed

6 files changed

+134
-25
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Checkmarx/containers-resolver v1.0.11
77
github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63
88
github.com/Checkmarx/gen-ai-wrapper v1.0.2
9-
github.com/Checkmarx/manifest-parser v0.0.7
9+
github.com/Checkmarx/manifest-parser v0.0.8
1010
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf
1111
github.com/MakeNowJust/heredoc v1.0.0
1212
github.com/bouk/monkey v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63 h1:SCuTcE
7575
github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63/go.mod h1:MI6lfLerXU+5eTV/EPTDavgnV3owz3GPT4g/msZBWPo=
7676
github.com/Checkmarx/gen-ai-wrapper v1.0.2 h1:T6X40+4hYnwfDsvkjWs9VIcE6s1O+8DUu0+sDdCY3GI=
7777
github.com/Checkmarx/gen-ai-wrapper v1.0.2/go.mod h1:xwRLefezwNNnRGu1EjGS6wNiR9FVV/eP9D+oXwLViVM=
78-
github.com/Checkmarx/manifest-parser v0.0.7 h1:lfbDS8tLzQoe8Zwt0HwKmtHWd3NTXHFg/niJFJhUYhE=
79-
github.com/Checkmarx/manifest-parser v0.0.7/go.mod h1:s11sV8akqWX+H0MwFK3XBF8H6JohAjoQe8ClvdDFziQ=
78+
github.com/Checkmarx/manifest-parser v0.0.8 h1:rbmPp1X7UE3LeEhZxkjcOqAzMpwzgnWz4wjNWtiku3o=
79+
github.com/Checkmarx/manifest-parser v0.0.8/go.mod h1:hh5FX5FdDieU8CKQEkged4hfOaSylpJzub8PRFXa4kA=
8080
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf h1:lKiogedU3WzWBc/xI6Xj1BhX2Gp1QBJj8C+czY7CcaE=
8181
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf/go.mod h1:mtAHOm1mHGh7MVu6JdYUyitANsLcHNLUTBIh9pTERNI=
8282
github.com/CycloneDX/cyclonedx-go v0.9.2 h1:688QHn2X/5nRezKe2ueIVCt+NRqf7fl3AVQk+vaFcIo=
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
5+
<DebugType>pdbonly</DebugType>
6+
<Prefer32Bit>false</Prefer32Bit>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="CxExtension\CxInitialPanel.xaml.cs">
10+
<DependentUpon>CxInitialPanel.xaml</DependentUpon>
11+
</Compile>
12+
<Compile Include="CxExtension\CxWindowControl.xaml.cs">
13+
<DependentUpon>CxWindowControl.xaml</DependentUpon>
14+
</Compile>
15+
<Compile Include="CxExtension\CxWindowPackage.cs" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<Content Include="log4net.config">
19+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
20+
<IncludeInVSIX>true</IncludeInVSIX>
21+
</Content>
22+
<None Include="source.extension.vsixmanifest">
23+
<SubType>Designer</SubType>
24+
</None>
25+
</ItemGroup>
26+
<ItemGroup>
27+
<Reference Include="Microsoft.CSharp" />
28+
<Reference Include="WindowsFormsIntegration" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.507" />
32+
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" />
33+
<PackageReference Include="Microsoft.TeamFoundationServer.Client">
34+
<Version>19.225.1</Version>
35+
</PackageReference>
36+
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.32112.339" />
37+
<PackageReference Include="System.Json" Version="4.7.1" />
38+
</ItemGroup>
39+
<ItemGroup>
40+
<EmbeddedResource Include="CxPreferences\CxPreferencesUI.resx">
41+
<DependentUpon>CxPreferencesUI.cs</DependentUpon>
42+
</EmbeddedResource>
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Page Include="CxExtension\CxInitialPanel.xaml">
46+
<Generator>MSBuild:Compile</Generator>
47+
<SubType>Designer</SubType>
48+
</Page>
49+
<Page Include="CxExtension\CxWindowControl.xaml">
50+
<SubType>Designer</SubType>
51+
</Page>
52+
</ItemGroup>
53+
<ItemGroup />
54+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
55+
</Project>

internal/services/realtimeengine/ossrealtime/config.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package ossrealtime
22

3+
import "github.com/checkmarx/ast-cli/internal/services/realtimeengine"
4+
35
// OssPackage represents a package's details for OSS scanning.
46
type OssPackage struct {
5-
PackageManager string `json:"PackageManager"`
6-
PackageName string `json:"PackageName"`
7-
PackageVersion string `json:"PackageVersion"`
8-
FilePath string `json:"FilePath"`
9-
LineStart int `json:"LineStart"`
10-
LineEnd int `json:"LineEnd"`
11-
StartIndex int `json:"StartIndex"`
12-
EndIndex int `json:"EndIndex"`
13-
Status string `json:"Status"`
14-
Vulnerabilities []Vulnerability `json:"Vulnerabilities"`
7+
PackageManager string `json:"PackageManager"`
8+
PackageName string `json:"PackageName"`
9+
PackageVersion string `json:"PackageVersion"`
10+
FilePath string `json:"FilePath"`
11+
Locations []realtimeengine.Location `json:"Locations"`
12+
Status string `json:"Status"`
13+
Vulnerabilities []Vulnerability `json:"Vulnerabilities"`
1514
}
1615

1716
// OssPackageResults holds the results of an OSS scan.

internal/services/realtimeengine/ossrealtime/oss-realtime.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ import (
88
"github.com/Checkmarx/manifest-parser/pkg/parser/models"
99
errorconstants "github.com/checkmarx/ast-cli/internal/constants/errors"
1010
"github.com/checkmarx/ast-cli/internal/logger"
11+
"github.com/checkmarx/ast-cli/internal/services/realtimeengine"
1112
"github.com/checkmarx/ast-cli/internal/services/realtimeengine/ossrealtime/osscache"
1213
"github.com/checkmarx/ast-cli/internal/wrappers"
1314
"github.com/pkg/errors"
1415
)
1516

17+
// convertLocations converts models.Location to realtimeengine.Location
18+
func convertLocations(locations []models.Location) []realtimeengine.Location {
19+
var result []realtimeengine.Location
20+
for _, loc := range locations {
21+
result = append(result, realtimeengine.Location{
22+
Line: loc.Line,
23+
StartIndex: loc.StartIndex,
24+
EndIndex: loc.EndIndex,
25+
})
26+
}
27+
return result
28+
}
29+
1630
// OssRealtimeService is the service responsible for performing real-time OSS scanning.
1731
type OssRealtimeService struct {
1832
JwtWrapper wrappers.JWTWrapper
@@ -81,10 +95,7 @@ func enrichResponseWithRealtimeScannerResults(
8195
PackageName: pkg.PackageName,
8296
PackageVersion: pkg.Version,
8397
FilePath: entry.FilePath,
84-
LineStart: entry.LineStart,
85-
LineEnd: entry.LineEnd,
86-
StartIndex: entry.StartIndex,
87-
EndIndex: entry.EndIndex,
98+
Locations: entry.Locations,
8899
Status: pkg.Status,
89100
Vulnerabilities: vulnerabilityMapper.FromRealtimeScanner(pkg.Vulnerabilities),
90101
})
@@ -157,11 +168,8 @@ func prepareScan(pkgs []models.Package) (*OssPackageResults, *wrappers.RealtimeS
157168
PackageManager: pkg.PackageManager,
158169
PackageName: pkg.PackageName,
159170
PackageVersion: pkg.Version,
160-
LineStart: pkg.LineStart,
161-
LineEnd: pkg.LineEnd,
162171
FilePath: pkg.FilePath,
163-
StartIndex: pkg.StartIndex,
164-
EndIndex: pkg.EndIndex,
172+
Locations: convertLocations(pkg.Locations),
165173
Status: cachedPkg.Status,
166174
Vulnerabilities: vulnerabilityMapper.FromCache(cachedPkg.Vulnerabilities),
167175
})
@@ -181,10 +189,7 @@ func createPackageMap(pkgs []models.Package) map[string]OssPackage {
181189
PackageName: pkg.PackageName,
182190
PackageVersion: pkg.Version,
183191
FilePath: pkg.FilePath,
184-
LineStart: pkg.LineStart,
185-
LineEnd: pkg.LineEnd,
186-
StartIndex: pkg.StartIndex,
187-
EndIndex: pkg.EndIndex,
192+
Locations: convertLocations(pkg.Locations),
188193
}
189194
}
190195
return packageMap

internal/services/realtimeengine/ossrealtime/oss-realtime_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,53 @@ func TestScanAndCache_CacheExistsAndScanSuccess_CacheUpdated(t *testing.T) {
262262
assert.Equal(t, "4.17.1", cache.Packages[1].PackageVersion)
263263
assert.Equal(t, "Malicious", cache.Packages[1].Status)
264264
}
265+
266+
func TestOssRealtimeScan_CsprojFile_ReturnsLocations(t *testing.T) {
267+
// Arrange
268+
mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.OssRealtimeEnabled, Status: true}
269+
ossRealtimeService := NewOssRealtimeService(
270+
&mock.JWTMockWrapper{},
271+
&mock.FeatureFlagsMockWrapper{},
272+
&mock.RealtimeScannerMockWrapper{},
273+
)
274+
response, err := ossRealtimeService.RunOssRealtimeScan("../../../commands/data/manifests/test.csproj")
275+
276+
// Assert
277+
assert.Nil(t, err)
278+
assert.NotNil(t, response)
279+
assert.Equal(t, 5, len(response.Packages), "Should find exactly 5 packages in test.csproj")
280+
281+
// Find the Microsoft.TeamFoundationServer.Client package that should have 3 locations
282+
var tfsPackage *OssPackage
283+
for _, pkg := range response.Packages {
284+
if pkg.PackageName == "Microsoft.TeamFoundationServer.Client" && pkg.PackageVersion == "19.225.1" {
285+
tfsPackage = &pkg
286+
break
287+
}
288+
}
289+
290+
// Assert TFS package was found and has expected locations
291+
assert.NotNil(t, tfsPackage, "Should find Microsoft.TeamFoundationServer.Client package")
292+
assert.Equal(t, 3, len(tfsPackage.Locations), "TFS package should have exactly 3 locations")
293+
assert.Equal(t, "../../../commands/data/manifests/test.csproj", tfsPackage.FilePath)
294+
295+
// Verify specific location details
296+
expectedLocations := []struct {
297+
line int
298+
startIndex int
299+
endIndex int
300+
}{
301+
{32, 4, 70}, // Location 0: Line=32, StartIndex=4, EndIndex=70
302+
{33, 6, 33}, // Location 1: Line=33, StartIndex=6, EndIndex=33
303+
{34, 4, 23}, // Location 2: Line=34, StartIndex=4, EndIndex=23
304+
}
305+
306+
for i, expected := range expectedLocations {
307+
assert.Equal(t, expected.line, tfsPackage.Locations[i].Line,
308+
"Location %d line should be %d", i, expected.line)
309+
assert.Equal(t, expected.startIndex, tfsPackage.Locations[i].StartIndex,
310+
"Location %d startIndex should be %d", i, expected.startIndex)
311+
assert.Equal(t, expected.endIndex, tfsPackage.Locations[i].EndIndex,
312+
"Location %d endIndex should be %d", i, expected.endIndex)
313+
}
314+
}

0 commit comments

Comments
 (0)