test_plugin.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. import os.path
  2. import zipfile
  3. from base64 import b64encode
  4. from io import BytesIO
  5. from unittest.mock import patch
  6. import responses
  7. from django.utils.encoding import force_bytes
  8. from sentry.models import File, Release, ReleaseFile
  9. from sentry.models.releasefile import update_artifact_index
  10. from sentry.testutils import RelayStoreHelper, SnubaTestCase, TransactionTestCase
  11. from sentry.testutils.helpers.datetime import before_now, iso_format
  12. from sentry.utils import json
  13. BASE64_SOURCEMAP = "data:application/json;base64," + (
  14. b64encode(
  15. b'{"version":3,"file":"generated.js","sources":["/test.js"],"names":[],"mappings":"AAAA","sourcesContent":['
  16. b'"console.log(\\"hello, World!\\")"]}'
  17. )
  18. .decode("utf-8")
  19. .replace("\n", "")
  20. )
  21. def get_fixture_path(name):
  22. return os.path.join(os.path.dirname(__file__), "fixtures", name)
  23. def load_fixture(name):
  24. with open(get_fixture_path(name), "rb") as fp:
  25. return fp.read()
  26. class JavascriptIntegrationTest(RelayStoreHelper, SnubaTestCase, TransactionTestCase):
  27. def setUp(self):
  28. super().setUp()
  29. self.min_ago = iso_format(before_now(minutes=1))
  30. def test_adds_contexts_without_device(self):
  31. data = {
  32. "timestamp": self.min_ago,
  33. "message": "hello",
  34. "platform": "javascript",
  35. "request": {
  36. "url": "http://example.com",
  37. "headers": [
  38. [
  39. "User-Agent",
  40. "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
  41. "Chrome/28.0.1500.72 Safari/537.36",
  42. ]
  43. ],
  44. },
  45. }
  46. event = self.post_and_retrieve_event(data)
  47. contexts = event.interfaces["contexts"].to_json()
  48. assert contexts.get("os") == {"name": "Windows", "version": "8", "type": "os"}
  49. assert contexts.get("device") is None
  50. def test_adds_contexts_with_device(self):
  51. data = {
  52. "timestamp": self.min_ago,
  53. "message": "hello",
  54. "platform": "javascript",
  55. "request": {
  56. "url": "http://example.com",
  57. "headers": [
  58. [
  59. "User-Agent",
  60. "Mozilla/5.0 (Linux; U; Android 4.3; en-us; SCH-R530U Build/JSS15J) AppleWebKit/534.30 ("
  61. "KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 USCC-R530U",
  62. ]
  63. ],
  64. },
  65. }
  66. event = self.post_and_retrieve_event(data)
  67. contexts = event.interfaces["contexts"].to_json()
  68. assert contexts.get("os") == {"name": "Android", "type": "os", "version": "4.3"}
  69. assert contexts.get("browser") == {"name": "Android", "type": "browser", "version": "4.3"}
  70. assert contexts.get("device") == {
  71. "family": "Samsung SCH-R530U",
  72. "type": "device",
  73. "model": "SCH-R530U",
  74. "brand": "Samsung",
  75. }
  76. def test_adds_contexts_with_ps4_device(self):
  77. data = {
  78. "timestamp": self.min_ago,
  79. "message": "hello",
  80. "platform": "javascript",
  81. "request": {
  82. "url": "http://example.com",
  83. "headers": [
  84. [
  85. "User-Agent",
  86. "Mozilla/5.0 (PlayStation 4 3.55) AppleWebKit/537.78 (KHTML, like Gecko)",
  87. ]
  88. ],
  89. },
  90. }
  91. event = self.post_and_retrieve_event(data)
  92. contexts = event.interfaces["contexts"].to_json()
  93. assert contexts.get("os") is None
  94. assert contexts.get("browser") is None
  95. assert contexts.get("device") == {
  96. "family": "PlayStation 4",
  97. "type": "device",
  98. "model": "PlayStation 4",
  99. "brand": "Sony",
  100. }
  101. @patch("sentry.lang.javascript.processor.fetch_file")
  102. def test_source_expansion(self, mock_fetch_file):
  103. data = {
  104. "timestamp": self.min_ago,
  105. "message": "hello",
  106. "platform": "javascript",
  107. "exception": {
  108. "values": [
  109. {
  110. "type": "Error",
  111. "stacktrace": {
  112. "frames": [
  113. {
  114. "abs_path": "http://example.com/foo.js",
  115. "filename": "foo.js",
  116. "lineno": 4,
  117. "colno": 0,
  118. },
  119. {
  120. "abs_path": "http://example.com/foo.js",
  121. "filename": "foo.js",
  122. "lineno": 1,
  123. "colno": 0,
  124. },
  125. ]
  126. },
  127. }
  128. ]
  129. },
  130. }
  131. mock_fetch_file.return_value.body = force_bytes("\n".join("hello world"))
  132. mock_fetch_file.return_value.encoding = None
  133. mock_fetch_file.return_value.headers = {}
  134. event = self.post_and_retrieve_event(data)
  135. mock_fetch_file.assert_called_once_with(
  136. "http://example.com/foo.js",
  137. project=self.project,
  138. release=None,
  139. dist=None,
  140. allow_scraping=True,
  141. )
  142. exception = event.interfaces["exception"]
  143. frame_list = exception.values[0].stacktrace.frames
  144. frame = frame_list[0]
  145. assert frame.pre_context == ["h", "e", "l"]
  146. assert frame.context_line == "l"
  147. assert frame.post_context == ["o", " ", "w", "o", "r"]
  148. frame = frame_list[1]
  149. assert not frame.pre_context
  150. assert frame.context_line == "h"
  151. assert frame.post_context == ["e", "l", "l", "o", " "]
  152. # no source map means no raw_stacktrace
  153. assert exception.values[0].raw_stacktrace is None
  154. @patch("sentry.lang.javascript.processor.fetch_file")
  155. @patch("sentry.lang.javascript.processor.discover_sourcemap")
  156. def test_inlined_sources(self, mock_discover_sourcemap, mock_fetch_file):
  157. data = {
  158. "timestamp": self.min_ago,
  159. "message": "hello",
  160. "platform": "javascript",
  161. "exception": {
  162. "values": [
  163. {
  164. "type": "Error",
  165. "stacktrace": {
  166. "frames": [
  167. {
  168. "abs_path": "http://example.com/test.min.js",
  169. "filename": "test.js",
  170. "lineno": 1,
  171. "colno": 1,
  172. }
  173. ]
  174. },
  175. }
  176. ]
  177. },
  178. }
  179. mock_discover_sourcemap.return_value = BASE64_SOURCEMAP
  180. mock_fetch_file.return_value.url = "http://example.com/test.min.js"
  181. mock_fetch_file.return_value.body = force_bytes("\n".join("<generated source>"))
  182. mock_fetch_file.return_value.encoding = None
  183. event = self.post_and_retrieve_event(data)
  184. mock_fetch_file.assert_called_once_with(
  185. "http://example.com/test.min.js",
  186. project=self.project,
  187. release=None,
  188. dist=None,
  189. allow_scraping=True,
  190. )
  191. exception = event.interfaces["exception"]
  192. frame_list = exception.values[0].stacktrace.frames
  193. frame = frame_list[0]
  194. assert not frame.pre_context
  195. assert frame.context_line == 'console.log("hello, World!")'
  196. assert not frame.post_context
  197. assert frame.data["sourcemap"] == "http://example.com/test.min.js"
  198. @responses.activate
  199. def test_error_message_translations(self):
  200. data = {
  201. "timestamp": self.min_ago,
  202. "message": "hello",
  203. "platform": "javascript",
  204. "logentry": {
  205. "formatted": "ReferenceError: Impossible de d\xe9finir une propri\xe9t\xe9 \xab foo \xbb : objet non "
  206. "extensible"
  207. },
  208. "exception": {
  209. "values": [
  210. {"type": "Error", "value": "P\u0159\xedli\u0161 mnoho soubor\u016f"},
  211. {
  212. "type": "Error",
  213. "value": "foo: wyst\u0105pi\u0142 nieoczekiwany b\u0142\u0105d podczas pr\xf3by uzyskania "
  214. "informacji o metadanych",
  215. },
  216. ]
  217. },
  218. }
  219. event = self.post_and_retrieve_event(data)
  220. message = event.interfaces["logentry"]
  221. assert (
  222. message.formatted
  223. == "ReferenceError: Cannot define property 'foo': object is not extensible"
  224. )
  225. exception = event.interfaces["exception"]
  226. assert exception.values[0].value == "Too many files"
  227. assert (
  228. exception.values[1].value
  229. == "foo: an unexpected failure occurred while trying to obtain metadata information"
  230. )
  231. @responses.activate
  232. def test_sourcemap_source_expansion(self):
  233. responses.add(
  234. responses.GET,
  235. "http://example.com/file.min.js",
  236. body=load_fixture("file.min.js"),
  237. content_type="application/javascript; charset=utf-8",
  238. )
  239. responses.add(
  240. responses.GET,
  241. "http://example.com/file1.js",
  242. body=load_fixture("file1.js"),
  243. content_type="application/javascript; charset=utf-8",
  244. )
  245. responses.add(
  246. responses.GET,
  247. "http://example.com/file2.js",
  248. body=load_fixture("file2.js"),
  249. content_type="application/javascript; charset=utf-8",
  250. )
  251. responses.add(
  252. responses.GET,
  253. "http://example.com/file.sourcemap.js",
  254. body=load_fixture("file.sourcemap.js"),
  255. content_type="application/javascript; charset=utf-8",
  256. )
  257. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  258. data = {
  259. "timestamp": self.min_ago,
  260. "message": "hello",
  261. "platform": "javascript",
  262. "exception": {
  263. "values": [
  264. {
  265. "type": "Error",
  266. "stacktrace": {
  267. "frames": [
  268. {
  269. "abs_path": "http://example.com/file.min.js",
  270. "filename": "file.min.js",
  271. "lineno": 1,
  272. "colno": 39,
  273. },
  274. # NOTE: Intentionally source is not retrieved from this HTML file
  275. {
  276. "function": 'function: "HTMLDocument.<anonymous>"',
  277. "abs_path": "http//example.com/index.html",
  278. "filename": "index.html",
  279. "lineno": 283,
  280. "colno": 17,
  281. "in_app": False,
  282. },
  283. ]
  284. },
  285. }
  286. ]
  287. },
  288. }
  289. event = self.post_and_retrieve_event(data)
  290. assert event.data["errors"] == [
  291. {"type": "js_no_source", "url": "http//example.com/index.html"}
  292. ]
  293. exception = event.interfaces["exception"]
  294. frame_list = exception.values[0].stacktrace.frames
  295. frame = frame_list[0]
  296. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  297. expected = "\treturn a + b; // fôo"
  298. assert frame.context_line == expected
  299. assert frame.post_context == ["}", ""]
  300. raw_frame_list = exception.values[0].raw_stacktrace.frames
  301. raw_frame = raw_frame_list[0]
  302. assert not raw_frame.pre_context
  303. assert (
  304. raw_frame.context_line
  305. == 'function add(a,b){"use strict";return a+b}function multiply(a,b){"use strict";return a*b}function '
  306. 'divide(a,b){"use strict";try{return multip {snip}'
  307. )
  308. assert raw_frame.post_context == ["//@ sourceMappingURL=file.sourcemap.js", ""]
  309. assert raw_frame.lineno == 1
  310. # Since we couldn't expand source for the 2nd frame, both
  311. # its raw and original form should be identical
  312. assert raw_frame_list[1] == frame_list[1]
  313. @responses.activate
  314. def test_sourcemap_embedded_source_expansion(self):
  315. responses.add(
  316. responses.GET,
  317. "http://example.com/embedded.js",
  318. body=load_fixture("embedded.js"),
  319. content_type="application/javascript; charset=utf-8",
  320. )
  321. responses.add(
  322. responses.GET,
  323. "http://example.com/embedded.js.map",
  324. body=load_fixture("embedded.js.map"),
  325. content_type="application/json; charset=utf-8",
  326. )
  327. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  328. data = {
  329. "timestamp": self.min_ago,
  330. "message": "hello",
  331. "platform": "javascript",
  332. "exception": {
  333. "values": [
  334. {
  335. "type": "Error",
  336. "stacktrace": {
  337. "frames": [
  338. {
  339. "abs_path": "http://example.com/embedded.js",
  340. "filename": "file.min.js",
  341. "lineno": 1,
  342. "colno": 39,
  343. },
  344. # NOTE: Intentionally source is not retrieved from this HTML file
  345. {
  346. "function": 'function: "HTMLDocument.<anonymous>"',
  347. "abs_path": "http//example.com/index.html",
  348. "filename": "index.html",
  349. "lineno": 283,
  350. "colno": 17,
  351. "in_app": False,
  352. },
  353. ]
  354. },
  355. }
  356. ]
  357. },
  358. }
  359. event = self.post_and_retrieve_event(data)
  360. assert event.data["errors"] == [
  361. {"type": "js_no_source", "url": "http//example.com/index.html"}
  362. ]
  363. exception = event.interfaces["exception"]
  364. frame_list = exception.values[0].stacktrace.frames
  365. frame = frame_list[0]
  366. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  367. expected = "\treturn a + b; // fôo"
  368. assert frame.context_line == expected
  369. assert frame.post_context == ["}", ""]
  370. @responses.activate
  371. def test_sourcemap_nofiles_source_expansion(self):
  372. project = self.project
  373. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  374. release.add_project(project)
  375. with open(get_fixture_path("nofiles.js"), "rb") as f:
  376. f_minified = File.objects.create(
  377. name="nofiles.js", type="release.file", headers={"Content-Type": "application/json"}
  378. )
  379. f_minified.putfile(f)
  380. ReleaseFile.objects.create(
  381. name=f"~/{f_minified.name}",
  382. release_id=release.id,
  383. organization_id=project.organization_id,
  384. file=f_minified,
  385. )
  386. with open(get_fixture_path("nofiles.js.map"), "rb") as f:
  387. f_sourcemap = File.objects.create(
  388. name="nofiles.js.map",
  389. type="release.file",
  390. headers={"Content-Type": "application/json"},
  391. )
  392. f_sourcemap.putfile(f)
  393. ReleaseFile.objects.create(
  394. name=f"app:///{f_sourcemap.name}",
  395. release_id=release.id,
  396. organization_id=project.organization_id,
  397. file=f_sourcemap,
  398. )
  399. data = {
  400. "timestamp": self.min_ago,
  401. "message": "hello",
  402. "platform": "javascript",
  403. "release": "abc",
  404. "exception": {
  405. "values": [
  406. {
  407. "type": "Error",
  408. "stacktrace": {
  409. "frames": [{"abs_path": "app:///nofiles.js", "lineno": 1, "colno": 39}]
  410. },
  411. }
  412. ]
  413. },
  414. }
  415. event = self.post_and_retrieve_event(data)
  416. assert "errors" not in event.data
  417. exception = event.interfaces["exception"]
  418. frame_list = exception.values[0].stacktrace.frames
  419. assert len(frame_list) == 1
  420. frame = frame_list[0]
  421. assert frame.abs_path == "app:///nofiles.js"
  422. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  423. assert frame.context_line == "\treturn a + b; // fôo"
  424. assert frame.post_context == ["}", ""]
  425. @responses.activate
  426. def test_indexed_sourcemap_source_expansion(self):
  427. responses.add(
  428. responses.GET,
  429. "http://example.com/indexed.min.js",
  430. body=load_fixture("indexed.min.js"),
  431. content_type="application/javascript; charset=utf-8",
  432. )
  433. responses.add(
  434. responses.GET,
  435. "http://example.com/file1.js",
  436. body=load_fixture("file1.js"),
  437. content_type="application/javascript; charset=utf-8",
  438. )
  439. responses.add(
  440. responses.GET,
  441. "http://example.com/file2.js",
  442. body=load_fixture("file2.js"),
  443. content_type="application/javascript; charset=utf-8",
  444. )
  445. responses.add(
  446. responses.GET,
  447. "http://example.com/indexed.sourcemap.js",
  448. body=load_fixture("indexed.sourcemap.js"),
  449. content_type="application/json; charset=utf-8",
  450. )
  451. data = {
  452. "timestamp": self.min_ago,
  453. "message": "hello",
  454. "platform": "javascript",
  455. "exception": {
  456. "values": [
  457. {
  458. "type": "Error",
  459. "stacktrace": {
  460. "frames": [
  461. {
  462. "abs_path": "http://example.com/indexed.min.js",
  463. "filename": "indexed.min.js",
  464. "lineno": 1,
  465. "colno": 39,
  466. },
  467. {
  468. "abs_path": "http://example.com/indexed.min.js",
  469. "filename": "indexed.min.js",
  470. "lineno": 2,
  471. "colno": 44,
  472. },
  473. ]
  474. },
  475. }
  476. ]
  477. },
  478. }
  479. event = self.post_and_retrieve_event(data)
  480. assert "errors" not in event.data
  481. exception = event.interfaces["exception"]
  482. frame_list = exception.values[0].stacktrace.frames
  483. frame = frame_list[0]
  484. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  485. expected = "\treturn a + b; // fôo"
  486. assert frame.context_line == expected
  487. assert frame.post_context == ["}", ""]
  488. raw_frame_list = exception.values[0].raw_stacktrace.frames
  489. raw_frame = raw_frame_list[0]
  490. assert not raw_frame.pre_context
  491. assert raw_frame.context_line == 'function add(a,b){"use strict";return a+b}'
  492. assert raw_frame.post_context == [
  493. 'function multiply(a,b){"use strict";return a*b}function divide(a,b){"use strict";try{return multiply('
  494. "add(a,b),a,b)/c}catch(e){Raven.captureE {snip}",
  495. "//# sourceMappingURL=indexed.sourcemap.js",
  496. "",
  497. ]
  498. assert raw_frame.lineno == 1
  499. frame = frame_list[1]
  500. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  501. assert frame.context_line == "\treturn a * b;"
  502. assert frame.post_context == [
  503. "}",
  504. "function divide(a, b) {",
  505. '\t"use strict";',
  506. "\ttry {",
  507. "\t\treturn multiply(add(a, b), a, b) / c;",
  508. ]
  509. raw_frame = raw_frame_list[1]
  510. assert raw_frame.pre_context == ['function add(a,b){"use strict";return a+b}']
  511. assert (
  512. raw_frame.context_line
  513. == 'function multiply(a,b){"use strict";return a*b}function divide(a,b){"use strict";try{return multiply('
  514. "add(a,b),a,b)/c}catch(e){Raven.captureE {snip}"
  515. )
  516. assert raw_frame.post_context == ["//# sourceMappingURL=indexed.sourcemap.js", ""]
  517. assert raw_frame.lineno == 2
  518. @responses.activate
  519. def test_expansion_via_release_artifacts(self):
  520. project = self.project
  521. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  522. release.add_project(project)
  523. # file.min.js
  524. # ------------
  525. with open(get_fixture_path("file.min.js"), "rb") as f:
  526. f_minified = File.objects.create(
  527. name="file.min.js",
  528. type="release.file",
  529. headers={"Content-Type": "application/json"},
  530. )
  531. f_minified.putfile(f)
  532. # Intentionally omit hostname - use alternate artifact path lookup instead
  533. # /file1.js vs http://example.com/file1.js
  534. ReleaseFile.objects.create(
  535. name=f"~/{f_minified.name}?foo=bar",
  536. release_id=release.id,
  537. organization_id=project.organization_id,
  538. file=f_minified,
  539. )
  540. # file1.js
  541. # ---------
  542. with open(get_fixture_path("file1.js"), "rb") as f:
  543. f1 = File.objects.create(
  544. name="file1.js", type="release.file", headers={"Content-Type": "application/json"}
  545. )
  546. f1.putfile(f)
  547. ReleaseFile.objects.create(
  548. name=f"http://example.com/{f1.name}",
  549. release_id=release.id,
  550. organization_id=project.organization_id,
  551. file=f1,
  552. )
  553. # file2.js
  554. # ----------
  555. with open(get_fixture_path("file2.js"), "rb") as f:
  556. f2 = File.objects.create(
  557. name="file2.js", type="release.file", headers={"Content-Type": "application/json"}
  558. )
  559. f2.putfile(f)
  560. ReleaseFile.objects.create(
  561. name=f"http://example.com/{f2.name}",
  562. release_id=release.id,
  563. organization_id=project.organization_id,
  564. file=f2,
  565. )
  566. # To verify that the full url has priority over the relative url,
  567. # we will also add a second ReleaseFile alias for file2.js (f3) w/o
  568. # hostname that points to an empty file. If the processor chooses
  569. # this empty file over the correct file2.js, it will not locate
  570. # context for the 2nd frame.
  571. with open(get_fixture_path("empty.js"), "rb") as f:
  572. f2_empty = File.objects.create(
  573. name="empty.js", type="release.file", headers={"Content-Type": "application/json"}
  574. )
  575. f2_empty.putfile(f)
  576. ReleaseFile.objects.create(
  577. name=f"~/{f2.name}", # intentionally using f2.name ("file2.js")
  578. release_id=release.id,
  579. organization_id=project.organization_id,
  580. file=f2_empty,
  581. )
  582. # sourcemap
  583. # ----------
  584. with open(get_fixture_path("file.sourcemap.js"), "rb") as f:
  585. f_sourcemap = File.objects.create(
  586. name="file.sourcemap.js",
  587. type="release.file",
  588. headers={"Content-Type": "application/json"},
  589. )
  590. f_sourcemap.putfile(f)
  591. ReleaseFile.objects.create(
  592. name=f"http://example.com/{f_sourcemap.name}",
  593. release_id=release.id,
  594. organization_id=project.organization_id,
  595. file=f_sourcemap,
  596. )
  597. data = {
  598. "timestamp": self.min_ago,
  599. "message": "hello",
  600. "platform": "javascript",
  601. "release": "abc",
  602. "exception": {
  603. "values": [
  604. {
  605. "type": "Error",
  606. "stacktrace": {
  607. "frames": [
  608. {
  609. "abs_path": "http://example.com/file.min.js?foo=bar",
  610. "filename": "file.min.js",
  611. "lineno": 1,
  612. "colno": 39,
  613. },
  614. {
  615. "abs_path": "http://example.com/file.min.js?foo=bar",
  616. "filename": "file.min.js",
  617. "lineno": 1,
  618. "colno": 79,
  619. },
  620. ]
  621. },
  622. }
  623. ]
  624. },
  625. }
  626. event = self.post_and_retrieve_event(data)
  627. assert "errors" not in event.data
  628. exception = event.interfaces["exception"]
  629. frame_list = exception.values[0].stacktrace.frames
  630. frame = frame_list[0]
  631. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  632. assert frame.context_line == "\treturn a + b; // fôo"
  633. assert frame.post_context == ["}", ""]
  634. frame = frame_list[1]
  635. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  636. assert frame.context_line == "\treturn a * b;"
  637. assert frame.post_context == [
  638. "}",
  639. "function divide(a, b) {",
  640. '\t"use strict";',
  641. "\ttry {",
  642. "\t\treturn multiply(add(a, b), a, b) / c;",
  643. ]
  644. @responses.activate
  645. def test_expansion_via_distribution_release_artifacts(self):
  646. project = self.project
  647. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  648. release.add_project(project)
  649. dist = release.add_dist("foo")
  650. # file.min.js
  651. # ------------
  652. with open(get_fixture_path("file.min.js"), "rb") as f:
  653. f_minified = File.objects.create(
  654. name="file.min.js",
  655. type="release.file",
  656. headers={"Content-Type": "application/json"},
  657. )
  658. f_minified.putfile(f)
  659. # Intentionally omit hostname - use alternate artifact path lookup instead
  660. # /file1.js vs http://example.com/file1.js
  661. ReleaseFile.objects.create(
  662. name=f"~/{f_minified.name}?foo=bar",
  663. release_id=release.id,
  664. dist_id=dist.id,
  665. organization_id=project.organization_id,
  666. file=f_minified,
  667. )
  668. # file1.js
  669. # ---------
  670. with open(get_fixture_path("file1.js"), "rb") as f:
  671. f1 = File.objects.create(
  672. name="file1.js", type="release.file", headers={"Content-Type": "application/json"}
  673. )
  674. f1.putfile(f)
  675. ReleaseFile.objects.create(
  676. name=f"http://example.com/{f1.name}",
  677. release_id=release.id,
  678. dist_id=dist.id,
  679. organization_id=project.organization_id,
  680. file=f1,
  681. )
  682. # file2.js
  683. # ----------
  684. with open(get_fixture_path("file2.js"), "rb") as f:
  685. f2 = File.objects.create(
  686. name="file2.js", type="release.file", headers={"Content-Type": "application/json"}
  687. )
  688. f2.putfile(f)
  689. ReleaseFile.objects.create(
  690. name=f"http://example.com/{f2.name}",
  691. release_id=release.id,
  692. dist_id=dist.id,
  693. organization_id=project.organization_id,
  694. file=f2,
  695. )
  696. # To verify that the full url has priority over the relative url,
  697. # we will also add a second ReleaseFile alias for file2.js (f3) w/o
  698. # hostname that points to an empty file. If the processor chooses
  699. # this empty file over the correct file2.js, it will not locate
  700. # context for the 2nd frame.
  701. with open(get_fixture_path("empty.js"), "rb") as f:
  702. f2_empty = File.objects.create(
  703. name="empty.js", type="release.file", headers={"Content-Type": "application/json"}
  704. )
  705. f2_empty.putfile(f)
  706. ReleaseFile.objects.create(
  707. name=f"~/{f2.name}", # intentionally using f2.name ("file2.js")
  708. release_id=release.id,
  709. dist_id=dist.id,
  710. organization_id=project.organization_id,
  711. file=f2_empty,
  712. )
  713. # sourcemap
  714. # ----------
  715. with open(get_fixture_path("file.sourcemap.js"), "rb") as f:
  716. f_sourcemap = File.objects.create(
  717. name="file.sourcemap.js",
  718. type="release.file",
  719. headers={"Content-Type": "application/json"},
  720. )
  721. f_sourcemap.putfile(f)
  722. ReleaseFile.objects.create(
  723. name=f"http://example.com/{f_sourcemap.name}",
  724. release_id=release.id,
  725. dist_id=dist.id,
  726. organization_id=project.organization_id,
  727. file=f_sourcemap,
  728. )
  729. data = {
  730. "timestamp": self.min_ago,
  731. "message": "hello",
  732. "platform": "javascript",
  733. "release": "abc",
  734. "dist": "foo",
  735. "exception": {
  736. "values": [
  737. {
  738. "type": "Error",
  739. "stacktrace": {
  740. "frames": [
  741. {
  742. "abs_path": "http://example.com/file.min.js?foo=bar",
  743. "filename": "file.min.js",
  744. "lineno": 1,
  745. "colno": 39,
  746. },
  747. {
  748. "abs_path": "http://example.com/file.min.js?foo=bar",
  749. "filename": "file.min.js",
  750. "lineno": 1,
  751. "colno": 79,
  752. },
  753. ]
  754. },
  755. }
  756. ]
  757. },
  758. }
  759. event = self.post_and_retrieve_event(data)
  760. assert "errors" not in event.data
  761. exception = event.interfaces["exception"]
  762. frame_list = exception.values[0].stacktrace.frames
  763. frame = frame_list[0]
  764. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  765. assert frame.context_line == "\treturn a + b; // fôo"
  766. assert frame.post_context == ["}", ""]
  767. frame = frame_list[1]
  768. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  769. assert frame.context_line == "\treturn a * b;"
  770. assert frame.post_context == [
  771. "}",
  772. "function divide(a, b) {",
  773. '\t"use strict";',
  774. "\ttry {",
  775. "\t\treturn multiply(add(a, b), a, b) / c;",
  776. ]
  777. @responses.activate
  778. def test_sourcemap_expansion_with_missing_source(self):
  779. """
  780. Tests a successful sourcemap expansion that points to source files
  781. that are not found.
  782. """
  783. responses.add(
  784. responses.GET,
  785. "http://example.com/file.min.js",
  786. body=load_fixture("file.min.js"),
  787. content_type="application/javascript; charset=utf-8",
  788. )
  789. responses.add(
  790. responses.GET,
  791. "http://example.com/file.sourcemap.js",
  792. body=load_fixture("file.sourcemap.js"),
  793. content_type="application/json; charset=utf-8",
  794. )
  795. responses.add(responses.GET, "http://example.com/file1.js", body="Not Found", status=404)
  796. data = {
  797. "timestamp": self.min_ago,
  798. "message": "hello",
  799. "platform": "javascript",
  800. "exception": {
  801. "values": [
  802. {
  803. "type": "Error",
  804. "stacktrace": {
  805. # Add two frames. We only want to see the
  806. # error once though.
  807. "frames": [
  808. {
  809. "abs_path": "http://example.com/file.min.js",
  810. "filename": "file.min.js",
  811. "lineno": 1,
  812. "colno": 39,
  813. },
  814. {
  815. "abs_path": "http://example.com/file.min.js",
  816. "filename": "file.min.js",
  817. "lineno": 1,
  818. "colno": 39,
  819. },
  820. ]
  821. },
  822. }
  823. ]
  824. },
  825. }
  826. event = self.post_and_retrieve_event(data)
  827. assert event.data["errors"] == [
  828. {"url": "http://example.com/file1.js", "type": "fetch_invalid_http_code", "value": 404}
  829. ]
  830. exception = event.interfaces["exception"]
  831. frame_list = exception.values[0].stacktrace.frames
  832. frame = frame_list[0]
  833. # no context information ...
  834. assert not frame.pre_context
  835. assert not frame.context_line
  836. assert not frame.post_context
  837. # ... but line, column numbers are still correctly mapped
  838. assert frame.lineno == 3
  839. assert frame.colno == 9
  840. @responses.activate
  841. def test_failed_sourcemap_expansion(self):
  842. """
  843. Tests attempting to parse an indexed source map where each section has a "url"
  844. property - this is unsupported and should fail.
  845. """
  846. responses.add(
  847. responses.GET,
  848. "http://example.com/unsupported.min.js",
  849. body=load_fixture("unsupported.min.js"),
  850. content_type="application/javascript; charset=utf-8",
  851. )
  852. responses.add(
  853. responses.GET,
  854. "http://example.com/unsupported.sourcemap.js",
  855. body=load_fixture("unsupported.sourcemap.js"),
  856. content_type="application/json; charset=utf-8",
  857. )
  858. data = {
  859. "timestamp": self.min_ago,
  860. "message": "hello",
  861. "platform": "javascript",
  862. "exception": {
  863. "values": [
  864. {
  865. "type": "Error",
  866. "stacktrace": {
  867. "frames": [
  868. {
  869. "abs_path": "http://example.com/unsupported.min.js",
  870. "filename": "indexed.min.js",
  871. "lineno": 1,
  872. "colno": 39,
  873. }
  874. ]
  875. },
  876. }
  877. ]
  878. },
  879. }
  880. event = self.post_and_retrieve_event(data)
  881. assert event.data["errors"] == [
  882. {"url": "http://example.com/unsupported.sourcemap.js", "type": "js_invalid_source"}
  883. ]
  884. def test_failed_sourcemap_expansion_data_url(self):
  885. data = {
  886. "timestamp": self.min_ago,
  887. "message": "hello",
  888. "platform": "javascript",
  889. "exception": {
  890. "values": [
  891. {
  892. "type": "Error",
  893. "stacktrace": {
  894. "frames": [
  895. {
  896. "abs_path": "data:application/javascript,base46,asfasf",
  897. "filename": "indexed.min.js",
  898. "lineno": 1,
  899. "colno": 39,
  900. }
  901. ]
  902. },
  903. }
  904. ]
  905. },
  906. }
  907. event = self.post_and_retrieve_event(data)
  908. assert event.data["errors"] == [{"url": "<data url>", "type": "js_no_source"}]
  909. @responses.activate
  910. def test_failed_sourcemap_expansion_missing_location_entirely(self):
  911. responses.add(
  912. responses.GET,
  913. "http://example.com/indexed.min.js",
  914. body="//# sourceMappingURL=indexed.sourcemap.js",
  915. )
  916. responses.add(responses.GET, "http://example.com/indexed.sourcemap.js", body="{}")
  917. data = {
  918. "timestamp": self.min_ago,
  919. "message": "hello",
  920. "platform": "javascript",
  921. "exception": {
  922. "values": [
  923. {
  924. "type": "Error",
  925. "stacktrace": {
  926. "frames": [
  927. {
  928. "abs_path": "http://example.com/indexed.min.js",
  929. "filename": "indexed.min.js",
  930. "lineno": 1,
  931. "colno": 1,
  932. },
  933. {
  934. "abs_path": "http://example.com/indexed.min.js",
  935. "filename": "indexed.min.js",
  936. },
  937. ]
  938. },
  939. }
  940. ]
  941. },
  942. }
  943. event = self.post_and_retrieve_event(data)
  944. assert "errors" not in event.data
  945. @responses.activate
  946. def test_html_response_for_js(self):
  947. responses.add(
  948. responses.GET,
  949. "http://example.com/file1.js",
  950. body=" <!DOCTYPE html><html><head></head><body></body></html>",
  951. )
  952. responses.add(
  953. responses.GET,
  954. "http://example.com/file2.js",
  955. body="<!doctype html><html><head></head><body></body></html>",
  956. )
  957. responses.add(
  958. responses.GET,
  959. "http://example.com/file.html",
  960. body=(
  961. "<!doctype html><html><head></head><body><script>/*legit case*/</script></body></html>"
  962. ),
  963. )
  964. data = {
  965. "timestamp": self.min_ago,
  966. "message": "hello",
  967. "platform": "javascript",
  968. "exception": {
  969. "values": [
  970. {
  971. "type": "Error",
  972. "stacktrace": {
  973. "frames": [
  974. {
  975. "abs_path": "http://example.com/file1.js",
  976. "filename": "file.min.js",
  977. "lineno": 1,
  978. "colno": 39,
  979. },
  980. {
  981. "abs_path": "http://example.com/file2.js",
  982. "filename": "file.min.js",
  983. "lineno": 1,
  984. "colno": 39,
  985. },
  986. {
  987. "abs_path": "http://example.com/file.html",
  988. "filename": "file.html",
  989. "lineno": 1,
  990. "colno": 1,
  991. },
  992. ]
  993. },
  994. }
  995. ]
  996. },
  997. }
  998. event = self.post_and_retrieve_event(data)
  999. assert event.data["errors"] == [
  1000. {"url": "http://example.com/file1.js", "type": "js_invalid_content"},
  1001. {"url": "http://example.com/file2.js", "type": "js_invalid_content"},
  1002. ]
  1003. def _test_expansion_via_release_archive(self, link_sourcemaps: bool):
  1004. project = self.project
  1005. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  1006. release.add_project(project)
  1007. manifest = {
  1008. "org": self.organization.slug,
  1009. "release": release.version,
  1010. "files": {
  1011. "files/_/_/file.min.js": {
  1012. "url": "http://example.com/file.min.js",
  1013. },
  1014. "files/_/_/file1.js": {
  1015. "url": "http://example.com/file1.js",
  1016. },
  1017. "files/_/_/file2.js": {
  1018. "url": "http://example.com/file2.js",
  1019. },
  1020. "files/_/_/file.sourcemap.js": {
  1021. "url": "http://example.com/file.sourcemap.js",
  1022. },
  1023. },
  1024. }
  1025. file_like = BytesIO()
  1026. with zipfile.ZipFile(file_like, "w") as zip:
  1027. for rel_path, entry in manifest["files"].items():
  1028. name = os.path.basename(rel_path)
  1029. content = load_fixture(name)
  1030. if name == "file.min.js" and not link_sourcemaps:
  1031. # Remove link to source map, add to header instead
  1032. content = content.replace(b"//@ sourceMappingURL=file.sourcemap.js", b"")
  1033. entry["headers"] = {"SourceMap": "/file.sourcemap.js"}
  1034. zip.writestr(rel_path, content)
  1035. zip.writestr("manifest.json", json.dumps(manifest))
  1036. file_like.seek(0)
  1037. file = File.objects.create(name="doesnt_matter", type="release.bundle")
  1038. file.putfile(file_like)
  1039. update_artifact_index(release, None, file)
  1040. data = {
  1041. "timestamp": self.min_ago,
  1042. "message": "hello",
  1043. "platform": "javascript",
  1044. "release": "abc",
  1045. "exception": {
  1046. "values": [
  1047. {
  1048. "type": "Error",
  1049. "stacktrace": {
  1050. "frames": [
  1051. {
  1052. "abs_path": "http://example.com/file.min.js",
  1053. "filename": "file.min.js",
  1054. "lineno": 1,
  1055. "colno": 39,
  1056. },
  1057. {
  1058. "abs_path": "http://example.com/file.min.js",
  1059. "filename": "file.min.js",
  1060. "lineno": 1,
  1061. "colno": 79,
  1062. },
  1063. ]
  1064. },
  1065. }
  1066. ]
  1067. },
  1068. }
  1069. event = self.post_and_retrieve_event(data)
  1070. assert "errors" not in event.data
  1071. exception = event.interfaces["exception"]
  1072. frame_list = exception.values[0].stacktrace.frames
  1073. frame = frame_list[0]
  1074. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1075. assert frame.context_line == "\treturn a + b; // fôo"
  1076. assert frame.post_context == ["}", ""]
  1077. frame = frame_list[1]
  1078. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  1079. assert frame.context_line == "\treturn a * b;"
  1080. assert frame.post_context == [
  1081. "}",
  1082. "function divide(a, b) {",
  1083. '\t"use strict";',
  1084. "\ttry {",
  1085. "\t\treturn multiply(add(a, b), a, b) / c;",
  1086. ]
  1087. def test_expansion_via_release_archive(self):
  1088. self._test_expansion_via_release_archive(link_sourcemaps=True)
  1089. def test_expansion_via_release_archive_no_sourcemap_link(self):
  1090. self._test_expansion_via_release_archive(link_sourcemaps=False)
  1091. def test_node_processing(self):
  1092. project = self.project
  1093. release = Release.objects.create(
  1094. organization_id=project.organization_id, version="nodeabc123"
  1095. )
  1096. release.add_project(project)
  1097. with open(get_fixture_path("dist.bundle.js"), "rb") as f:
  1098. f_minified = File.objects.create(
  1099. name="dist.bundle.js",
  1100. type="release.file",
  1101. headers={"Content-Type": "application/javascript"},
  1102. )
  1103. f_minified.putfile(f)
  1104. ReleaseFile.objects.create(
  1105. name=f"~/{f_minified.name}",
  1106. release_id=release.id,
  1107. organization_id=project.organization_id,
  1108. file=f_minified,
  1109. )
  1110. with open(get_fixture_path("dist.bundle.js.map"), "rb") as f:
  1111. f_sourcemap = File.objects.create(
  1112. name="dist.bundle.js.map",
  1113. type="release.file",
  1114. headers={"Content-Type": "application/javascript"},
  1115. )
  1116. f_sourcemap.putfile(f)
  1117. ReleaseFile.objects.create(
  1118. name=f"~/{f_sourcemap.name}",
  1119. release_id=release.id,
  1120. organization_id=project.organization_id,
  1121. file=f_sourcemap,
  1122. )
  1123. data = {
  1124. "timestamp": self.min_ago,
  1125. "message": "hello",
  1126. "platform": "node",
  1127. "release": "nodeabc123",
  1128. "exception": {
  1129. "values": [
  1130. {
  1131. "type": "Error",
  1132. "stacktrace": {
  1133. "frames": [
  1134. {
  1135. "filename": "app:///dist.bundle.js",
  1136. "function": "bar",
  1137. "lineno": 9,
  1138. "colno": 2321,
  1139. },
  1140. {
  1141. "filename": "app:///dist.bundle.js",
  1142. "function": "foo",
  1143. "lineno": 3,
  1144. "colno": 2308,
  1145. },
  1146. {
  1147. "filename": "app:///dist.bundle.js",
  1148. "function": "App",
  1149. "lineno": 3,
  1150. "colno": 1011,
  1151. },
  1152. {
  1153. "filename": "app:///dist.bundle.js",
  1154. "function": "Object.<anonymous>",
  1155. "lineno": 1,
  1156. "colno": 1014,
  1157. },
  1158. {
  1159. "filename": "app:///dist.bundle.js",
  1160. "function": "__webpack_require__",
  1161. "lineno": 20,
  1162. "colno": 30,
  1163. },
  1164. {
  1165. "filename": "app:///dist.bundle.js",
  1166. "function": "<unknown>",
  1167. "lineno": 18,
  1168. "colno": 63,
  1169. },
  1170. ]
  1171. },
  1172. }
  1173. ]
  1174. },
  1175. }
  1176. event = self.post_and_retrieve_event(data)
  1177. exception = event.interfaces["exception"]
  1178. frame_list = exception.values[0].stacktrace.frames
  1179. assert len(frame_list) == 6
  1180. assert frame_list[0].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1181. assert frame_list[0].function == "bar"
  1182. assert frame_list[0].lineno == 8
  1183. assert frame_list[1].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1184. assert frame_list[1].function == "foo"
  1185. assert frame_list[1].lineno == 2
  1186. assert frame_list[2].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1187. assert frame_list[2].function == "App"
  1188. assert frame_list[2].lineno == 2
  1189. assert frame_list[3].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1190. assert frame_list[3].function == "Object.<anonymous>"
  1191. assert frame_list[3].lineno == 1
  1192. assert frame_list[4].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1193. assert frame_list[4].function == "__webpack_require__"
  1194. assert frame_list[4].lineno == 19
  1195. assert frame_list[5].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1196. assert frame_list[5].function == "<unknown>"
  1197. assert frame_list[5].lineno == 16
  1198. @responses.activate
  1199. def test_no_fetch_from_http(self):
  1200. responses.add(
  1201. responses.GET,
  1202. "http://example.com/node_app.min.js",
  1203. body=load_fixture("node_app.min.js"),
  1204. content_type="application/javascript; charset=utf-8",
  1205. )
  1206. responses.add(
  1207. responses.GET,
  1208. "http://example.com/node_app.min.js.map",
  1209. body=load_fixture("node_app.min.js.map"),
  1210. content_type="application/javascript; charset=utf-8",
  1211. )
  1212. data = {
  1213. "timestamp": self.min_ago,
  1214. "message": "hello",
  1215. "platform": "node",
  1216. "exception": {
  1217. "values": [
  1218. {
  1219. "type": "Error",
  1220. "stacktrace": {
  1221. "frames": [
  1222. {
  1223. "abs_path": "node_bootstrap.js",
  1224. "filename": "node_bootstrap.js",
  1225. "lineno": 1,
  1226. "colno": 38,
  1227. },
  1228. {
  1229. "abs_path": "timers.js",
  1230. "filename": "timers.js",
  1231. "lineno": 1,
  1232. "colno": 39,
  1233. },
  1234. {
  1235. "abs_path": "webpack:///internal",
  1236. "filename": "internal",
  1237. "lineno": 1,
  1238. "colno": 43,
  1239. },
  1240. {
  1241. "abs_path": "webpack:///~/some_dep/file.js",
  1242. "filename": "file.js",
  1243. "lineno": 1,
  1244. "colno": 41,
  1245. },
  1246. {
  1247. "abs_path": "webpack:///./node_modules/file.js",
  1248. "filename": "file.js",
  1249. "lineno": 1,
  1250. "colno": 42,
  1251. },
  1252. {
  1253. "abs_path": "http://example.com/node_app.min.js",
  1254. "filename": "node_app.min.js",
  1255. "lineno": 1,
  1256. "colno": 40,
  1257. },
  1258. ]
  1259. },
  1260. }
  1261. ]
  1262. },
  1263. }
  1264. event = self.post_and_retrieve_event(data)
  1265. exception = event.interfaces["exception"]
  1266. frame_list = exception.values[0].stacktrace.frames
  1267. # This one should not process, so this one should be none.
  1268. assert exception.values[0].raw_stacktrace is None
  1269. # None of the in app should update
  1270. for x in range(6):
  1271. assert not frame_list[x].in_app
  1272. @responses.activate
  1273. def test_html_file_with_query_param_ending_with_js_extension(self):
  1274. responses.add(
  1275. responses.GET,
  1276. "http://example.com/file.html",
  1277. body=(
  1278. "<!doctype html><html><head></head><body><script>/*legit case*/</script></body></html>"
  1279. ),
  1280. )
  1281. data = {
  1282. "timestamp": self.min_ago,
  1283. "message": "hello",
  1284. "platform": "javascript",
  1285. "exception": {
  1286. "values": [
  1287. {
  1288. "type": "Error",
  1289. "stacktrace": {
  1290. "frames": [
  1291. {
  1292. "abs_path": "http://example.com/file.html?sw=iddqd1337.js",
  1293. "filename": "file.html",
  1294. "lineno": 1,
  1295. "colno": 1,
  1296. },
  1297. ]
  1298. },
  1299. }
  1300. ]
  1301. },
  1302. }
  1303. event = self.post_and_retrieve_event(data)
  1304. assert "errors" not in event.data