Skip to content

Commit a4a902f

Browse files
Regex from eiffel-commons to validate subscription (#216)
* taking regEx from common for subscription validation * putting regexes code in global-variables.js as methods
1 parent 4490a70 commit a4a902f

File tree

7 files changed

+23
-18
lines changed

7 files changed

+23
-18
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
<dependency>
176176
<groupId>com.github.eiffel-community</groupId>
177177
<artifactId>eiffel-commons</artifactId>
178-
<version>0.0.6</version>
178+
<version>0.0.9</version>
179179
</dependency>
180180
</dependencies>
181181

src/main/java/com/ericsson/ei/frontend/WebController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
import org.springframework.web.bind.annotation.RequestMapping;
2525

2626
import com.ericsson.ei.frontend.utils.WebControllerUtils;
27+
import com.ericsson.eiffelcommons.utils.RegExProvider;
2728

2829
@Controller
2930
public class WebController {
3031

3132
@Autowired
3233
private WebControllerUtils frontEndUtils;
3334

35+
3436
@RequestMapping("/")
3537
public String greeting(Model model) {
3638
model.addAttribute("frontendServiceUrl", frontEndUtils.getFrontEndServiceUrl());
39+
model.addAttribute("subscriptionNameRegex", RegExProvider.SUBSCRIPTION_NAME);
40+
model.addAttribute("notificationMetaRegex", RegExProvider.NOTIFICATION_META);
3741
String eiffelDocumentationUrlLinks = String.format("%s", frontEndUtils.getEiffelDocumentationUrls());
3842
model.addAttribute("eiffelDocumentationUrlLinks", eiffelDocumentationUrlLinks);
3943
return "index";

src/main/java/com/ericsson/ei/frontend/utils/WebControllerUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,4 @@ public String getBackEndServiceUrl(HttpSession httpSession) {
112112

113113
return backEndInformation.getUrlAsString();
114114
}
115-
116115
}

src/main/resources/static/js/global-variables.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var frontendServiceUrl = $('#frontendServiceUrl').text();
33
var frontendServiceBackEndPath = "/backend";
44
var ldapEnabled = true;
55
var table;
6+
var subscriptionNameRegex = $('#subscriptionNameRegex').text();
7+
var notificationMetaRegex = $('#notificationMetaRegex').text();
68

79
var backendEndpoints = {
810
AUTH: "/auth",
@@ -100,4 +102,12 @@ function getWhiteListedPages() {
100102
return String(PAGES_FOR_STATUS_INDICATION);
101103
}
102104

105+
function getSubscriptionNameRegex() {
106+
return subscriptionNameRegex;
107+
}
108+
109+
function getNotificationMetaRegex() {
110+
return notificationMetaRegex;
111+
}
112+
103113
// End ## getters and setters status handling

src/main/resources/static/js/subscription.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var defaultFormKeyValuePairAuth = { "formkey": "Authorization", "formvalue": ""
66
jQuery(document).ready(function () {
77

88
$('.modal-dialog').draggable({ handle: ".modal-header", cursor: 'move' });
9-
9+
1010
checkBackendStatus();
1111

1212
function loadSubButtons() {
@@ -754,16 +754,10 @@ jQuery(document).ready(function () {
754754
$('#invalidSubscriptionName').text("SubscriptionName must not be empty");
755755
$('#subscriptionNameInput').addClass("is-invalid");
756756
error = true;
757-
}
758-
759-
// When this regExp need to be changed then remember to change the one in the
760-
// back-end (invalidSubscriptionNameRegex in SubscriptionValidator.java), which do the same
761-
// invalid subscription name check. The two
762-
// regEx always need to be the same for ensuring the same check.
763-
// /(\W)/ Is a regex that matches anything that is not [A-Z,a-z,0-8] and _.
764-
var invalidSubscriptionNameRegex = "(\W)";
757+
}
758+
// This regular expression is fetched from the Eiffel-Commons. It is same for both front-end and back-end
765759
var regExpressionFlag = "g";
766-
var regExpression = new RegExp(invalidSubscriptionNameRegex, regExpressionFlag);
760+
var regExpression = new RegExp(getSubscriptionNameRegex(), regExpressionFlag);
767761
if ((regExpression.test(subscriptionName))) {
768762
var invalidLetters = subscriptionName.match(regExpression);
769763
$('#invalidSubscriptionName').text(
@@ -796,11 +790,8 @@ jQuery(document).ready(function () {
796790
var emails = notificationMeta.split(",");
797791
emails.forEach(function(email){
798792
email = email.trim();
799-
// When this regExp need to be changed then remember to change the one in the
800-
// back-end (validEmailRegExpression in SubscriptionValidator.java), which do the same
801-
// email validation check. The two
802-
// regEx always need to be the same for ensuring the same check.
803-
var validEmailRegExpression = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
793+
// This regular expression is fetched from the Eiffel-Commons. It is same for both front-end and back-end
794+
var validEmailRegExpression = new RegExp(getNotificationMetaRegex());
804795
var isValidEmailAddress = validEmailRegExpression.test(email);
805796
if (!isValidEmailAddress) {
806797
$('#invalidNotificationMeta').text(email + " not a valid email.");

src/main/resources/templates/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<body>
2323
<div class="d-none" id="eiffelDocumentationUrlLinks" th:text="${eiffelDocumentationUrlLinks}"></div>
2424
<div class="d-none" id="frontendServiceUrl" th:text="${frontendServiceUrl}"></div>
25+
<div class="d-none" id="subscriptionNameRegex" th:text="${subscriptionNameRegex}"></div>
26+
<div class="d-none" id="notificationMetaRegex" th:text="${notificationMetaRegex}"></div>
2527
<header class="app-header">
2628
<a class="navbar-logo" href="#">
2729
<img src="assets/images/favicon-32x32.png" width="32" height="32" alt="EI Logo">

src/test/java/com/ericsson/ei/frontend/WebControllerUtilsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ public void testGetFrontEndServiceUrl() throws Exception {
3838
controllerUtils = new WebControllerUtils(HOST, PORT, CONTEXT_PATH, false, null, null, null, null, null);
3939
assertEquals(expectedUrl, controllerUtils.getFrontEndServiceUrl());
4040
}
41-
4241
}

0 commit comments

Comments
 (0)