-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag to enable subscription name validation
JMS 3.1 Spec "A.3.16. Subscription name characters and length" https://jakarta.ee/specifications/messaging/3.1/jakarta-messaging-spec-3.1.html#subscription-name-characters-and-length-2 The validation can be enabled with a flag, it's disabled by default, to avoid breaking existing code. The flag is RMQConnectionFactory#validateSubscriptionNames. References #180 Fixes #203
- Loading branch information
1 parent
197fddd
commit a073da5
Showing
10 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 VMware, Inc. or its affiliates. All rights reserved. | ||
|
||
package com.rabbitmq.jms.client; | ||
|
||
import java.util.function.Predicate; | ||
|
||
abstract class Utils { | ||
|
||
private Utils() { | ||
|
||
} | ||
|
||
static final Predicate<String> SUBSCRIPTION_NAME_PREDICATE = name -> { | ||
if (name == null) { | ||
return true; | ||
} | ||
if (name.length() > 128) { | ||
return false; | ||
} | ||
for (int i = 0; i < name.length(); i++) { | ||
char c = name.charAt(i); | ||
if (c != '_' && c != '.' && c != '-' && !Character.isLetter(c) && !Character.isDigit(c)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2022 VMware, Inc. or its affiliates. All rights reserved. | ||
|
||
package com.rabbitmq.jms.client; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
public class UtilsTest { | ||
|
||
@CsvSource({ | ||
"valid-subscription-name,true", | ||
"valid_subscription_name,true", | ||
"valid.subscription.name,true", | ||
"yet-another_valid.subscription.name,true", | ||
"invalid?subscription!name,false", | ||
"invalid(subscription)name,false", | ||
"invalid(subscription)name,false", | ||
"very.loooooooooooooooooooooooooooooooooooooooooooooooooooooooo" | ||
+ "ooooooooooooooooooooooooooooooooooooooooooooong.subscription.name,true", | ||
"too.loooooooooooooooooooooooooooooooooooooooooooooooooooooooo" | ||
+ "oooooooooooooooooooooooooooooooooooooooooooooooooooong.subscription.name,false", | ||
}) | ||
@ParameterizedTest | ||
void subscriptionNameValidation(String subscriptionName, boolean valid) { | ||
// https://jakarta.ee/specifications/messaging/3.1/jakarta-messaging-spec-3.1.html#subscription-name-characters-and-length | ||
assertThat(Utils.SUBSCRIPTION_NAME_PREDICATE.test(subscriptionName)).isEqualTo(valid); | ||
} | ||
} |