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
26d26e84
Commit
26d26e84
authored
2 years ago
by
Klaus Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Resolved annotations from review
parent
c8f4ef8c
No related branches found
No related tags found
1 merge request
!4
Feature/563 check callback
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
FitConnect/Subscriber.cs
+1
-1
1 addition, 1 deletion
FitConnect/Subscriber.cs
IntegrationTests/CallbackTest.cs
+7
-11
7 additions, 11 deletions
IntegrationTests/CallbackTest.cs
with
8 additions
and
12 deletions
FitConnect/Subscriber.cs
+
1
−
1
View file @
26d26e84
...
@@ -234,7 +234,7 @@ public class Subscriber : FitConnectClient,
...
@@ -234,7 +234,7 @@ public class Subscriber : FitConnectClient,
var
result
=
VerifyCallback
(
callbackSecret
,
timestamp
,
content
);
var
result
=
VerifyCallback
(
callbackSecret
,
timestamp
,
content
);
if
(
result
!=
authentication
)
if
(
result
!=
authentication
)
throw
new
ArgumentException
(
"
R
equest
i
s not authentic"
);
throw
new
ArgumentException
(
"
Verified r
equest
doe
s not
match
authentic
ation
"
);
return
true
;
return
true
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
IntegrationTests/CallbackTest.cs
+
7
−
11
View file @
26d26e84
...
@@ -17,7 +17,7 @@ namespace IntegrationTests;
...
@@ -17,7 +17,7 @@ namespace IntegrationTests;
[
TestFixture
]
[
TestFixture
]
public
class
CallbackTest
{
public
class
CallbackTest
{
private
HttpRequest
R
equest
;
private
HttpRequest
_r
equest
=
null
!
;
private
string
_callbackSecret
=
""
;
private
string
_callbackSecret
=
""
;
[
SetUp
]
[
SetUp
]
...
@@ -30,10 +30,6 @@ public class CallbackTest {
...
@@ -30,10 +30,6 @@ public class CallbackTest {
streamWriter
.
Flush
();
streamWriter
.
Flush
();
memoryStream
.
Position
=
0
;
memoryStream
.
Position
=
0
;
// Request = new DefaultHttpRequest(new DefaultHttpContext()) {
// Body = new StreamBody(memoryStream)
// };
var
headers
=
new
HeaderDictionary
(
new
Dictionary
<
string
,
StringValues
>()
{
var
headers
=
new
HeaderDictionary
(
new
Dictionary
<
string
,
StringValues
>()
{
{
"callback-timestamp"
,
"1672527599"
},
{
{
"callback-timestamp"
,
"1672527599"
},
{
"callback-authentication"
,
"callback-authentication"
,
...
@@ -49,7 +45,7 @@ public class CallbackTest {
...
@@ -49,7 +45,7 @@ public class CallbackTest {
mock
.
Setup
(
w
=>
w
.
Method
).
Returns
(
"POST"
);
mock
.
Setup
(
w
=>
w
.
Method
).
Returns
(
"POST"
);
mock
.
Setup
(
w
=>
w
.
Body
).
Returns
(
memoryStream
);
mock
.
Setup
(
w
=>
w
.
Body
).
Returns
(
memoryStream
);
R
equest
=
mock
.
Object
;
_r
equest
=
mock
.
Object
;
_callbackSecret
=
MockContainer
.
Container
.
Create
().
Resolve
<
MockSettings
>().
CallbackSecret
;
_callbackSecret
=
MockContainer
.
Container
.
Create
().
Resolve
<
MockSettings
>().
CallbackSecret
;
}
}
...
@@ -72,18 +68,18 @@ public class CallbackTest {
...
@@ -72,18 +68,18 @@ public class CallbackTest {
[
Test
]
[
Test
]
public
void
ValidRequest
()
{
public
void
ValidRequest
()
{
// Assert
// Assert
FitConnect
.
Subscriber
.
VerifyCallback
(
_callbackSecret
,
R
equest
).
Should
().
Be
(
true
);
FitConnect
.
Subscriber
.
VerifyCallback
(
_callbackSecret
,
_r
equest
).
Should
().
Be
(
true
);
}
}
[
Test
]
[
Test
]
public
void
RequestAge_Fails
()
{
public
void
RequestAge_Fails
()
{
// Arrange
// Arrange
R
equest
.
Headers
[
"callback-timestamp"
]
=
"1641066653"
;
_r
equest
.
Headers
[
"callback-timestamp"
]
=
"1641066653"
;
// Atc
// Atc
// Assert
// Assert
Assert
.
Throws
<
ArgumentException
>(()
=>
{
Assert
.
Throws
<
ArgumentException
>(()
=>
{
FitConnect
.
Subscriber
.
VerifyCallback
(
_callbackSecret
,
R
equest
);
FitConnect
.
Subscriber
.
VerifyCallback
(
_callbackSecret
,
_r
equest
);
})
})
.
Message
.
Should
().
Be
(
"Request is too old"
);
.
Message
.
Should
().
Be
(
"Request is too old"
);
}
}
...
@@ -91,13 +87,13 @@ public class CallbackTest {
...
@@ -91,13 +87,13 @@ public class CallbackTest {
[
Test
]
[
Test
]
public
void
RequestAuthentication_Fails
()
{
public
void
RequestAuthentication_Fails
()
{
// Arrange
// Arrange
R
equest
.
Headers
[
"callback-authentication"
]
=
_r
equest
.
Headers
[
"callback-authentication"
]
=
"898cd0edb70c08e5b32aa8a18cbbc8ff6b3078c51af6d011ff4e32e470c746234fc4314821fe5185264b029e962bd37de33f3b9fc5f1a93c40ce6672845e90df"
;
"898cd0edb70c08e5b32aa8a18cbbc8ff6b3078c51af6d011ff4e32e470c746234fc4314821fe5185264b029e962bd37de33f3b9fc5f1a93c40ce6672845e90df"
;
// Atc
// Atc
// Assert
// Assert
Assert
.
Throws
<
ArgumentException
>(()
=>
{
Assert
.
Throws
<
ArgumentException
>(()
=>
{
FitConnect
.
Subscriber
.
VerifyCallback
(
_callbackSecret
,
R
equest
);
FitConnect
.
Subscriber
.
VerifyCallback
(
_callbackSecret
,
_r
equest
);
})
})
.
Message
.
Should
().
Be
(
"Request is not authentic"
);
.
Message
.
Should
().
Be
(
"Request is not authentic"
);
}
}
...
...
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