Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FIT-Connect-SDK - .NET
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FIT-Connect
FIT-Connect-SDK - .NET
Commits
da89f0ca
Commit
da89f0ca
authored
1 year ago
by
Klaus Fischer
Browse files
Options
Downloads
Patches
Plain Diff
fix: added exception if invalid json keys are passed
parent
93f77aa8
No related branches found
Branches containing commit
No related tags found
1 merge request
!91
Feature/1308 attachment from string
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
FitConnect/ClientFactory.cs
+25
-0
25 additions, 0 deletions
FitConnect/ClientFactory.cs
Tests/BasicUnitTest/SubscriberTests.cs
+55
-0
55 additions, 0 deletions
Tests/BasicUnitTest/SubscriberTests.cs
with
80 additions
and
0 deletions
FitConnect/ClientFactory.cs
+
25
−
0
View file @
da89f0ca
...
...
@@ -4,6 +4,7 @@ using FitConnect.Interfaces;
using
FitConnect.Interfaces.Subscriber
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.IdentityModel.Logging
;
using
Newtonsoft.Json.Linq
;
namespace
FitConnect
;
...
...
@@ -47,6 +48,9 @@ public static class ClientFactory {
List
<
string
>
privateDecryptionKeys
,
string
privateSigningKey
,
ILogger
?
logger
=
null
)
{
CheckKeysForValidJsonFormat
(
privateDecryptionKeys
,
privateSigningKey
);
if
(
privateDecryptionKeys
.
Count
!=
1
)
throw
new
FitConnectInitialisationException
(
"Only one private key for decryption is supported"
);
...
...
@@ -61,6 +65,27 @@ public static class ClientFactory {
}
private
static
void
CheckKeysForValidJsonFormat
(
List
<
string
>
privateDecryptionKeys
,
string
privateSigningKey
)
{
foreach
(
var
key
in
privateDecryptionKeys
)
{
try
{
var
json
=
JObject
.
Parse
(
key
);
}
catch
(
Exception
e
)
{
throw
new
FitConnectInitialisationException
(
"Private decryption key is not in valid JSON format"
,
e
);
}
}
try
{
var
json
=
JObject
.
Parse
(
privateSigningKey
);
}
catch
(
Exception
e
)
{
throw
new
FitConnectInitialisationException
(
"Private signing key is not in valid JSON format"
,
e
);
}
}
/// <summary>
/// Returns a Router API implementation
/// </summary>
...
...
This diff is collapsed.
Click to expand it.
Tests/BasicUnitTest/SubscriberTests.cs
0 → 100644
+
55
−
0
View file @
da89f0ca
using
System
;
using
System.Collections.Generic
;
using
Autofac
;
using
FitConnect
;
using
FitConnect.Exceptions
;
using
FitConnect.Interfaces
;
using
FluentAssertions
;
using
NUnit.Framework
;
namespace
BasicUnitTest
;
[
TestFixture
]
public
class
SubscriberTests
{
IFitConnectSettings
_settings
=
null
!;
[
SetUp
]
public
void
Setup
()
{
var
container
=
MockContainer
.
Container
.
Create
();
_settings
=
container
.
Resolve
<
IFitConnectSettings
>();
}
[
Test
]
public
void
CreateSubscriber_ShouldPass
()
{
// Arrange
var
clientId
=
Guid
.
NewGuid
().
ToString
();
var
clientSecret
=
"VerySecret"
;
var
privateDecryptionKeys
=
_settings
.
PrivateDecryptionKeys
;
var
publicKey
=
_settings
.
PrivateSigningKey
;
// Act
var
subscriber
=
FitConnect
.
ClientFactory
.
GetSubscriberClient
(
FitConnectEnvironment
.
Test
,
clientId
,
clientSecret
,
privateDecryptionKeys
,
publicKey
);
// Assert
subscriber
.
Should
().
NotBeNull
();
}
[
Test
]
public
void
CreateSubscriber_InvalidKeys_ShouldFail
()
{
// Arrange
var
clientId
=
Guid
.
NewGuid
().
ToString
();
var
clientSecret
=
"VerySecret"
;
var
privateDecryptionKeys
=
new
List
<
string
>()
{
"C:\\temp.key"
};
var
publicKey
=
"C:\\temp.key"
;
// Act & Assert
var
exception
=
Assert
.
Throws
<
FitConnectInitialisationException
>(()
=>
{
var
subscriber
=
FitConnect
.
ClientFactory
.
GetSubscriberClient
(
FitConnectEnvironment
.
Test
,
clientId
,
clientSecret
,
privateDecryptionKeys
,
publicKey
);
});
Console
.
WriteLine
(
exception
?.
Message
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment