Skip to content
Snippets Groups Projects
Commit 58e7395b authored by Klaus Fischer's avatar Klaus Fischer
Browse files

Cleaned up and added comments

parent 44b797ae
No related branches found
No related tags found
1 merge request!3Feature/440 mvp net sdk part 1
Showing
with 117 additions and 143 deletions
...@@ -9,18 +9,18 @@ ...@@ -9,18 +9,18 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" /> <ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="Test.pdf"> <None Update="Test.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -21,11 +21,11 @@ void FluentSenderCall() { ...@@ -21,11 +21,11 @@ void FluentSenderCall() {
new Client( new Client(
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development),
clientId, clientSecret, clientId, clientSecret,
logger: logger).GetSender() logger).GetSender()
.WithDestination(destinationId) .WithDestination(destinationId)
.WithServiceType("ServiceName", leikaKey) .WithServiceType("ServiceName", leikaKey)
.WithAttachments(new List<Attachment>() { .WithAttachments(new List<Attachment> {
new Attachment("Test.pdf", "The description of the attachment") new("Test.pdf", "The description of the attachment")
}) })
.WithData("{\"data\":\"value\"}") .WithData("{\"data\":\"value\"}")
.Submit(); .Submit();
...@@ -35,7 +35,7 @@ void FluentSubscriberCall() { ...@@ -35,7 +35,7 @@ void FluentSubscriberCall() {
var client = new Client( var client = new Client(
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development),
clientId, clientSecret, clientId, clientSecret,
logger: logger); logger);
} }
FluentSenderCall(); FluentSenderCall();
......
...@@ -8,24 +8,24 @@ ...@@ -8,24 +8,24 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DotNet.Testcontainers" Version="1.6.0" /> <PackageReference Include="DotNet.Testcontainers" Version="1.6.0"/>
<PackageReference Include="FluentAssertions" Version="6.7.0" /> <PackageReference Include="FluentAssertions" Version="6.7.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.0" /> <PackageReference Include="coverlet.collector" Version="3.1.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" /> <ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
<ProjectReference Include="..\Services\Services.csproj" /> <ProjectReference Include="..\Services\Services.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="Test.pdf"> <None Update="Test.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
</Project> </Project>
using System;
using System.IO;
using System.Security.Authentication; using System.Security.Authentication;
using FitConnect; using FitConnect;
using FitConnect.Services; using FitConnect.Services;
using FluentAssertions; using FluentAssertions;
using Newtonsoft.Json;
using NUnit.Framework; using NUnit.Framework;
namespace E2ETests; namespace E2ETests;
...@@ -20,7 +17,6 @@ public class OAuthServiceTest { ...@@ -20,7 +17,6 @@ public class OAuthServiceTest {
} }
[SetUp] [SetUp]
public void SetUp() { public void SetUp() {
var endpoints = FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development); var endpoints = FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development);
......
...@@ -2,23 +2,21 @@ using System; ...@@ -2,23 +2,21 @@ using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Threading;
using NUnit.Framework;
using DotNet.Testcontainers;
using DotNet.Testcontainers.Builders; using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers; using DotNet.Testcontainers.Containers;
using FitConnect; using FitConnect;
using FitConnect.Services; using FitConnect.Services;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework;
namespace E2ETests; namespace E2ETests;
[Ignore("Not testable in docker container, take to long to run every time")] [Ignore("Not testable in docker container, take to long to run every time")]
public class ProxyTest { public class ProxyTest {
private TestcontainersContainer _container;
private Client _client; private Client _client;
private string _secret; private TestcontainersContainer _container;
private string _id; private string _id;
private string _secret;
[OneTimeSetUp] [OneTimeSetUp]
public void OneTimeSetup() { public void OneTimeSetup() {
...@@ -50,7 +48,7 @@ public class ProxyTest { ...@@ -50,7 +48,7 @@ public class ProxyTest {
_container.Should().NotBeNull(); _container.Should().NotBeNull();
_container.State.Should().Be(TestcontainersState.Running); _container.State.Should().Be(TestcontainersState.Running);
var client = new WebClient() { var client = new WebClient {
Proxy = Proxy =
new WebProxy("http://localhost:3128") new WebProxy("http://localhost:3128")
}; };
......
...@@ -12,13 +12,6 @@ namespace E2ETests; ...@@ -12,13 +12,6 @@ namespace E2ETests;
[TestFixture] [TestFixture]
public abstract class SenderTestBase { public abstract class SenderTestBase {
protected const string desitnationId = "aa3704d6-8bd7-4d40-a8af-501851f93934";
protected string _clientId = "73a8ff88-076b-4263-9a80-8ebadac97b0d";
protected string _clientSecret = "rdlXms-4ikO47AbTmmCTdzFoE4cTSt13JmSbcY5Dhsw";
protected Sender _sender;
protected IFluentSender _fluentSender;
/// <summary> /// <summary>
/// Setup creates json file for credentials if not found /// Setup creates json file for credentials if not found
/// </summary> /// </summary>
...@@ -55,7 +48,13 @@ public abstract class SenderTestBase { ...@@ -55,7 +48,13 @@ public abstract class SenderTestBase {
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development),
_clientId, _clientSecret, logger).GetSender(); _clientId, _clientSecret, logger).GetSender();
} }
protected const string desitnationId = "aa3704d6-8bd7-4d40-a8af-501851f93934";
protected string _clientId = "73a8ff88-076b-4263-9a80-8ebadac97b0d";
protected string _clientSecret = "rdlXms-4ikO47AbTmmCTdzFoE4cTSt13JmSbcY5Dhsw";
protected Sender _sender;
protected IFluentSender _fluentSender;
protected Submission GetSubmissionInfo(IFluentSender sender) { protected Submission GetSubmissionInfo(IFluentSender sender) {
var submission = sender.GetType().GetProperties() var submission = sender.GetType().GetProperties()
.FirstOrDefault(p => p.Name == "Submission") .FirstOrDefault(p => p.Name == "Submission")
...@@ -63,6 +62,4 @@ public abstract class SenderTestBase { ...@@ -63,6 +62,4 @@ public abstract class SenderTestBase {
return submission; return submission;
} }
} }
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using FitConnect; using FitConnect;
using FitConnect.Interfaces;
using FitConnect.Models; using FitConnect.Models;
using FluentAssertions; using FluentAssertions;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using NUnit.Framework; using NUnit.Framework;
...@@ -120,7 +117,7 @@ public class SenderTestHappyPath : SenderTestBase { ...@@ -120,7 +117,7 @@ public class SenderTestHappyPath : SenderTestBase {
.WithData(JsonConvert.SerializeObject(new { .WithData(JsonConvert.SerializeObject(new {
FirstName = "John", FirstName = "John",
LastName = "Doe", LastName = "Doe",
Age = 42, Age = 42
})); }));
// Act // Act
......
...@@ -21,11 +21,10 @@ public class SenderTestUnhappyPath : SenderTestBase { ...@@ -21,11 +21,10 @@ public class SenderTestUnhappyPath : SenderTestBase {
_fluentSender.WithDestination("This is very wrong"); _fluentSender.WithDestination("This is very wrong");
}).Message.Should().Be("The destination must be a valid GUID"); }).Message.Should().Be("The destination must be a valid GUID");
} }
[Test] [Test]
public void WithData_DataIsInvalidJson_ShouldThrowArgumentException() { public void WithData_DataIsInvalidJson_ShouldThrowArgumentException() {
Assert.Throws<ArgumentException>(() => { Assert.Throws<ArgumentException>(() => { _fluentSender.WithData("This is very wrong"); })
_fluentSender.WithData("This is very wrong"); .Message.Should().Be("The data must be valid JSON string");
}).Message.Should().Be("The data must be valid JSON string");
} }
} }
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="IdentityModel" Version="6.0.0" /> <PackageReference Include="IdentityModel" Version="6.0.0"/>
<PackageReference Include="jose-jwt" Version="4.0.0" /> <PackageReference Include="jose-jwt" Version="4.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.20.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.20.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="DefaultEncryptor.cs" /> <Compile Remove="DefaultEncryptor.cs"/>
<Compile Remove="RsaEncryption.cs" /> <Compile Remove="RsaEncryption.cs"/>
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -7,13 +7,8 @@ public record KeySet(string? PrivateKeyDecryption, ...@@ -7,13 +7,8 @@ public record KeySet(string? PrivateKeyDecryption,
); );
public class FitEncryption { public class FitEncryption {
private readonly ILogger? _logger;
public string? PrivateKeyDecryption { get; set; }
public string? PrivateKeySigning { get; set; }
public string? PublicKeyEncryption { get; set; }
public string? PublicKeySignatureVerification { get; set; }
private readonly IEncryptor _encryptor = new JoseEncryptor(); private readonly IEncryptor _encryptor = new JoseEncryptor();
private readonly ILogger? _logger;
public FitEncryption(ILogger? logger) { public FitEncryption(ILogger? logger) {
_logger = logger; _logger = logger;
...@@ -37,34 +32,42 @@ public class FitEncryption { ...@@ -37,34 +32,42 @@ public class FitEncryption {
PublicKeySignatureVerification = keySet.PublicKeySignatureVerification; PublicKeySignatureVerification = keySet.PublicKeySignatureVerification;
} }
public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string cypherText, string key) => public string? PrivateKeyDecryption { get; set; }
_encryptor.Decrypt(key, cypherText); public string? PrivateKeySigning { get; set; }
public string? PublicKeyEncryption { get; set; }
public string? PublicKeySignatureVerification { get; set; }
public (string plainText, byte[] plainBytes, byte[] tag)
Decrypt(string cypherText, string key) {
return _encryptor.Decrypt(key, cypherText);
}
public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string cypherText) { public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string cypherText) {
if (PrivateKeyDecryption == null) { if (PrivateKeyDecryption == null)
throw new InvalidOperationException("PrivateKey is not provided"); throw new InvalidOperationException("PrivateKey is not provided");
}
return Decrypt(cypherText, PrivateKeyDecryption); return Decrypt(cypherText, PrivateKeyDecryption);
} }
public string Encrypt(string plainText, string key) => _encryptor.Encrypt(key, plainText); public string Encrypt(string plainText, string key) {
return _encryptor.Encrypt(key, plainText);
}
public string Encrypt(string plain) { public string Encrypt(string plain) {
if (PublicKeyEncryption == null) { if (PublicKeyEncryption == null)
throw new InvalidOperationException("PrivateKey is not provided"); throw new InvalidOperationException("PrivateKey is not provided");
}
return Encrypt(plain, PublicKeyEncryption); return Encrypt(plain, PublicKeyEncryption);
} }
public string Encrypt(byte[] plain, string key) => _encryptor.Encrypt(key, plain); public string Encrypt(byte[] plain, string key) {
return _encryptor.Encrypt(key, plain);
}
public string Encrypt(byte[] plain) { public string Encrypt(byte[] plain) {
if (PublicKeyEncryption == null) { if (PublicKeyEncryption == null)
throw new InvalidOperationException("PrivateKey is not provided"); throw new InvalidOperationException("PrivateKey is not provided");
}
return Encrypt(plain, PublicKeyEncryption); return Encrypt(plain, PublicKeyEncryption);
} }
......
using System.Security.Cryptography;
using IdentityModel;
using IdentityModel.Jwk;
using Base64Url = Jose.Base64Url;
namespace FitConnect.Encryption; namespace FitConnect.Encryption;
public interface IEncryptor { public interface IEncryptor {
public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string key, string cipher); public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string key, string cipher);
public string Encrypt(string key, string plain); public string Encrypt(string key, string plain);
public string Encrypt(string key, byte[] plain); public string Encrypt(string key, byte[] plain);
} }
\ No newline at end of file
...@@ -11,16 +11,10 @@ public class JoseEncryptor : IEncryptor { ...@@ -11,16 +11,10 @@ public class JoseEncryptor : IEncryptor {
private const string ErrorMessage = private const string ErrorMessage =
"On macOS add DYLD_LIBRARY_PATH to your environment variables. Look at the README for more information."; "On macOS add DYLD_LIBRARY_PATH to your environment variables. Look at the README for more information.";
private (string plainText, byte[] plainBytes, byte[] tag) Decrypt(Jwk key, string payload) {
var result = JWE.Decrypt(payload, key);
return (result.Plaintext, result.PlaintextBytes, result.AuthTag);
}
public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string key, string cipher) { public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string key, string cipher) {
try { try {
var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); var jwk = Jwk.FromJson(key, new JsonMapper());
return Decrypt(jwk, cipher); return Decrypt(jwk, cipher);
} }
catch (PlatformNotSupportedException e) { catch (PlatformNotSupportedException e) {
...@@ -30,7 +24,7 @@ public class JoseEncryptor : IEncryptor { ...@@ -30,7 +24,7 @@ public class JoseEncryptor : IEncryptor {
public string Encrypt(string key, string plain) { public string Encrypt(string key, string plain) {
try { try {
var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); var jwk = Jwk.FromJson(key, new JsonMapper());
return JWE.Encrypt(plain, return JWE.Encrypt(plain,
new JweRecipient[] { new JweRecipient(Algorithm, jwk) }, new JweRecipient[] { new JweRecipient(Algorithm, jwk) },
Encryption, Encryption,
...@@ -49,7 +43,7 @@ public class JoseEncryptor : IEncryptor { ...@@ -49,7 +43,7 @@ public class JoseEncryptor : IEncryptor {
public string Encrypt(string key, byte[] plain) { public string Encrypt(string key, byte[] plain) {
try { try {
var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); var jwk = Jwk.FromJson(key, new JsonMapper());
return JWE.EncryptBytes(plain, return JWE.EncryptBytes(plain,
new JweRecipient[] { new JweRecipient(Algorithm, jwk) }, new JweRecipient[] { new JweRecipient(Algorithm, jwk) },
Encryption, Encryption,
...@@ -65,4 +59,10 @@ public class JoseEncryptor : IEncryptor { ...@@ -65,4 +59,10 @@ public class JoseEncryptor : IEncryptor {
throw new PlatformNotSupportedException(ErrorMessage, e); throw new PlatformNotSupportedException(ErrorMessage, e);
} }
} }
private (string plainText, byte[] plainBytes, byte[] tag) Decrypt(Jwk key, string payload) {
var result = JWE.Decrypt(payload, key);
return (result.Plaintext, result.PlaintextBytes, result.AuthTag);
}
} }
...@@ -10,31 +10,31 @@ ...@@ -10,31 +10,31 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" /> <PackageReference Include="FluentAssertions" Version="6.7.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" /> <PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.0" /> <PackageReference Include="coverlet.collector" Version="3.1.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" /> <ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
<ProjectReference Include="..\MockContainer\MockContainer.csproj" /> <ProjectReference Include="..\MockContainer\MockContainer.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Certificates" /> <Folder Include="Certificates"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="assets\attachment.pdf"> <None Update="assets\attachment.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Test.pdf"> <None Update="Test.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
</Project> </Project>
using System.IO; using System.IO;
using System.Net;
using System.Security.Cryptography; using System.Security.Cryptography;
using Autofac; using Autofac;
using FitConnect.Encryption; using FitConnect.Encryption;
using FitConnect.Models.Api.Metadata; using FitConnect.Models;
using FluentAssertions; using FluentAssertions;
using MockContainer;
using NUnit.Framework; using NUnit.Framework;
namespace SenderTest; namespace SenderTest;
public class FileEncryptionTest { public class FileEncryptionTest {
private byte[] sourceFile = null!;
private FitEncryption _encryption;
private string _encryptedFile; private string _encryptedFile;
private FitEncryption _encryption;
private byte[] sourceFile = null!;
[SetUp] [SetUp]
public void Setup() { public void Setup() {
sourceFile = RandomNumberGenerator.GetBytes(4096); sourceFile = RandomNumberGenerator.GetBytes(4096);
var container = MockContainer.Container.Create(); var container = Container.Create();
var keySet = container.Resolve<KeySet>(); var keySet = container.Resolve<KeySet>();
_encryption = new FitEncryption(keySet, null); _encryption = new FitEncryption(keySet, null);
} }
...@@ -30,15 +30,14 @@ public class FileEncryptionTest { ...@@ -30,15 +30,14 @@ public class FileEncryptionTest {
[Test] [Test]
public void TestSha512FileHash() { public void TestSha512FileHash() {
// Arrange // Arrange
var content = File.ReadAllBytes("Test.pdf"); var content = File.ReadAllBytes("Test.pdf");
// Act // Act
var attachment = new FitConnect.Models.Attachment { var attachment = new Attachment {
MimeType = "application/pdf", MimeType = "application/pdf",
Content = content, Content = content
}; };
var hash = attachment.Hash; var hash = attachment.Hash;
......
using System; using System;
using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text;
using Autofac; using Autofac;
using FitConnect; using FitConnect;
using FitConnect.Encryption; using FitConnect.Encryption;
...@@ -14,9 +12,9 @@ using NUnit.Framework; ...@@ -14,9 +12,9 @@ using NUnit.Framework;
namespace SenderTest; namespace SenderTest;
public class JweTest { public class JweTest {
private IContainer _container;
private ILogger<JweTest> _logger; private ILogger<JweTest> _logger;
private Sender _sender; private Sender _sender;
private IContainer _container;
private MockSettings _settings; private MockSettings _settings;
...@@ -27,9 +25,9 @@ public class JweTest { ...@@ -27,9 +25,9 @@ public class JweTest {
_sender = Sender.Create( _sender = Sender.Create(
FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development), FitConnectEndpoints.Create(FitConnectEndpoints.EndpointType.Development),
logger: _logger); _logger);
_container = MockContainer.Container.Create(); _container = Container.Create();
_settings = _container.Resolve<MockSettings>(); _settings = _container.Resolve<MockSettings>();
} }
......
using System;
using System.IO; using System.IO;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using FitConnect; using FitConnect;
using FitConnect.Encryption;
using FluentAssertions; using FluentAssertions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NUnit.Framework; using NUnit.Framework;
...@@ -14,7 +12,7 @@ namespace SenderTest; ...@@ -14,7 +12,7 @@ namespace SenderTest;
public class SenderEncryptionWithSelfSignedCertificateTest { public class SenderEncryptionWithSelfSignedCertificateTest {
private const string ToEncrypt = "This is a test message"; private const string ToEncrypt = "This is a test message";
private static string? cypher; private static string? cypher;
private X509Certificate2 _certificate = null!; private readonly X509Certificate2 _certificate = null!;
private ILogger<SenderEncryptionWithSelfSignedCertificateTest> _logger = null!; private ILogger<SenderEncryptionWithSelfSignedCertificateTest> _logger = null!;
private Sender _sender = null!; private Sender _sender = null!;
......
using System;
using System.Text; using System.Text;
using FitConnect; using FitConnect;
using FluentAssertions; using FluentAssertions;
...@@ -10,7 +9,7 @@ namespace SenderTest; ...@@ -10,7 +9,7 @@ namespace SenderTest;
[Ignore("Encryption strategy does not match the one used on server")] [Ignore("Encryption strategy does not match the one used on server")]
public class SenderEncryptionWithoutCertificateTest { public class SenderEncryptionWithoutCertificateTest {
private const string ToEncrypt = "Hello World"; private const string ToEncrypt = "Hello World";
private string _cypherText = null!; private readonly string _cypherText = null!;
private ILogger<SenderEncryptionWithoutCertificateTest> _logger = null!; private ILogger<SenderEncryptionWithoutCertificateTest> _logger = null!;
private Sender _sender = null!; private Sender _sender = null!;
...@@ -40,7 +39,7 @@ public class SenderEncryptionWithoutCertificateTest { ...@@ -40,7 +39,7 @@ public class SenderEncryptionWithoutCertificateTest {
[Test] [Test]
[Order(20)] [Order(20)]
public void DecryptData_ShouldMatchToEncrypt() { public void DecryptData_ShouldMatchToEncrypt() {
var (plain,_, tag) = _sender.Encryption.Decrypt(_cypherText); var (plain, _, tag) = _sender.Encryption.Decrypt(_cypherText);
plain.Should().Be(ToEncrypt); plain.Should().Be(ToEncrypt);
} }
......
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=leika/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
\ No newline at end of file
using System.Security.Cryptography.X509Certificates;
using FitConnect.Encryption;
using FitConnect.Models; using FitConnect.Models;
using FitConnect.Services; using FitConnect.Services;
using FitConnect.Services.Models; using FitConnect.Services.Models;
...@@ -8,8 +6,6 @@ using Microsoft.Extensions.Logging; ...@@ -8,8 +6,6 @@ using Microsoft.Extensions.Logging;
namespace FitConnect.BaseClasses; namespace FitConnect.BaseClasses;
public abstract class FunctionalBaseClass { public abstract class FunctionalBaseClass {
protected IDestinationService DestinationService { get; }
protected readonly ILogger? Logger; protected readonly ILogger? Logger;
// protected readonly FitConnectApiService ApiService; // protected readonly FitConnectApiService ApiService;
...@@ -46,6 +42,8 @@ public abstract class FunctionalBaseClass { ...@@ -46,6 +42,8 @@ public abstract class FunctionalBaseClass {
RouteService = routeService; RouteService = routeService;
} }
protected IDestinationService DestinationService { get; }
internal Client Owner { get; set; } internal Client Owner { get; set; }
protected string? ClientId => Owner?.ClientId; protected string? ClientId => Owner?.ClientId;
......
using System.Net; using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;
using Autofac; using Autofac;
using FitConnect.Interfaces; using FitConnect.Interfaces;
using FitConnect.Models; using FitConnect.Models;
using FitConnect.Services; using FitConnect.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
namespace FitConnect; namespace FitConnect;
...@@ -16,19 +13,19 @@ namespace FitConnect; ...@@ -16,19 +13,19 @@ namespace FitConnect;
// ReSharper disable once UnusedType.Global // ReSharper disable once UnusedType.Global
public class Client { public class Client {
private readonly FitConnectEndpoints _endpoints; private readonly FitConnectEndpoints _endpoints;
internal readonly string ClientId;
internal readonly string ClientSecret;
private readonly ILogger? _logger; private readonly ILogger? _logger;
private readonly IOAuthService _oAuthService; private readonly IOAuthService _oAuthService;
private readonly IRouteService _routeService;
private readonly ISubmissionService _submissionService; private readonly ISubmissionService _submissionService;
internal readonly string ClientId;
private readonly IRouteService _routeService; internal readonly string ClientSecret;
private IDestinationService _destinationService; private readonly IDestinationService _destinationService;
// private Routing Routing { get; } // private Routing Routing { get; }
...@@ -57,7 +54,6 @@ public class Client { ...@@ -57,7 +54,6 @@ public class Client {
} }
/// <summary> /// <summary>
///
/// </summary> /// </summary>
/// <param name="host"></param> /// <param name="host"></param>
/// <param name="port"></param> /// <param name="port"></param>
...@@ -67,9 +63,8 @@ public class Client { ...@@ -67,9 +63,8 @@ public class Client {
public Client WithProxy(string host, int port, string? username = null, public Client WithProxy(string host, int port, string? username = null,
string? password = null) { string? password = null) {
var proxy = new WebProxy(host, port); var proxy = new WebProxy(host, port);
if (username != null && password != null) { if (username != null && password != null)
proxy.Credentials = new NetworkCredential(username, password); proxy.Credentials = new NetworkCredential(username, password);
}
DiContainer.WebProxy = proxy; DiContainer.WebProxy = proxy;
return this; return this;
...@@ -79,18 +74,18 @@ public class Client { ...@@ -79,18 +74,18 @@ public class Client {
return new FluentSubscriber(_endpoints, _oAuthService, _submissionService, _routeService, return new FluentSubscriber(_endpoints, _oAuthService, _submissionService, _routeService,
_destinationService, _destinationService,
privateKeyEncryption, _logger) privateKeyEncryption, _logger)
{ Owner = this}; { Owner = this };
} }
/// <summary> /// <summary>
/// /// Creates the FluentSender for <see cref="Submission" /> sending
/// </summary> /// </summary>
/// <param name="skipServerActions">No server interaction, only logging</param>
/// <returns></returns> /// <returns></returns>
public IFluentSender GetSender(bool skipServerActions = false) => public IFluentSender GetSender() {
new FluentSender(_endpoints, _oAuthService, _submissionService, _routeService, return new FluentSender(_endpoints, _oAuthService, _submissionService, _routeService,
_destinationService, _logger) _destinationService, _logger)
{ Owner = this }; { Owner = this };
}
/// <summary> /// <summary>
/// Get destination for submission. /// Get destination for submission.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment