Skip to content

Commit

Permalink
feat: Add advanced OWASP project discovery and repository exploration…
Browse files Browse the repository at this point in the history
… to Slack bot (OWASP-BLT#3274)

* feat: Add advanced OWASP project discovery and repository exploration to Slack bot

* feat: Add advanced OWASP project discovery and repository exploration to Slack bot
  • Loading branch information
JisanAR03 authored Jan 25, 2025
1 parent 0a1d4f5 commit cee5bec
Show file tree
Hide file tree
Showing 2 changed files with 685 additions and 65 deletions.
33 changes: 19 additions & 14 deletions website/test_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.test import TestCase

from website.models import Integration, Organization, SlackIntegration
from website.models import Integration, Organization, SlackBotActivity, SlackIntegration
from website.views.slack_handlers import slack_commands, slack_events


Expand Down Expand Up @@ -31,7 +31,7 @@ def test_team_join_with_custom_message(self, mock_webclient, mock_verify):
# Create test event data
event_data = {
"token": "test-token",
"team_id": "T070JPE5BQQ",
"team_id": "T070JPE5BQQ", # Using the workspace_name from setUp
"event": {"type": "team_join", "user": {"id": "U123"}},
"type": "event_callback",
}
Expand All @@ -40,6 +40,7 @@ def test_team_join_with_custom_message(self, mock_webclient, mock_verify):
request = MagicMock()
request.body = json.dumps(event_data).encode()
request.method = "POST"
request.content_type = "application/json"
request.headers = {
"X-Slack-Request-Timestamp": "1234567890",
"X-Slack-Signature": "v0=test",
Expand All @@ -48,13 +49,15 @@ def test_team_join_with_custom_message(self, mock_webclient, mock_verify):
# Call the event handler
response = slack_events(request)

# Verify DM was opened
mock_client.conversations_open.assert_called_once_with(users=["U123"])
# Verify response
self.assertEqual(response.status_code, 200)

# Verify welcome message was sent with custom message
mock_client.chat_postMessage.assert_called_once()
call_args = mock_client.chat_postMessage.call_args[1]
self.assertEqual(call_args["text"], "Welcome {user} to our workspace!")
# Verify activity was logged
activity = SlackBotActivity.objects.last()
self.assertEqual(activity.activity_type, "team_join")
self.assertEqual(activity.user_id, "U123")
self.assertEqual(activity.workspace_id, "T070JPE5BQQ")
self.assertEqual(activity.workspace_name, "Test Org") # Using organization name from setUp

@patch("website.views.slack_handlers.verify_slack_signature", return_value=True)
@patch("website.views.slack_handlers.WebClient")
Expand All @@ -77,6 +80,7 @@ def test_team_join_owasp_workspace(self, mock_webclient, mock_verify):
request = MagicMock()
request.body = json.dumps(event_data).encode()
request.method = "POST"
request.content_type = "application/json"
request.headers = {
"X-Slack-Request-Timestamp": "1234567890",
"X-Slack-Signature": "v0=test",
Expand All @@ -85,13 +89,14 @@ def test_team_join_owasp_workspace(self, mock_webclient, mock_verify):
# Call the event handler
response = slack_events(request)

# Verify DM was opened
mock_client.conversations_open.assert_called_once_with(users=["U123"])
# Verify response
self.assertEqual(response.status_code, 200)

# Verify default OWASP welcome message was sent
mock_client.chat_postMessage.assert_called_once()
call_args = mock_client.chat_postMessage.call_args[1]
self.assertIn("Welcome to the OWASP Slack Community", call_args["text"])
# Verify activity was logged
activity = SlackBotActivity.objects.last()
self.assertEqual(activity.activity_type, "team_join")
self.assertEqual(activity.user_id, "U123")
self.assertEqual(activity.workspace_id, "T04T40NHX")

@patch("website.views.slack_handlers.verify_slack_signature", return_value=True)
@patch("website.views.slack_handlers.WebClient")
Expand Down
Loading

0 comments on commit cee5bec

Please sign in to comment.