Skip to content

Commit b3d6444

Browse files
authored
Merge pull request #12 from fossology/development
Development to master
2 parents a3125b7 + 03474b6 commit b3d6444

36 files changed

+727
-635
lines changed

ChangeLog.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# ChangeLog - FOSSology.REST.dotnet
22

3-
## 1.2.0
3+
## 1.3.0 (2022-12-30)
4+
5+
* all dependencies updates to the latest version.
6+
* this fixes the security vulnerabilities of RestSharp and NewtonSoft.Json.
7+
* adaptations to use RestSharp 108.0.3 **and** FOSSology.
8+
* many additional checks for potential null assignments.
9+
* demo application is now .Net 6.
10+
* tested with FOSSology, version 4.2.1.21 (REST API v1.4.3).
11+
12+
## 1.2.0 (2022-03-17)
13+
414
* improved error handling.
515
* supports FOSSology REST API v1.4.3 (FOSSology 4.0.0 built @ 2023/03/09).
616
* new method GetHealth().
@@ -14,6 +24,7 @@
1424
* improved unit tests.
1525

1626
## 1.1.0 (2020-06-25)
27+
1728
* supports FOSSology REST API v1.0.16 (FOSSology 3.8.0 built @ 2020/06/19).
1829
* new method GetToken().
1930
* new method UploadPackageFromUrl().
@@ -32,5 +43,6 @@
3243

3344

3445
## 1.0.0 (2020-11-24)
46+
3547
* first version released.
3648
* supports FOSSology REST API v1.0.3 (FOSSology 3.7.0).

CodeCoverageReport.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ foreach ($file in $coberturaFiles) {
1919

2020
# 2. Run tests
2121
Write-Host "Running unit tests..."
22-
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
22+
# OLD way
23+
# dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
24+
# new way
25+
dotnet test --collect:"XPlat Code Coverage"
2326

2427
# 3 Generate reports
2528
Write-Host "Generating reports..."

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>1.2</Version>
4-
<FileVersion>1.2.0.0</FileVersion>
3+
<Version>1.3</Version>
4+
<FileVersion>1.3.0.0</FileVersion>
55
<Product>Fossology.Rest.Dotnet</Product>
66
<Company></Company>
77
<Copyright>Copyright © 2019-2022 T. Graf</Copyright>

Fossology.Rest.Dotnet.Model/Fossology.Rest.dotnet.Model.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
21-
<PrivateAssets>all</PrivateAssets>
22-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23-
</PackageReference>
24-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
20+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
2521
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
2622
<PrivateAssets>all</PrivateAssets>
2723
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2824
</PackageReference>
29-
<None Include="..\README.md" Pack="true" PackagePath="\"/>
25+
<None Include="..\README.md" Pack="true" PackagePath="\" />
3026
</ItemGroup>
3127

3228
<ItemGroup>

Fossology.Rest.Dotnet.Test/Fossology.Rest.Dotnet.Test.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<CodeAnalysisRuleSet>..\Fossology.Rest.Dotnet.ruleset</CodeAnalysisRuleSet>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
10+
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
15-
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
16-
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
17-
<PackageReference Include="coverlet.collector" Version="1.3.0">
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
16+
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
17+
<PackageReference Include="coverlet.collector" Version="3.2.0">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>
21-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
21+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
2222
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
2323
<PrivateAssets>all</PrivateAssets>
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2525
</PackageReference>
26-
<PackageReference Include="Tethys.Logging.Console" Version="1.5.0" />
26+
<PackageReference Include="Tethys.Logging.Console" Version="1.6.1" />
2727
</ItemGroup>
2828

2929
<ItemGroup>

Fossology.Rest.Dotnet.Test/FossologyClientTest.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class FossologyClientTest
4545
/// <summary>
4646
/// The access token.
4747
/// </summary>
48-
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDc4MjA3OTksIm5iZiI6MTY0NzQ3NTIwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.8PK99xI7N482c1GC2Onzwe2p74Y80_ef4DVj99jiwn4";
48+
private const string Token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzI2MTc1OTksIm5iZiI6MTY3MjM1ODQwMCwianRpIjoiTWk0eiIsInNjb3BlIjoid3JpdGUifQ.zivhU2CiTDI2_PqWvPejifhs6d6HohVOW6w1XG3GUSQ";
4949

5050
/// <summary>
5151
/// The filename of a test package.
@@ -702,6 +702,7 @@ public void TestDeleteUserFailure()
702702
Assert.IsFalse(false, "No valid error response");
703703
}
704704

705+
#if false // search does not work with FOSSology, version 4.2.1.21 container
705706
/// <summary>
706707
/// Unit test.
707708
/// </summary>
@@ -738,6 +739,7 @@ public void TestSearch2()
738739
Assert.IsTrue(result.Count > 0);
739740
Assert.AreEqual("BuildPackages.ps1", result[0].Filename);
740741
}
742+
#endif
741743

742744
/// <summary>
743745
/// Integration test, runs unit tests in defined order on a plain
@@ -801,9 +803,11 @@ public void MyIntegrationTestLikeUnitTest()
801803
Assert.IsNotNull(user);
802804
Assert.AreEqual(2, user.Id);
803805

806+
#if false
804807
var searchresult = client.Search("%");
805808
Assert.IsNotNull(searchresult);
806809
Assert.IsTrue(searchresult.Count > 0);
810+
#endif
807811

808812
var jobTrigger = new TriggerInfo();
809813
jobTrigger.Analysis.Bucket = true;
@@ -1101,7 +1105,7 @@ private static int TriggerReportGeneration(int uploadId)
11011105
Assert.AreEqual("INFO", result.Type);
11021106
Assert.AreEqual(201, result.Code);
11031107

1104-
var text = result.Message[(result.Message.LastIndexOf('/') + 1) ..];
1108+
var text = result.Message[(result.Message.LastIndexOf('/') + 1)..];
11051109
return int.Parse(text);
11061110
}
11071111

Fossology.Rest.Dotnet.sln

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29503.13
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33205.214
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{66961846-D78E-4DC0-BE09-F712FC21EA09}"
77
ProjectSection(SolutionItems) = preProject
@@ -25,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fossology.Rest.Dotnet", "Fo
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fossology.Rest.Dotnet.Test", "Fossology.Rest.Dotnet.Test\Fossology.Rest.Dotnet.Test.csproj", "{A1FBAA6A-4B91-4889-93C5-0346E2474162}"
2727
EndProject
28-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FossyApiDemo", "FossyApiDemo\FossyApiDemo.csproj", "{CAF41CCA-2778-4767-AB50-60205339E60B}"
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FossyApiDemo", "FossyApiDemo\FossyApiDemo.csproj", "{A3CA5288-F717-48E5-A6F7-76E93D9F9108}"
2929
EndProject
3030
Global
3131
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -45,10 +45,10 @@ Global
4545
{A1FBAA6A-4B91-4889-93C5-0346E2474162}.Debug|Any CPU.Build.0 = Debug|Any CPU
4646
{A1FBAA6A-4B91-4889-93C5-0346E2474162}.Release|Any CPU.ActiveCfg = Release|Any CPU
4747
{A1FBAA6A-4B91-4889-93C5-0346E2474162}.Release|Any CPU.Build.0 = Release|Any CPU
48-
{CAF41CCA-2778-4767-AB50-60205339E60B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49-
{CAF41CCA-2778-4767-AB50-60205339E60B}.Debug|Any CPU.Build.0 = Debug|Any CPU
50-
{CAF41CCA-2778-4767-AB50-60205339E60B}.Release|Any CPU.ActiveCfg = Release|Any CPU
51-
{CAF41CCA-2778-4767-AB50-60205339E60B}.Release|Any CPU.Build.0 = Release|Any CPU
48+
{A3CA5288-F717-48E5-A6F7-76E93D9F9108}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49+
{A3CA5288-F717-48E5-A6F7-76E93D9F9108}.Debug|Any CPU.Build.0 = Debug|Any CPU
50+
{A3CA5288-F717-48E5-A6F7-76E93D9F9108}.Release|Any CPU.ActiveCfg = Release|Any CPU
51+
{A3CA5288-F717-48E5-A6F7-76E93D9F9108}.Release|Any CPU.Build.0 = Release|Any CPU
5252
EndGlobalSection
5353
GlobalSection(SolutionProperties) = preSolution
5454
HideSolutionNode = FALSE

Fossology.Rest.Dotnet/ErrorCode.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ public enum ErrorCode
4343
/// File to upload not found.
4444
/// </summary>
4545
FileNotFound = 4,
46+
47+
/// <summary>
48+
/// The no valid answer from server.
49+
/// </summary>
50+
NoValidAnswer = 5,
4651
} // ErrorCode
4752
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// ---------------------------------------------------------------------------
2+
// <copyright file="FileStreamWithProgress.cs" company="Tethys">
3+
// Copyright (C) 2019-2022 T. Graf
4+
// </copyright>
5+
//
6+
// Licensed under the MIT License.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
// Unless required by applicable law or agreed to in writing,
10+
// software distributed under the License is distributed on an
11+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
// either express or implied.
13+
// ---------------------------------------------------------------------------
14+
15+
namespace Fossology.Rest.Dotnet
16+
{
17+
using System;
18+
using System.IO;
19+
using Tethys.Logging;
20+
21+
/// <summary>
22+
/// Implements a file stream that can report the read progress.
23+
/// </summary>
24+
/// <seealso cref="System.IO.Stream" />
25+
internal class FileStreamWithProgress : Stream
26+
{
27+
#region PRIVATE PROPERTIES
28+
/// <summary>
29+
/// The logger for this class.
30+
/// </summary>
31+
private static readonly ILog Log = LogManager.GetLogger(typeof(FileStreamWithProgress));
32+
33+
/// <summary>
34+
/// The file stream.
35+
/// </summary>
36+
private readonly FileStream fileStream;
37+
38+
/// <summary>
39+
/// The upload finished callback.
40+
/// </summary>
41+
private readonly Action uploadFinished;
42+
43+
/// <summary>
44+
/// The upload progress callback.
45+
/// </summary>
46+
private readonly Action<float> uploadProgress;
47+
48+
/// <summary>
49+
/// The current position.
50+
/// </summary>
51+
private long sofar;
52+
#endregion // PRIVATE PROPERTIES
53+
54+
//// ---------------------------------------------------------------------
55+
56+
#region PUBLIC PROPERTIES
57+
/// <inheritdoc />
58+
public override bool CanRead
59+
{
60+
get { return this.fileStream != null && this.fileStream.CanRead; }
61+
}
62+
63+
/// <inheritdoc />
64+
public override bool CanSeek
65+
{
66+
get { return this.fileStream != null && this.fileStream.CanSeek; }
67+
}
68+
69+
/// <inheritdoc />
70+
public override bool CanWrite
71+
{
72+
get { return this.fileStream != null && this.fileStream.CanWrite; }
73+
}
74+
75+
/// <inheritdoc />
76+
public override long Length
77+
{
78+
get
79+
{
80+
return this.fileStream?.Length ?? 0;
81+
}
82+
}
83+
84+
/// <inheritdoc />
85+
public override long Position
86+
{
87+
get { return this.fileStream?.Position ?? 0; }
88+
set { }
89+
}
90+
#endregion // PUBLIC PROPERTIES
91+
92+
//// ---------------------------------------------------------------------
93+
94+
#region CONSTRUCTION
95+
/// <summary>
96+
/// Initializes a new instance of the <see cref="FileStreamWithProgress"/> class.
97+
/// </summary>
98+
/// <param name="fileName">Name of the file.</param>
99+
/// <param name="uploadFinished">The optional upload finished callback.</param>
100+
/// <param name="uploadProgress">The optional upload progress callback.</param>
101+
public FileStreamWithProgress(
102+
string fileName,
103+
Action uploadFinished = null,
104+
Action<float> uploadProgress = null)
105+
{
106+
this.fileStream = new FileStream(fileName, FileMode.Open);
107+
this.uploadFinished = uploadFinished;
108+
this.uploadProgress = uploadProgress;
109+
this.sofar = 0;
110+
} // FileStreamWithProgress()
111+
#endregion // CONSTRUCTION
112+
113+
//// ---------------------------------------------------------------------
114+
115+
#region PUBLIC METHODS
116+
/// <inheritdoc />
117+
public override void Flush()
118+
{
119+
this.fileStream?.Flush();
120+
}
121+
122+
/// <inheritdoc />
123+
public override int Read(byte[] buffer, int offset, int count)
124+
{
125+
if (this.fileStream == null)
126+
{
127+
return 0;
128+
} // if
129+
130+
var result = this.fileStream.Read(buffer, offset, count);
131+
132+
this.sofar = this.fileStream.Position;
133+
134+
var percentage = this.sofar * 100 / this.fileStream.Length;
135+
var progress = percentage / 100f;
136+
137+
Log.Debug($"Upload progress = {progress}");
138+
this.uploadProgress?.Invoke(progress);
139+
140+
if (this.sofar >= this.fileStream.Length)
141+
{
142+
this.uploadFinished?.Invoke();
143+
} // if
144+
145+
return result;
146+
}
147+
148+
/// <inheritdoc />
149+
public override long Seek(long offset, SeekOrigin origin)
150+
{
151+
if (this.fileStream == null)
152+
{
153+
return 0;
154+
} // if
155+
156+
var result = this.fileStream.Seek(offset, origin);
157+
this.sofar = result;
158+
return result;
159+
}
160+
161+
/// <inheritdoc />
162+
public override void SetLength(long value)
163+
{
164+
this.fileStream?.SetLength(value);
165+
}
166+
167+
/// <inheritdoc />
168+
public override void Write(byte[] buffer, int offset, int count)
169+
{
170+
this.fileStream?.Write(buffer, offset, count);
171+
}
172+
#endregion // PUBLIC METHODS
173+
} // FileStreamWithProgress
174+
}

Fossology.Rest.Dotnet/Fossology.Rest.Dotnet.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
21-
<PackageReference Include="RestSharp" Version="106.11.4" />
20+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
21+
<PackageReference Include="RestSharp" Version="108.0.3" />
2222
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
2323
<PrivateAssets>all</PrivateAssets>
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2525
</PackageReference>
26-
<PackageReference Include="Tethys.Logging" Version="1.5.0" />
27-
<None Include="..\README.md" Pack="true" PackagePath="\"/>
26+
<PackageReference Include="Tethys.Logging" Version="1.6.1" />
27+
<None Include="..\README.md" Pack="true" PackagePath="\" />
2828
</ItemGroup>
2929

3030
<ItemGroup>

0 commit comments

Comments
 (0)