-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add webhook domain exclusion config for notification channels #172
Merged
pavan-traceable
merged 5 commits into
main
from
domain-exclusion-notification-channel-config
Jul 20, 2023
+240
−9
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5322048
Add webhook domain exclusion config for notification channels
pavan-traceable 3954272
Add validations for webhook urls
pavan-traceable 97489d7
Updated tests
pavan-traceable d410f6c
Fix vulnerabilities
pavan-traceable c560380
Fix vulnerability
pavan-traceable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
92 changes: 92 additions & 0 deletions
92
...ace/notification/config/service/NotificationChannelConfigServiceRequestValidatorTest.java
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,92 @@ | ||
package org.hypertrace.notification.config.service; | ||
|
||
import static org.hypertrace.notification.config.service.NotificationChannelConfigServiceImpl.NOTIFICATION_CHANNEL_CONFIG_SERVICE_CONFIG; | ||
import static org.hypertrace.notification.config.service.NotificationChannelConfigServiceRequestValidator.WEBHOOK_HTTP_SUPPORT_ENABLED; | ||
|
||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
import com.typesafe.config.ConfigValueFactory; | ||
import java.io.File; | ||
import org.hypertrace.notification.config.service.v1.NotificationChannelMutableData; | ||
import org.hypertrace.notification.config.service.v1.WebhookChannelConfig; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class NotificationChannelConfigServiceRequestValidatorTest { | ||
@Test | ||
public void testValidateWebhookExclusions() { | ||
NotificationChannelConfigServiceRequestValidator | ||
notificationChannelConfigServiceRequestValidator = | ||
new NotificationChannelConfigServiceRequestValidator(); | ||
File configFile = new File(ClassLoader.getSystemResource("application.conf").getPath()); | ||
Config config = ConfigFactory.parseFile(configFile); | ||
NotificationChannelMutableData notificationChannelMutableDataWithExcludedDomain = | ||
getNotificationChannelMutableData("http://localhost:9000/test"); | ||
Assertions.assertThrows( | ||
RuntimeException.class, | ||
() -> { | ||
notificationChannelConfigServiceRequestValidator.validateWebhookConfigExclusionDomains( | ||
notificationChannelMutableDataWithExcludedDomain, | ||
config.getConfig(NOTIFICATION_CHANNEL_CONFIG_SERVICE_CONFIG)); | ||
}, | ||
"RuntimeException was expected"); | ||
NotificationChannelMutableData notificationChannelMutableDataWithValidDomain = | ||
getNotificationChannelMutableData("http://testHost:9000/test"); | ||
notificationChannelConfigServiceRequestValidator.validateWebhookConfigExclusionDomains( | ||
notificationChannelMutableDataWithValidDomain, | ||
config.getConfig(NOTIFICATION_CHANNEL_CONFIG_SERVICE_CONFIG)); | ||
} | ||
|
||
@Test | ||
public void testValidateWebhookHttpsSupport() { | ||
NotificationChannelConfigServiceRequestValidator | ||
notificationChannelConfigServiceRequestValidator = | ||
new NotificationChannelConfigServiceRequestValidator(); | ||
File configFile = new File(ClassLoader.getSystemResource("application.conf").getPath()); | ||
Config config = ConfigFactory.parseFile(configFile); | ||
Config notificationChannelConfig = config.getConfig(NOTIFICATION_CHANNEL_CONFIG_SERVICE_CONFIG); | ||
NotificationChannelMutableData notificationChannelWithHttpUrl = | ||
getNotificationChannelMutableData("http://localhost:9000/test"); | ||
// As http support disabled RuntimeException should be thrown. | ||
Assertions.assertThrows( | ||
RuntimeException.class, | ||
() -> { | ||
notificationChannelConfigServiceRequestValidator.validateWebhookHttpSupport( | ||
notificationChannelWithHttpUrl, notificationChannelConfig); | ||
}, | ||
"RuntimeException was expected"); | ||
|
||
// In valid URl not accepted | ||
NotificationChannelMutableData notificationChannelWithInvalidUrl = | ||
getNotificationChannelMutableData("localhost"); | ||
Assertions.assertThrows( | ||
RuntimeException.class, | ||
() -> { | ||
notificationChannelConfigServiceRequestValidator.validateWebhookHttpSupport( | ||
notificationChannelWithInvalidUrl, notificationChannelConfig); | ||
}, | ||
"RuntimeException was expected"); | ||
|
||
// Valid webhook config with https url. | ||
NotificationChannelMutableData notificationChannelMutableDataWithHttpsUrl = | ||
getNotificationChannelMutableData("https://localhost:9000/test"); | ||
notificationChannelConfigServiceRequestValidator.validateWebhookHttpSupport( | ||
notificationChannelMutableDataWithHttpsUrl, notificationChannelConfig); | ||
|
||
// Update config with http support enabled and verify no exceptions for http url | ||
Config updatedNotificationChannelConfig = | ||
config.withValue(WEBHOOK_HTTP_SUPPORT_ENABLED, ConfigValueFactory.fromAnyRef("true")); | ||
|
||
NotificationChannelMutableData notificationChannelMutableDataWithHttpUrl = | ||
getNotificationChannelMutableData("http://localhost:9000/test"); | ||
notificationChannelConfigServiceRequestValidator.validateWebhookHttpSupport( | ||
notificationChannelMutableDataWithHttpUrl, updatedNotificationChannelConfig); | ||
} | ||
|
||
private static NotificationChannelMutableData getNotificationChannelMutableData(String url) { | ||
return NotificationChannelMutableData.newBuilder() | ||
.setChannelName("testChannel") | ||
.addWebhookChannelConfig(WebhookChannelConfig.newBuilder().setUrl(url)) | ||
.build(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
notification-channel-config-service-impl/src/test/resources/application.conf
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,4 @@ | ||
notification.channel.config.service { | ||
webhook.exclusion.domains = ["localhost"] | ||
webhook.http.support.enabled = false | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Added validation for https support