Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
9e92160e
Commit
9e92160e
authored
May 28, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add subscription name validation for the AzureServerBus. (#344)
parent
93ab8c6f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
1 deletion
+42
-1
AzureServiceBusConsumerClient.cs
...Core.CAP.AzureServiceBus/AzureServiceBusConsumerClient.cs
+42
-1
No files found.
src/DotNetCore.CAP.AzureServiceBus/AzureServiceBusConsumerClient.cs
View file @
9e92160e
...
...
@@ -52,6 +52,8 @@ namespace DotNetCore.CAP.AzureServiceBus
foreach
(
var
newRule
in
topics
.
Except
(
allRuleNames
))
{
CheckValidSubscriptionName
(
newRule
);
_consumerClient
.
AddRuleAsync
(
new
RuleDescription
{
Filter
=
new
CorrelationFilter
{
Label
=
newRule
},
...
...
@@ -99,7 +101,7 @@ namespace DotNetCore.CAP.AzureServiceBus
public
void
Dispose
()
{
_consumerClient
.
CloseAsync
().
Wait
(
);
_consumerClient
?.
CloseAsync
().
Wait
(
1500
);
}
#
region
private
methods
...
...
@@ -168,6 +170,45 @@ namespace DotNetCore.CAP.AzureServiceBus
return
Task
.
CompletedTask
;
}
private
static
void
CheckValidSubscriptionName
(
string
subscriptionName
)
{
const
string
pathDelimiter
=
@"/"
;
const
int
ruleNameMaximumLength
=
50
;
char
[]
invalidEntityPathCharacters
=
{
'@'
,
'?'
,
'#'
,
'*'
};
if
(
string
.
IsNullOrWhiteSpace
(
subscriptionName
))
{
throw
new
ArgumentNullException
(
subscriptionName
);
}
// and "\" will be converted to "/" on the REST path anyway. Gateway/REST do not
// have to worry about the begin/end slash problem, so this is purely a client side check.
var
tmpName
=
subscriptionName
.
Replace
(
@"\"
,
pathDelimiter
);
if
(
tmpName
.
Length
>
ruleNameMaximumLength
)
{
throw
new
ArgumentOutOfRangeException
(
subscriptionName
,
$@"Subscribe name '
{
subscriptionName
}
' exceeds the '
{
ruleNameMaximumLength
}
' character limit."
);
}
if
(
tmpName
.
StartsWith
(
pathDelimiter
,
StringComparison
.
OrdinalIgnoreCase
)
||
tmpName
.
EndsWith
(
pathDelimiter
,
StringComparison
.
OrdinalIgnoreCase
))
{
throw
new
ArgumentException
(
$@"The subscribe name cannot contain '/' as prefix or suffix. The supplied value is '
{
subscriptionName
}
'"
,
subscriptionName
);
}
if
(
tmpName
.
Contains
(
pathDelimiter
))
{
throw
new
ArgumentException
(
$@"The subscribe name contains an invalid character '
{
pathDelimiter
}
'"
,
subscriptionName
);
}
foreach
(
var
uriSchemeKey
in
invalidEntityPathCharacters
)
{
if
(
subscriptionName
.
IndexOf
(
uriSchemeKey
)
>=
0
)
{
throw
new
ArgumentException
(
$@"'
{
subscriptionName
}
' contains character '
{
uriSchemeKey
}
' which is not allowed because it is reserved in the Uri scheme."
,
subscriptionName
);
}
}
}
#
endregion
private
methods
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment