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

Checking leika key with regex

parent ccbb4b87
No related branches found
No related tags found
1 merge request!3Feature/440 mvp net sdk part 1
......@@ -212,6 +212,9 @@ public class FluentSender : Sender, IFluentSender, IFluentSenderWithDestination,
}
public IFluentSenderWithService WithServiceType(string serviceName, string leikaKey) {
if (!Regex.IsMatch(leikaKey, "^urn:[a-z0-9][a-z0-9-]{0,31}:[a-z0-9()+,.:=@;$_!*'%/?#-]+$"))
throw new ArgumentException("Invalid leika key");
Submission.ServiceType = new ServiceType() {
Name = serviceName,
Identifier = leikaKey
......
......@@ -2,6 +2,7 @@ using System;
using Autofac;
using FitConnect;
using FitConnect.Models;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using MockContainer;
using NUnit.Framework;
......@@ -30,11 +31,23 @@ public class FluentSenderTests {
logger: logger);
}
[Test]
public void FluentSender_ShouldNotThrowAnError_ArgumentExceptionLeikaKeyInvalid() {
Assert.Throws<ArgumentException>(() => {
_client.GetSender()
.WithDestination("destinationId")
.WithServiceType("", "")
.WithAttachments(Array.Empty<Attachment>())
.WithData("")
.Submit();
})!.Message.Should().Be("Invalid leika key");
}
[Test]
public void FluentSender_ShouldNotThrowAnError_MockingServicesWithData() {
_client.GetSender()
.WithDestination("destinationId")
.WithServiceType("","")
.WithServiceType("", "urn:de:fim:leika:leistung:99400048079000")
.WithAttachments(Array.Empty<Attachment>())
.WithData("")
.Submit();
......@@ -44,7 +57,7 @@ public class FluentSenderTests {
public void FluentSender_ShouldNotThrowAnError_MockingServicesWithoutData() {
_client.GetSender()
.WithDestination("destinationId")
.WithServiceType("","")
.WithServiceType("", "urn:de:fim:leika:leistung:99400048079000")
.WithAttachments(Array.Empty<Attachment>())
.Submit();
}
......
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