-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from snyk/feat/scan-dotnet-with-missing-proj
Feat/scan dotnet with missing proj
- Loading branch information
Showing
8 changed files
with
144 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { TargetFramework } from "./types"; | ||
|
||
export function toReadableFramework(targetFramework: string): TargetFramework | undefined { | ||
const typeMapping = { | ||
net: '.NETFramework', | ||
netcoreapp: '.NETCore', | ||
netstandard: '.NETStandard', | ||
v: '.NETFramework', | ||
}; | ||
|
||
for (const type in typeMapping) { | ||
if (new RegExp(type + /\d.?\d(.?\d)?$/.source).test(targetFramework)) { | ||
return { | ||
framework: typeMapping[type], | ||
original: targetFramework, | ||
version: targetFramework.split(type)[1], | ||
}; | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface TargetFramework { | ||
framework: string; | ||
original: string; | ||
version: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as tap from 'tap'; | ||
const test = tap.test; | ||
import { getMinimumTargetFrameworkFromPackagesConfig } from '../lib/nuget-parser'; | ||
|
||
test('various error handling is performed for getMinimumTargetFrameworkFromPackagesConfig', async (t) => { | ||
// give bad content and expect to throw | ||
const malformedXml = '<hello></bye>'; | ||
try { | ||
await getMinimumTargetFrameworkFromPackagesConfig(malformedXml); | ||
t.fail('expected to throw on malformed xml'); | ||
} catch (error) { | ||
t.pass('expected to throw on malformed xml'); | ||
} | ||
|
||
// give empty content and expect undefined | ||
try { | ||
const result = await getMinimumTargetFrameworkFromPackagesConfig(''); | ||
t.pass('expected not to throw on empty content'); | ||
t.deepEqual(result, undefined, 'should return undefined on empty content'); | ||
} catch (error) { | ||
t.fail('expected not to throw on empty content'); | ||
} | ||
|
||
// give no packages but don't expect to throw | ||
const noPackages = ` | ||
<?xml version="1.0" encoding="utf-8"?> | ||
`; | ||
try { | ||
const result = await getMinimumTargetFrameworkFromPackagesConfig(noPackages); | ||
t.pass('expected not to throw on missing packages element in the xml'); | ||
t.deepEqual(result, undefined, 'should return undefined on missing packages element'); | ||
} catch (error) { | ||
t.fail('expected not to throw on missing packages element in the xml') | ||
} | ||
|
||
// give empty packages but don't expect to throw | ||
const emptyPackages = ` | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
</packages> | ||
`; | ||
try { | ||
const result = await getMinimumTargetFrameworkFromPackagesConfig(emptyPackages); | ||
t.pass('expected not to throw on empty packages element in the xml'); | ||
t.deepEqual(result, undefined, 'should return undefined on empty packages element'); | ||
} catch (error) { | ||
t.fail('expected not to throw on empty packages element in the xml'); | ||
} | ||
|
||
// give a file with no targetFramework in the dependencies and expect undefined | ||
const emptyTargetFramework = ` | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="jQuery" version="3.2.1" /> | ||
</packages> | ||
`; | ||
try { | ||
const shouldBeUndefined = await getMinimumTargetFrameworkFromPackagesConfig(emptyTargetFramework); | ||
t.pass('expected not to throw on missing targetFramework'); | ||
t.equal(shouldBeUndefined, undefined, 'should return undefined on missing targetFramework'); | ||
} catch (error) { | ||
t.fail('expected not to throw on missing targetFramework'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="jQuery" version="3.2.1" targetFramework="net461" /> | ||
<package id="Moment.js" version="2.20.1" targetFramework="net452" /> | ||
</packages> |