Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 85ed746

Browse files
committedJul 21, 2023
Fix validation
1 parent 1ef3c14 commit 85ed746

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎src/main/java/com/ionos/go/plugin/notifier/ValidateConfigurationHandler.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,17 @@ private void validateCondition(ValidateConfigurationRequest validateRequest, Lis
140140
response.add(new ValidateConfigurationResponse(Constants.PARAM_CONDITION, Constants.PARAM_CONDITION + " is empty"));
141141
} else {
142142
try {
143+
String nonTrueOrFalse = null;
143144
TemplateHandler handler = new TemplateHandler(Constants.PARAM_CONDITION, condition);
144145
for (StageStatusRequest sample : newSampleStageStatusRequests()) {
145146
String shouldBeBool = handler.eval(sample, serverInfo);
146147
if (!(shouldBeBool.equals("true") || shouldBeBool.equals("false"))) {
147-
response.add(new ValidateConfigurationResponse(Constants.PARAM_CONDITION, "Condition should eval to true or false, but evals to: " + shouldBeBool));
148+
nonTrueOrFalse = shouldBeBool;
148149
}
149150
}
151+
if (nonTrueOrFalse != null) {
152+
response.add(new ValidateConfigurationResponse(Constants.PARAM_CONDITION, "Condition should eval to true or false, but evals to: " + nonTrueOrFalse));
153+
}
150154
}
151155
catch (Exception e) {
152156
LOGGER.warn("Exception in " + Constants.PARAM_CONDITION, e);

‎src/test/java/com/ionos/go/plugin/notifier/GoNotifierPluginValidateConfigurationTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ public void testHandleValidateConfigurationWithConditionAccessingUndefinedProper
121121
assertEquals(Constants.PARAM_CONDITION, validateConfigurationResponses[0].getKey());
122122
}
123123

124+
@Test
125+
public void testHandleValidateConfigurationWithConditionNotTrueOrFalse() {
126+
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
127+
pluginSettings.put(Constants.PARAM_CONDITION, Collections.singletonMap(Constants.FIELD_VALUE, "tralse"));
128+
request.setPluginSettings(pluginSettings);
129+
GoPluginApiResponse response = getGoNotifierPlugin().handle(
130+
GoCdObjects.request(Constants.PLUGIN_VALIDATE_CONFIGURATION, getGson().toJson(request)));
131+
assertNotNull(response);
132+
assertEquals(HttpStatus.SC_OK, response.responseCode());
133+
assertEquals(Collections.emptyMap(), response.responseHeaders());
134+
ValidateConfigurationResponse[] validateConfigurationResponses = getGson().fromJson(response.responseBody(), ValidateConfigurationResponse[].class);
135+
assertEquals(1, validateConfigurationResponses.length);
136+
assertEquals(Constants.PARAM_CONDITION, validateConfigurationResponses[0].getKey());
137+
assertTrue("Should contain 'true or false'", validateConfigurationResponses[0].getMessage().contains("true or false"));
138+
}
139+
124140
@Test
125141
public void testHandleValidateConfigurationWithMalformedProxyUrl() {
126142
Map<String, Map<String, String>> pluginSettings = newGoodPluginSettingsTemplate();
@@ -134,6 +150,7 @@ public void testHandleValidateConfigurationWithMalformedProxyUrl() {
134150
ValidateConfigurationResponse[] validateConfigurationResponses = getGson().fromJson(response.responseBody(), ValidateConfigurationResponse[].class);
135151
assertEquals(1, validateConfigurationResponses.length);
136152
assertEquals(Constants.PARAM_PROXY_URL, validateConfigurationResponses[0].getKey());
153+
assertEquals("Malformed url: unknown protocol: hppt", validateConfigurationResponses[0].getMessage());
137154
}
138155

139156
@Test
@@ -149,5 +166,6 @@ public void testHandleValidateConfigurationWithMalformedWebhookUrl() {
149166
ValidateConfigurationResponse[] validateConfigurationResponses = getGson().fromJson(response.responseBody(), ValidateConfigurationResponse[].class);
150167
assertEquals(1, validateConfigurationResponses.length);
151168
assertEquals(Constants.PARAM_WEBHOOK_URL, validateConfigurationResponses[0].getKey());
169+
assertEquals("Malformed url: unknown protocol: hppt", validateConfigurationResponses[0].getMessage());
152170
}
153171
}

0 commit comments

Comments
 (0)