Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions share/scan/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ type mvnDependency struct {
}
*/

type dotnetRuntimeDetail struct {
AssemblyVersion string `json:"assemblyVersion"`
FileVersion string `json:"fileVersion"`
}
type dotnetDependency struct {
Deps map[string]string `json:"dependencies"`
Deps map[string]string `json:"dependencies"`
Runtime map[string]dotnetRuntimeDetail `json:"runtime"`
}

type dotnetRuntime struct {
Expand Down Expand Up @@ -733,7 +738,11 @@ func parseDotNetJsonData(filename string, fullpath string, dotnet dotnetPackage)

if targets, ok := dotnet.Targets[dotnet.Runtime.Name]; ok {
for target, dep := range targets {

// Skip if the target has no runtime; it means the dependency is not actually installed.
// if SCAN_DOTNET_RUNTIME is not set, we don't need to skip
if dep.Runtime == nil && os.Getenv("SCAN_DOTNET_RUNTIME") != "" {
continue
}
//Get dependencies of individual targets
for app, v := range dep.Deps {
key := fmt.Sprintf("%s-%s", ".NET:"+app, v)
Expand Down
48 changes: 48 additions & 0 deletions share/scan/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,54 @@ func TestParseDotNetModuleNameVersion(t *testing.T) {
}

func TestParseDotNetPackage(t *testing.T) {
t.Setenv("SCAN_DOTNET_RUNTIME", "true")
filename := "test.deps.json"
fullpath := "/home/test.deps.json"
data := dotnetPackage{
Runtime: dotnetRuntime{
Name: ".NETCoreApp,Version=v2.2",
Signature: "c10e7f708ec2454055c233c695ddc3ac682c23df",
},
Targets: map[string]map[string]dotnetDependency{
".NETCoreApp,Version=v2.2": {
"Business.ProfileService/1.0.0": dotnetDependency{
Deps: map[string]string{
"CorrelationId": "2.1.0",
"EasyNetQ": "3.4.0",
},
Runtime: map[string]dotnetRuntimeDetail{
"runtime": {
AssemblyVersion: "1.0.0",
FileVersion: "1.0.0",
},
},
},
"Elasticsearch.Net/6.0.0": dotnetDependency{
Deps: map[string]string{
"CorrelationId": "2.1.0",
"EasyNetQ": "3.4.0",
},
},
},
},
}
expectedResults := map[string]string{
".NET:Business.ProfileService": "1.0.0",
".NET:CorrelationId": "2.1.0",
".NET:EasyNetQ": "3.4.0",
}
pkgs := parseDotNetJsonData(filename, fullpath, data)
assert.Equal(t, len(expectedResults), len(pkgs), "unexpected number of pkgs")

for _, pkg := range pkgs {
assert.Contains(t, expectedResults, pkg.ModuleName, "unexpected pkg name")
if version, ok := expectedResults[pkg.ModuleName]; ok {
assert.Equal(t, version, pkg.Version, "ModuleVersion does not match expected version")
}
}
}

func TestParseDotNetPackageWithoutScanRuntime(t *testing.T) {
filename := "test.deps.json"
fullpath := "/home/test.deps.json"
data := dotnetPackage{
Expand Down