2
2
3
3
from sentry .models .identity import Identity , IdentityStatus
4
4
from sentry .silo import SiloMode
5
- from sentry .silo .util import PROXY_BASE_URL_HEADER , PROXY_OI_HEADER , PROXY_SIGNATURE_HEADER
6
5
from sentry .testutils .cases import IntegratedApiTestCase
7
6
from sentry .testutils .helpers import get_response_text
8
7
from sentry .testutils .silo import assume_test_silo_mode , region_silo_test
@@ -66,34 +65,22 @@ def test_identifying_channel_correctly(self):
66
65
data = json .loads (request .body )
67
66
assert data .get ("channel" ) == event_data ["channel" ]
68
67
69
- def _check_proxying (self ) -> None :
70
- assert len (responses .calls ) == 1
71
- request = responses .calls [0 ].request
72
- assert request .headers [PROXY_OI_HEADER ] == str (self .organization_integration .id )
73
- assert request .headers [PROXY_BASE_URL_HEADER ] == "https://slack.com/api"
74
- assert PROXY_SIGNATURE_HEADER in request .headers
75
-
76
68
@responses .activate
77
69
def test_user_message_im_notification_platform (self ):
78
70
responses .add (responses .POST , "https://slack.com/api/chat.postMessage" , json = {"ok" : True })
79
71
resp = self .post_webhook (event_data = json .loads (MESSAGE_IM_EVENT ))
80
72
assert resp .status_code == 200 , resp .content
81
73
82
- if self .should_call_api_without_proxying ():
83
- assert len (responses .calls ) == 1
84
- request = responses .calls [0 ].request
85
- assert (
86
- request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
87
- )
88
- data = json .loads (request .body )
89
- heading , contents = self .get_block_section_text (data )
90
- assert heading == "Unknown command: `helloo`"
91
- assert (
92
- contents
93
- == "Here are the commands you can use. Commands not working? Re-install the app!"
94
- )
95
- else :
96
- self ._check_proxying ()
74
+ assert len (responses .calls ) == 1
75
+ request = responses .calls [0 ].request
76
+ assert request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
77
+ data = json .loads (request .body )
78
+ heading , contents = self .get_block_section_text (data )
79
+ assert heading == "Unknown command: `helloo`"
80
+ assert (
81
+ contents
82
+ == "Here are the commands you can use. Commands not working? Re-install the app!"
83
+ )
97
84
98
85
@responses .activate
99
86
def test_user_message_link (self ):
@@ -107,16 +94,11 @@ def test_user_message_link(self):
107
94
resp = self .post_webhook (event_data = json .loads (MESSAGE_IM_EVENT_LINK ))
108
95
assert resp .status_code == 200 , resp .content
109
96
110
- if self .should_call_api_without_proxying ():
111
- assert len (responses .calls ) == 1
112
- request = responses .calls [0 ].request
113
- assert (
114
- request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
115
- )
116
- data = json .loads (request .body )
117
- assert "Link your Slack identity" in get_response_text (data )
118
- else :
119
- self ._check_proxying ()
97
+ assert len (responses .calls ) == 1
98
+ request = responses .calls [0 ].request
99
+ assert request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
100
+ data = json .loads (request .body )
101
+ assert "Link your Slack identity" in get_response_text (data )
120
102
121
103
@responses .activate
122
104
def test_user_message_already_linked (self ):
@@ -138,16 +120,11 @@ def test_user_message_already_linked(self):
138
120
resp = self .post_webhook (event_data = json .loads (MESSAGE_IM_EVENT_LINK ))
139
121
assert resp .status_code == 200 , resp .content
140
122
141
- if self .should_call_api_without_proxying ():
142
- assert len (responses .calls ) == 1
143
- request = responses .calls [0 ].request
144
- assert (
145
- request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
146
- )
147
- data = json .loads (request .body )
148
- assert "You are already linked" in get_response_text (data )
149
- else :
150
- self ._check_proxying ()
123
+ assert len (responses .calls ) == 1
124
+ request = responses .calls [0 ].request
125
+ assert request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
126
+ data = json .loads (request .body )
127
+ assert "You are already linked" in get_response_text (data )
151
128
152
129
@responses .activate
153
130
def test_user_message_unlink (self ):
@@ -168,16 +145,11 @@ def test_user_message_unlink(self):
168
145
resp = self .post_webhook (event_data = json .loads (MESSAGE_IM_EVENT_UNLINK ))
169
146
assert resp .status_code == 200 , resp .content
170
147
171
- if self .should_call_api_without_proxying ():
172
- assert len (responses .calls ) == 1
173
- request = responses .calls [0 ].request
174
- assert (
175
- request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
176
- )
177
- data = json .loads (request .body )
178
- assert "Click here to unlink your identity" in get_response_text (data )
179
- else :
180
- self ._check_proxying ()
148
+ assert len (responses .calls ) == 1
149
+ request = responses .calls [0 ].request
150
+ assert request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
151
+ data = json .loads (request .body )
152
+ assert "Click here to unlink your identity" in get_response_text (data )
181
153
182
154
@responses .activate
183
155
def test_user_message_already_unlinked (self ):
@@ -192,16 +164,11 @@ def test_user_message_already_unlinked(self):
192
164
resp = self .post_webhook (event_data = json .loads (MESSAGE_IM_EVENT_UNLINK ))
193
165
assert resp .status_code == 200 , resp .content
194
166
195
- if self .should_call_api_without_proxying ():
196
- assert len (responses .calls ) == 1
197
- request = responses .calls [0 ].request
198
- assert (
199
- request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
200
- )
201
- data = json .loads (request .body )
202
- assert "You do not have a linked identity to unlink" in get_response_text (data )
203
- else :
204
- self ._check_proxying ()
167
+ assert len (responses .calls ) == 1
168
+ request = responses .calls [0 ].request
169
+ assert request .headers ["Authorization" ] == "Bearer xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"
170
+ data = json .loads (request .body )
171
+ assert "You do not have a linked identity to unlink" in get_response_text (data )
205
172
206
173
def test_bot_message_im (self ):
207
174
resp = self .post_webhook (event_data = json .loads (MESSAGE_IM_BOT_EVENT ))
0 commit comments