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

Added E2E Test for pre encrypted submission

parent 351d6b00
No related branches found
No related tags found
3 merge requests!18Feature/651 outsource crypto,!17Feature/638 xml data,!15Feature/580 encrypted data
using System.Threading.Channels;
using FitConnect;
using FitConnect.Encryption;
using FitConnect.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
......@@ -30,13 +31,30 @@ public static class SenderDemo {
var destinationId = config["FitConnect:Sender:DestinationId"];
var leikaKey = config["FitConnect:Sender:LeikaKey"];
FitEncryption encryption;
Dictionary<string, string>? encryptedAttachments = null;
string? encryptedMetadata = null;
string? encryptedData = null;
var sender = Client
.GetSender(FitConnectEnvironment.Testing, clientId, clientSecret, logger)
.WithDestination(destinationId, (key) => Console.WriteLine(key))
.WithServiceType("FIT Connect Demo", leikaKey)
.WithEncryptedAttachments(new Dictionary<string, string>())
.WithEncryptedMetaData("")
.WithEncryptedData("")
.WithDestination(destinationId,
(k) => {
logger?.LogInformation("Received public key: {Key}", k);
encryption = new FitEncryption(k, logger);
encryptedAttachments = new Dictionary<string, string>() { { "", "" } };
encryptedMetadata = "";
encryptedData = encryption.Encrypt("{\"message\":\"Hello World\"}");
});
// Return the public key to the JavaScript client
// Come back later with the encrypted data
sender.WithServiceType("FIT Connect Demo", leikaKey)
.WithEncryptedAttachments(encryptedAttachments)
.WithEncryptedMetaData(encryptedMetadata)
.WithEncryptedData(encryptedData)
.Submit();
}
}
......@@ -9,17 +9,17 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FitConnect\FitConnect.csproj"/>
<ProjectReference Include="..\MockContainer\MockContainer.csproj"/>
<ProjectReference Include="..\FitConnect\FitConnect.csproj" />
<ProjectReference Include="..\MockContainer\MockContainer.csproj" />
</ItemGroup>
</Project>
......@@ -22,7 +22,7 @@ public abstract class EndToEndTestBase {
Logger = LoggerFactory.Create(
builder => {
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
builder.SetMinimumLevel(LogLevel.Trace);
}).CreateLogger("E2E Test");
......
......@@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
namespace E2ETest;
[TestFixture]
public class StraightForwardTest : EndToEndTestBase {
private string _caseId = null!;
private string _submissionId = null!;
......@@ -47,7 +48,7 @@ public class StraightForwardTest : EndToEndTestBase {
status.ForEach(
s => Logger.LogInformation("Status {When} {Event}", s.EventTime, s.EventType));
}
[Test]
[Order(40)]
public void RequestSubmission() {
......
This diff is collapsed.
......@@ -8,6 +8,17 @@ namespace FitConnect;
public partial class Sender {
public IWithEncryptedAttachments WithEncryptedAttachments(
Dictionary<string, string> attachments) {
if (Submission?.ServiceType == null) {
Logger?.LogError("Submission has no service type");
throw new ArgumentException("Submission has no service type");
}
var createSubmissionDto = (CreateSubmissionDto)Submission;
createSubmissionDto.AnnouncedAttachments = attachments.Keys.ToList();
var created = SubmissionService.CreateSubmission(createSubmissionDto);
Submission.Id = created.SubmissionId;
Submission.CaseId = created.CaseId;
if (Submission?.Id == null)
throw new ArgumentException("Submission is not ready");
......
......@@ -49,6 +49,10 @@ public class FitEncryption {
PublicKeySignatureVerification = keySet.PublicKeySignatureVerification;
}
public FitEncryption(string publicKeyEncryption, ILogger? logger) : this(logger) {
PublicKeyEncryption = publicKeyEncryption;
}
public (string plainText, byte[] plainBytes, byte[] tag)
Decrypt(string cypherText, string key) {
......@@ -270,4 +274,4 @@ public class FitEncryption {
return result.IsValid;
}
}
\ No newline at end of file
}
......@@ -14,10 +14,4 @@ public interface ISenderWithAttachments : ISenderReady {
public ISenderWithData WithData(string data);
}
public interface ISenderWithEncryptedMetaData {
public ISenderWithEncryptedData WithEncryptedData(string data);
}
public interface ISenderWithEncryptedData {
public Submission Submit();
}
......@@ -30,3 +30,10 @@ public interface IWithEncryptedAttachments {
public ISenderWithEncryptedMetaData WithEncryptedMetaData(string metaData);
}
public interface ISenderWithEncryptedMetaData : ISenderWithEncryptedData {
public ISenderWithEncryptedData WithEncryptedData(string data);
}
public interface ISenderWithEncryptedData {
public Submission Submit();
}
......@@ -113,7 +113,7 @@ public static class Container {
subscriberClientId, subscriberClientSecret,
destinationId, leikaKey, callbackSecret, setPublicKeys);
}
catch (Exception e) {
catch {
Console.WriteLine("Files not found, using environment variables");
return null;
}
......
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