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

Loading key in Tests

parent 50ac12d6
No related branches found
No related tags found
1 merge request!9.NET-SDK: SET-Empfang inkl. Signaturprüfung - Ticket 562
FitConnect
\ No newline at end of file
......@@ -21,7 +21,7 @@ public class CertificateHelper {
var certificates = key.X5c.Select(s => new X509Certificate2(Convert.FromBase64String(s)))
.ToList();
var root = new X509Certificate2("./certificates/root.pem");
X509Certificate2? root = null; //new X509Certificate2("./certificates/root.pem");
_logger?.LogTrace("Found {Count} certificate(s)", certificates.Count);
......
......@@ -4,25 +4,32 @@ public class FitConnectEnvironment {
// List of Domains
// https://wiki.fit-connect.fitko.dev/de/Betrieb/Dokumentation/Domains
public static readonly FitConnectEnvironment Develop = new(
"https://auth-dev.fit-connect.fitko.dev/token",
new[] { "https://submission-api-dev.fit-connect.fitko.dev" },
string.Empty, // "https://routing-api-testing.fit-connect.fitko.dev", // Dev does not have a routing API
"https://portal.auth-dev.fit-connect.fitko.dev"
) { VerifiedKeysAreMandatory = false };
public static readonly FitConnectEnvironment Testing = new(
"https://auth-testing.fit-connect.fitko.dev/token",
new[] { "https://submission-api-testing.fit-connect.fitko.dev" },
"https://routing-api-testing.fit-connect.fitko.dev",
"https://portal.auth-testing.fit-connect.fitko.dev"
){VerifiedKeysAreMandatory = false};
) { VerifiedKeysAreMandatory = false };
public static readonly FitConnectEnvironment Staging = new(
"https://auth-testing.fit-connect.fitko.dev/token",
new[] { "https://submission-api-testing.fit-connect.fitko.dev" },
"https://routing-api-testing.fit-connect.fitko.dev",
"https://portal.auth-testing.fit-connect.fitko.dev"
"https://auth-refz.fit-connect.fitko.net/token",
new[] { "submission-api-refz.fit-connect.niedersachsen.de" },
string.Empty, // "https://routing-api-testing.fit-connect.fitko.dev", // Stage does not have a routing API
"https://portal.auth-refz.fit-connect.fitko.net"
);
public static readonly FitConnectEnvironment Production = new(
"https://auth.fit-connect.fitko.net/token",
new[] { "https://submission-api.fit-connect.fitko.net" },
"https://routing-api.fit-connect.fitko.net",
"https://portal.auth.fit-connect.fitko.net"
"https://auth-prod.fit-connect.fitko.net/token",
new[] { "https://submission-api-prod.fit-connect.niedersachsen.de" },
"https://routing-api-prod.fit-connect.fitko.net",
"https://portal.auth-prod.fit-connect.fitko.net"
);
public FitConnectEnvironment(string sspUrl, string tokenUrl, string[] submissionUrl,
......
......@@ -181,7 +181,7 @@ public class Sender : FitConnectClient, ISender, ISenderWithDestination,
return submission;
}
private async Task<string> GetPublicKeyFromDestination(string destinationId) {
internal async Task<string> GetPublicKeyFromDestination(string destinationId) {
var publicKey = await DestinationService.GetPublicKey(destinationId);
var keyIsValid = new CertificateHelper(Logger).ValidateCertificate(publicKey,
......
......@@ -39,6 +39,19 @@ public class CertificateValidation {
_certificateHelper = new CertificateHelper(_logger);
}
[Test]
public void CheckCertificateInEnvironment_Dev() {
var environment = FitConnectEnvironment.Develop;
var sender = Client.GetSender(environment, _settings.SenderClientId,
_settings.SenderClientSecret,
_logger);
var certificate = (sender as FitConnect.Sender)
.GetPublicKeyFromDestination(_settings.DestinationId).Result;
new CertificateHelper(_logger).ValidateCertificate(JsonWebKey.Create(certificate),
LogLevel.Trace);
}
[Test]
public void CheckCertificateInEnvironment_Testing() {
var environment = FitConnectEnvironment.Testing;
......@@ -46,10 +59,10 @@ public class CertificateValidation {
_settings.SenderClientSecret,
_logger);
sender.WithDestination(_settings.DestinationId)
.WithServiceType("", _settings.LeikaKey)
.WithAttachments(new Attachment("Test.pdf", "Simple Test PDF"))
.Submit();
var certificate = (sender as FitConnect.Sender)
.GetPublicKeyFromDestination(_settings.DestinationId).Result;
new CertificateHelper(_logger).ValidateCertificate(JsonWebKey.Create(certificate),
LogLevel.Trace);
}
[Test]
......@@ -67,6 +80,21 @@ public class CertificateValidation {
}).InnerExceptions.Any(e => e.GetType() == typeof(SecurityException));
}
[Test]
public void CheckCertificateInEnvironment_Production() {
var environment = FitConnectEnvironment.Production;
var sender = Client.GetSender(environment, _settings.SenderClientId,
_settings.SenderClientSecret,
_logger);
Assert.Throws<AggregateException>(() => {
sender.WithDestination(_settings.DestinationId)
.WithServiceType("", _settings.LeikaKey)
.WithAttachments(new Attachment("Test.pdf", "Simple Test PDF"))
.Submit();
}).InnerExceptions.Any(e => e.GetType() == typeof(SecurityException));
}
[Test]
public void CheckPublicKeyEncryption() {
_certificateHelper.ValidateCertificate(new JsonWebKey(_settings.PublicKeyEncryption))
......
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