test_plugin.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  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. f_minified = File.objects.create(
  376. name="nofiles.js", type="release.file", headers={"Content-Type": "application/json"}
  377. )
  378. f_minified.putfile(open(get_fixture_path("nofiles.js"), "rb"))
  379. ReleaseFile.objects.create(
  380. name=f"~/{f_minified.name}",
  381. release_id=release.id,
  382. organization_id=project.organization_id,
  383. file=f_minified,
  384. )
  385. f_sourcemap = File.objects.create(
  386. name="nofiles.js.map", type="release.file", headers={"Content-Type": "application/json"}
  387. )
  388. f_sourcemap.putfile(open(get_fixture_path("nofiles.js.map"), "rb"))
  389. ReleaseFile.objects.create(
  390. name=f"app:///{f_sourcemap.name}",
  391. release_id=release.id,
  392. organization_id=project.organization_id,
  393. file=f_sourcemap,
  394. )
  395. data = {
  396. "timestamp": self.min_ago,
  397. "message": "hello",
  398. "platform": "javascript",
  399. "release": "abc",
  400. "exception": {
  401. "values": [
  402. {
  403. "type": "Error",
  404. "stacktrace": {
  405. "frames": [{"abs_path": "app:///nofiles.js", "lineno": 1, "colno": 39}]
  406. },
  407. }
  408. ]
  409. },
  410. }
  411. event = self.post_and_retrieve_event(data)
  412. assert "errors" not in event.data
  413. exception = event.interfaces["exception"]
  414. frame_list = exception.values[0].stacktrace.frames
  415. assert len(frame_list) == 1
  416. frame = frame_list[0]
  417. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  418. assert frame.context_line == "\treturn a * b;"
  419. assert frame.post_context == [
  420. "}",
  421. "function divide(a, b) {",
  422. '\t"use strict";',
  423. "\ttry {",
  424. "\t\treturn multiply(add(a, b), a, b) / c;",
  425. ]
  426. @responses.activate
  427. def test_indexed_sourcemap_source_expansion(self):
  428. responses.add(
  429. responses.GET,
  430. "http://example.com/indexed.min.js",
  431. body=load_fixture("indexed.min.js"),
  432. content_type="application/javascript; charset=utf-8",
  433. )
  434. responses.add(
  435. responses.GET,
  436. "http://example.com/file1.js",
  437. body=load_fixture("file1.js"),
  438. content_type="application/javascript; charset=utf-8",
  439. )
  440. responses.add(
  441. responses.GET,
  442. "http://example.com/file2.js",
  443. body=load_fixture("file2.js"),
  444. content_type="application/javascript; charset=utf-8",
  445. )
  446. responses.add(
  447. responses.GET,
  448. "http://example.com/indexed.sourcemap.js",
  449. body=load_fixture("indexed.sourcemap.js"),
  450. content_type="application/json; charset=utf-8",
  451. )
  452. data = {
  453. "timestamp": self.min_ago,
  454. "message": "hello",
  455. "platform": "javascript",
  456. "exception": {
  457. "values": [
  458. {
  459. "type": "Error",
  460. "stacktrace": {
  461. "frames": [
  462. {
  463. "abs_path": "http://example.com/indexed.min.js",
  464. "filename": "indexed.min.js",
  465. "lineno": 1,
  466. "colno": 39,
  467. },
  468. {
  469. "abs_path": "http://example.com/indexed.min.js",
  470. "filename": "indexed.min.js",
  471. "lineno": 2,
  472. "colno": 44,
  473. },
  474. ]
  475. },
  476. }
  477. ]
  478. },
  479. }
  480. event = self.post_and_retrieve_event(data)
  481. assert "errors" not in event.data
  482. exception = event.interfaces["exception"]
  483. frame_list = exception.values[0].stacktrace.frames
  484. frame = frame_list[0]
  485. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  486. expected = "\treturn a + b; // fôo"
  487. assert frame.context_line == expected
  488. assert frame.post_context == ["}", ""]
  489. raw_frame_list = exception.values[0].raw_stacktrace.frames
  490. raw_frame = raw_frame_list[0]
  491. assert not raw_frame.pre_context
  492. assert raw_frame.context_line == 'function add(a,b){"use strict";return a+b}'
  493. assert raw_frame.post_context == [
  494. 'function multiply(a,b){"use strict";return a*b}function divide(a,b){"use strict";try{return multiply('
  495. "add(a,b),a,b)/c}catch(e){Raven.captureE {snip}",
  496. "//# sourceMappingURL=indexed.sourcemap.js",
  497. "",
  498. ]
  499. assert raw_frame.lineno == 1
  500. frame = frame_list[1]
  501. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  502. assert frame.context_line == "\treturn a * b;"
  503. assert frame.post_context == [
  504. "}",
  505. "function divide(a, b) {",
  506. '\t"use strict";',
  507. "\ttry {",
  508. "\t\treturn multiply(add(a, b), a, b) / c;",
  509. ]
  510. raw_frame = raw_frame_list[1]
  511. assert raw_frame.pre_context == ['function add(a,b){"use strict";return a+b}']
  512. assert (
  513. raw_frame.context_line
  514. == 'function multiply(a,b){"use strict";return a*b}function divide(a,b){"use strict";try{return multiply('
  515. "add(a,b),a,b)/c}catch(e){Raven.captureE {snip}"
  516. )
  517. assert raw_frame.post_context == ["//# sourceMappingURL=indexed.sourcemap.js", ""]
  518. assert raw_frame.lineno == 2
  519. @responses.activate
  520. def test_expansion_via_release_artifacts(self):
  521. project = self.project
  522. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  523. release.add_project(project)
  524. # file.min.js
  525. # ------------
  526. f_minified = File.objects.create(
  527. name="file.min.js", type="release.file", headers={"Content-Type": "application/json"}
  528. )
  529. f_minified.putfile(open(get_fixture_path("file.min.js"), "rb"))
  530. # Intentionally omit hostname - use alternate artifact path lookup instead
  531. # /file1.js vs http://example.com/file1.js
  532. ReleaseFile.objects.create(
  533. name=f"~/{f_minified.name}?foo=bar",
  534. release_id=release.id,
  535. organization_id=project.organization_id,
  536. file=f_minified,
  537. )
  538. # file1.js
  539. # ---------
  540. f1 = File.objects.create(
  541. name="file1.js", type="release.file", headers={"Content-Type": "application/json"}
  542. )
  543. f1.putfile(open(get_fixture_path("file1.js"), "rb"))
  544. ReleaseFile.objects.create(
  545. name=f"http://example.com/{f1.name}",
  546. release_id=release.id,
  547. organization_id=project.organization_id,
  548. file=f1,
  549. )
  550. # file2.js
  551. # ----------
  552. f2 = File.objects.create(
  553. name="file2.js", type="release.file", headers={"Content-Type": "application/json"}
  554. )
  555. f2.putfile(open(get_fixture_path("file2.js"), "rb"))
  556. ReleaseFile.objects.create(
  557. name=f"http://example.com/{f2.name}",
  558. release_id=release.id,
  559. organization_id=project.organization_id,
  560. file=f2,
  561. )
  562. # To verify that the full url has priority over the relative url,
  563. # we will also add a second ReleaseFile alias for file2.js (f3) w/o
  564. # hostname that points to an empty file. If the processor chooses
  565. # this empty file over the correct file2.js, it will not locate
  566. # context for the 2nd frame.
  567. f2_empty = File.objects.create(
  568. name="empty.js", type="release.file", headers={"Content-Type": "application/json"}
  569. )
  570. f2_empty.putfile(open(get_fixture_path("empty.js"), "rb"))
  571. ReleaseFile.objects.create(
  572. name=f"~/{f2.name}", # intentionally using f2.name ("file2.js")
  573. release_id=release.id,
  574. organization_id=project.organization_id,
  575. file=f2_empty,
  576. )
  577. # sourcemap
  578. # ----------
  579. f_sourcemap = File.objects.create(
  580. name="file.sourcemap.js",
  581. type="release.file",
  582. headers={"Content-Type": "application/json"},
  583. )
  584. f_sourcemap.putfile(open(get_fixture_path("file.sourcemap.js"), "rb"))
  585. ReleaseFile.objects.create(
  586. name=f"http://example.com/{f_sourcemap.name}",
  587. release_id=release.id,
  588. organization_id=project.organization_id,
  589. file=f_sourcemap,
  590. )
  591. data = {
  592. "timestamp": self.min_ago,
  593. "message": "hello",
  594. "platform": "javascript",
  595. "release": "abc",
  596. "exception": {
  597. "values": [
  598. {
  599. "type": "Error",
  600. "stacktrace": {
  601. "frames": [
  602. {
  603. "abs_path": "http://example.com/file.min.js?foo=bar",
  604. "filename": "file.min.js",
  605. "lineno": 1,
  606. "colno": 39,
  607. },
  608. {
  609. "abs_path": "http://example.com/file.min.js?foo=bar",
  610. "filename": "file.min.js",
  611. "lineno": 1,
  612. "colno": 79,
  613. },
  614. ]
  615. },
  616. }
  617. ]
  618. },
  619. }
  620. event = self.post_and_retrieve_event(data)
  621. assert "errors" not in event.data
  622. exception = event.interfaces["exception"]
  623. frame_list = exception.values[0].stacktrace.frames
  624. frame = frame_list[0]
  625. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  626. assert frame.context_line == "\treturn a + b; // fôo"
  627. assert frame.post_context == ["}", ""]
  628. frame = frame_list[1]
  629. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  630. assert frame.context_line == "\treturn a * b;"
  631. assert frame.post_context == [
  632. "}",
  633. "function divide(a, b) {",
  634. '\t"use strict";',
  635. "\ttry {",
  636. "\t\treturn multiply(add(a, b), a, b) / c;",
  637. ]
  638. @responses.activate
  639. def test_expansion_via_distribution_release_artifacts(self):
  640. project = self.project
  641. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  642. release.add_project(project)
  643. dist = release.add_dist("foo")
  644. # file.min.js
  645. # ------------
  646. f_minified = File.objects.create(
  647. name="file.min.js", type="release.file", headers={"Content-Type": "application/json"}
  648. )
  649. f_minified.putfile(open(get_fixture_path("file.min.js"), "rb"))
  650. # Intentionally omit hostname - use alternate artifact path lookup instead
  651. # /file1.js vs http://example.com/file1.js
  652. ReleaseFile.objects.create(
  653. name=f"~/{f_minified.name}?foo=bar",
  654. release_id=release.id,
  655. dist_id=dist.id,
  656. organization_id=project.organization_id,
  657. file=f_minified,
  658. )
  659. # file1.js
  660. # ---------
  661. f1 = File.objects.create(
  662. name="file1.js", type="release.file", headers={"Content-Type": "application/json"}
  663. )
  664. f1.putfile(open(get_fixture_path("file1.js"), "rb"))
  665. ReleaseFile.objects.create(
  666. name=f"http://example.com/{f1.name}",
  667. release_id=release.id,
  668. dist_id=dist.id,
  669. organization_id=project.organization_id,
  670. file=f1,
  671. )
  672. # file2.js
  673. # ----------
  674. f2 = File.objects.create(
  675. name="file2.js", type="release.file", headers={"Content-Type": "application/json"}
  676. )
  677. f2.putfile(open(get_fixture_path("file2.js"), "rb"))
  678. ReleaseFile.objects.create(
  679. name=f"http://example.com/{f2.name}",
  680. release_id=release.id,
  681. dist_id=dist.id,
  682. organization_id=project.organization_id,
  683. file=f2,
  684. )
  685. # To verify that the full url has priority over the relative url,
  686. # we will also add a second ReleaseFile alias for file2.js (f3) w/o
  687. # hostname that points to an empty file. If the processor chooses
  688. # this empty file over the correct file2.js, it will not locate
  689. # context for the 2nd frame.
  690. f2_empty = File.objects.create(
  691. name="empty.js", type="release.file", headers={"Content-Type": "application/json"}
  692. )
  693. f2_empty.putfile(open(get_fixture_path("empty.js"), "rb"))
  694. ReleaseFile.objects.create(
  695. name=f"~/{f2.name}", # intentionally using f2.name ("file2.js")
  696. release_id=release.id,
  697. dist_id=dist.id,
  698. organization_id=project.organization_id,
  699. file=f2_empty,
  700. )
  701. # sourcemap
  702. # ----------
  703. f_sourcemap = File.objects.create(
  704. name="file.sourcemap.js",
  705. type="release.file",
  706. headers={"Content-Type": "application/json"},
  707. )
  708. f_sourcemap.putfile(open(get_fixture_path("file.sourcemap.js"), "rb"))
  709. ReleaseFile.objects.create(
  710. name=f"http://example.com/{f_sourcemap.name}",
  711. release_id=release.id,
  712. dist_id=dist.id,
  713. organization_id=project.organization_id,
  714. file=f_sourcemap,
  715. )
  716. data = {
  717. "timestamp": self.min_ago,
  718. "message": "hello",
  719. "platform": "javascript",
  720. "release": "abc",
  721. "dist": "foo",
  722. "exception": {
  723. "values": [
  724. {
  725. "type": "Error",
  726. "stacktrace": {
  727. "frames": [
  728. {
  729. "abs_path": "http://example.com/file.min.js?foo=bar",
  730. "filename": "file.min.js",
  731. "lineno": 1,
  732. "colno": 39,
  733. },
  734. {
  735. "abs_path": "http://example.com/file.min.js?foo=bar",
  736. "filename": "file.min.js",
  737. "lineno": 1,
  738. "colno": 79,
  739. },
  740. ]
  741. },
  742. }
  743. ]
  744. },
  745. }
  746. event = self.post_and_retrieve_event(data)
  747. assert "errors" not in event.data
  748. exception = event.interfaces["exception"]
  749. frame_list = exception.values[0].stacktrace.frames
  750. frame = frame_list[0]
  751. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  752. assert frame.context_line == "\treturn a + b; // fôo"
  753. assert frame.post_context == ["}", ""]
  754. frame = frame_list[1]
  755. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  756. assert frame.context_line == "\treturn a * b;"
  757. assert frame.post_context == [
  758. "}",
  759. "function divide(a, b) {",
  760. '\t"use strict";',
  761. "\ttry {",
  762. "\t\treturn multiply(add(a, b), a, b) / c;",
  763. ]
  764. @responses.activate
  765. def test_sourcemap_expansion_with_missing_source(self):
  766. """
  767. Tests a successful sourcemap expansion that points to source files
  768. that are not found.
  769. """
  770. responses.add(
  771. responses.GET,
  772. "http://example.com/file.min.js",
  773. body=load_fixture("file.min.js"),
  774. content_type="application/javascript; charset=utf-8",
  775. )
  776. responses.add(
  777. responses.GET,
  778. "http://example.com/file.sourcemap.js",
  779. body=load_fixture("file.sourcemap.js"),
  780. content_type="application/json; charset=utf-8",
  781. )
  782. responses.add(responses.GET, "http://example.com/file1.js", body="Not Found", status=404)
  783. data = {
  784. "timestamp": self.min_ago,
  785. "message": "hello",
  786. "platform": "javascript",
  787. "exception": {
  788. "values": [
  789. {
  790. "type": "Error",
  791. "stacktrace": {
  792. # Add two frames. We only want to see the
  793. # error once though.
  794. "frames": [
  795. {
  796. "abs_path": "http://example.com/file.min.js",
  797. "filename": "file.min.js",
  798. "lineno": 1,
  799. "colno": 39,
  800. },
  801. {
  802. "abs_path": "http://example.com/file.min.js",
  803. "filename": "file.min.js",
  804. "lineno": 1,
  805. "colno": 39,
  806. },
  807. ]
  808. },
  809. }
  810. ]
  811. },
  812. }
  813. event = self.post_and_retrieve_event(data)
  814. assert event.data["errors"] == [
  815. {"url": "http://example.com/file1.js", "type": "fetch_invalid_http_code", "value": 404}
  816. ]
  817. exception = event.interfaces["exception"]
  818. frame_list = exception.values[0].stacktrace.frames
  819. frame = frame_list[0]
  820. # no context information ...
  821. assert not frame.pre_context
  822. assert not frame.context_line
  823. assert not frame.post_context
  824. # ... but line, column numbers are still correctly mapped
  825. assert frame.lineno == 3
  826. assert frame.colno == 9
  827. @responses.activate
  828. def test_failed_sourcemap_expansion(self):
  829. """
  830. Tests attempting to parse an indexed source map where each section has a "url"
  831. property - this is unsupported and should fail.
  832. """
  833. responses.add(
  834. responses.GET,
  835. "http://example.com/unsupported.min.js",
  836. body=load_fixture("unsupported.min.js"),
  837. content_type="application/javascript; charset=utf-8",
  838. )
  839. responses.add(
  840. responses.GET,
  841. "http://example.com/unsupported.sourcemap.js",
  842. body=load_fixture("unsupported.sourcemap.js"),
  843. content_type="application/json; charset=utf-8",
  844. )
  845. data = {
  846. "timestamp": self.min_ago,
  847. "message": "hello",
  848. "platform": "javascript",
  849. "exception": {
  850. "values": [
  851. {
  852. "type": "Error",
  853. "stacktrace": {
  854. "frames": [
  855. {
  856. "abs_path": "http://example.com/unsupported.min.js",
  857. "filename": "indexed.min.js",
  858. "lineno": 1,
  859. "colno": 39,
  860. }
  861. ]
  862. },
  863. }
  864. ]
  865. },
  866. }
  867. event = self.post_and_retrieve_event(data)
  868. assert event.data["errors"] == [
  869. {"url": "http://example.com/unsupported.sourcemap.js", "type": "js_invalid_source"}
  870. ]
  871. def test_failed_sourcemap_expansion_data_url(self):
  872. data = {
  873. "timestamp": self.min_ago,
  874. "message": "hello",
  875. "platform": "javascript",
  876. "exception": {
  877. "values": [
  878. {
  879. "type": "Error",
  880. "stacktrace": {
  881. "frames": [
  882. {
  883. "abs_path": "data:application/javascript,base46,asfasf",
  884. "filename": "indexed.min.js",
  885. "lineno": 1,
  886. "colno": 39,
  887. }
  888. ]
  889. },
  890. }
  891. ]
  892. },
  893. }
  894. event = self.post_and_retrieve_event(data)
  895. assert event.data["errors"] == [{"url": "<data url>", "type": "js_no_source"}]
  896. @responses.activate
  897. def test_failed_sourcemap_expansion_missing_location_entirely(self):
  898. responses.add(
  899. responses.GET,
  900. "http://example.com/indexed.min.js",
  901. body="//# sourceMappingURL=indexed.sourcemap.js",
  902. )
  903. responses.add(responses.GET, "http://example.com/indexed.sourcemap.js", body="{}")
  904. data = {
  905. "timestamp": self.min_ago,
  906. "message": "hello",
  907. "platform": "javascript",
  908. "exception": {
  909. "values": [
  910. {
  911. "type": "Error",
  912. "stacktrace": {
  913. "frames": [
  914. {
  915. "abs_path": "http://example.com/indexed.min.js",
  916. "filename": "indexed.min.js",
  917. "lineno": 1,
  918. "colno": 1,
  919. },
  920. {
  921. "abs_path": "http://example.com/indexed.min.js",
  922. "filename": "indexed.min.js",
  923. },
  924. ]
  925. },
  926. }
  927. ]
  928. },
  929. }
  930. event = self.post_and_retrieve_event(data)
  931. assert "errors" not in event.data
  932. @responses.activate
  933. def test_html_response_for_js(self):
  934. responses.add(
  935. responses.GET,
  936. "http://example.com/file1.js",
  937. body=" <!DOCTYPE html><html><head></head><body></body></html>",
  938. )
  939. responses.add(
  940. responses.GET,
  941. "http://example.com/file2.js",
  942. body="<!doctype html><html><head></head><body></body></html>",
  943. )
  944. responses.add(
  945. responses.GET,
  946. "http://example.com/file.html",
  947. body=(
  948. "<!doctype html><html><head></head><body><script>/*legit case*/</script></body></html>"
  949. ),
  950. )
  951. data = {
  952. "timestamp": self.min_ago,
  953. "message": "hello",
  954. "platform": "javascript",
  955. "exception": {
  956. "values": [
  957. {
  958. "type": "Error",
  959. "stacktrace": {
  960. "frames": [
  961. {
  962. "abs_path": "http://example.com/file1.js",
  963. "filename": "file.min.js",
  964. "lineno": 1,
  965. "colno": 39,
  966. },
  967. {
  968. "abs_path": "http://example.com/file2.js",
  969. "filename": "file.min.js",
  970. "lineno": 1,
  971. "colno": 39,
  972. },
  973. {
  974. "abs_path": "http://example.com/file.html",
  975. "filename": "file.html",
  976. "lineno": 1,
  977. "colno": 1,
  978. },
  979. ]
  980. },
  981. }
  982. ]
  983. },
  984. }
  985. event = self.post_and_retrieve_event(data)
  986. assert event.data["errors"] == [
  987. {"url": "http://example.com/file1.js", "type": "js_invalid_content"},
  988. {"url": "http://example.com/file2.js", "type": "js_invalid_content"},
  989. ]
  990. def _test_expansion_via_release_archive(self, link_sourcemaps: bool):
  991. project = self.project
  992. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  993. release.add_project(project)
  994. manifest = {
  995. "org": self.organization.slug,
  996. "release": release.version,
  997. "files": {
  998. "files/_/_/file.min.js": {
  999. "url": "http://example.com/file.min.js",
  1000. },
  1001. "files/_/_/file1.js": {
  1002. "url": "http://example.com/file1.js",
  1003. },
  1004. "files/_/_/file2.js": {
  1005. "url": "http://example.com/file2.js",
  1006. },
  1007. "files/_/_/file.sourcemap.js": {
  1008. "url": "http://example.com/file.sourcemap.js",
  1009. },
  1010. },
  1011. }
  1012. file_like = BytesIO()
  1013. with zipfile.ZipFile(file_like, "w") as zip:
  1014. for rel_path, entry in manifest["files"].items():
  1015. name = os.path.basename(rel_path)
  1016. content = load_fixture(name)
  1017. if name == "file.min.js" and not link_sourcemaps:
  1018. # Remove link to source map, add to header instead
  1019. content = content.replace(b"//@ sourceMappingURL=file.sourcemap.js", b"")
  1020. entry["headers"] = {"SourceMap": "/file.sourcemap.js"}
  1021. zip.writestr(rel_path, content)
  1022. zip.writestr("manifest.json", json.dumps(manifest))
  1023. file_like.seek(0)
  1024. file = File.objects.create(name="doesnt_matter", type="release.bundle")
  1025. file.putfile(file_like)
  1026. update_artifact_index(release, None, file)
  1027. data = {
  1028. "timestamp": self.min_ago,
  1029. "message": "hello",
  1030. "platform": "javascript",
  1031. "release": "abc",
  1032. "exception": {
  1033. "values": [
  1034. {
  1035. "type": "Error",
  1036. "stacktrace": {
  1037. "frames": [
  1038. {
  1039. "abs_path": "http://example.com/file.min.js",
  1040. "filename": "file.min.js",
  1041. "lineno": 1,
  1042. "colno": 39,
  1043. },
  1044. {
  1045. "abs_path": "http://example.com/file.min.js",
  1046. "filename": "file.min.js",
  1047. "lineno": 1,
  1048. "colno": 79,
  1049. },
  1050. ]
  1051. },
  1052. }
  1053. ]
  1054. },
  1055. }
  1056. event = self.post_and_retrieve_event(data)
  1057. assert "errors" not in event.data
  1058. exception = event.interfaces["exception"]
  1059. frame_list = exception.values[0].stacktrace.frames
  1060. frame = frame_list[0]
  1061. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1062. assert frame.context_line == "\treturn a + b; // fôo"
  1063. assert frame.post_context == ["}", ""]
  1064. frame = frame_list[1]
  1065. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  1066. assert frame.context_line == "\treturn a * b;"
  1067. assert frame.post_context == [
  1068. "}",
  1069. "function divide(a, b) {",
  1070. '\t"use strict";',
  1071. "\ttry {",
  1072. "\t\treturn multiply(add(a, b), a, b) / c;",
  1073. ]
  1074. def test_expansion_via_release_archive(self):
  1075. self._test_expansion_via_release_archive(link_sourcemaps=True)
  1076. def test_expansion_via_release_archive_no_sourcemap_link(self):
  1077. self._test_expansion_via_release_archive(link_sourcemaps=False)
  1078. def test_node_processing(self):
  1079. project = self.project
  1080. release = Release.objects.create(
  1081. organization_id=project.organization_id, version="nodeabc123"
  1082. )
  1083. release.add_project(project)
  1084. f_minified = File.objects.create(
  1085. name="dist.bundle.js",
  1086. type="release.file",
  1087. headers={"Content-Type": "application/javascript"},
  1088. )
  1089. f_minified.putfile(open(get_fixture_path("dist.bundle.js"), "rb"))
  1090. ReleaseFile.objects.create(
  1091. name=f"~/{f_minified.name}",
  1092. release_id=release.id,
  1093. organization_id=project.organization_id,
  1094. file=f_minified,
  1095. )
  1096. f_sourcemap = File.objects.create(
  1097. name="dist.bundle.js.map",
  1098. type="release.file",
  1099. headers={"Content-Type": "application/javascript"},
  1100. )
  1101. f_sourcemap.putfile(open(get_fixture_path("dist.bundle.js.map"), "rb"))
  1102. ReleaseFile.objects.create(
  1103. name=f"~/{f_sourcemap.name}",
  1104. release_id=release.id,
  1105. organization_id=project.organization_id,
  1106. file=f_sourcemap,
  1107. )
  1108. data = {
  1109. "timestamp": self.min_ago,
  1110. "message": "hello",
  1111. "platform": "node",
  1112. "release": "nodeabc123",
  1113. "exception": {
  1114. "values": [
  1115. {
  1116. "type": "Error",
  1117. "stacktrace": {
  1118. "frames": [
  1119. {
  1120. "filename": "app:///dist.bundle.js",
  1121. "function": "bar",
  1122. "lineno": 9,
  1123. "colno": 2321,
  1124. },
  1125. {
  1126. "filename": "app:///dist.bundle.js",
  1127. "function": "foo",
  1128. "lineno": 3,
  1129. "colno": 2308,
  1130. },
  1131. {
  1132. "filename": "app:///dist.bundle.js",
  1133. "function": "App",
  1134. "lineno": 3,
  1135. "colno": 1011,
  1136. },
  1137. {
  1138. "filename": "app:///dist.bundle.js",
  1139. "function": "Object.<anonymous>",
  1140. "lineno": 1,
  1141. "colno": 1014,
  1142. },
  1143. {
  1144. "filename": "app:///dist.bundle.js",
  1145. "function": "__webpack_require__",
  1146. "lineno": 20,
  1147. "colno": 30,
  1148. },
  1149. {
  1150. "filename": "app:///dist.bundle.js",
  1151. "function": "<unknown>",
  1152. "lineno": 18,
  1153. "colno": 63,
  1154. },
  1155. ]
  1156. },
  1157. }
  1158. ]
  1159. },
  1160. }
  1161. event = self.post_and_retrieve_event(data)
  1162. exception = event.interfaces["exception"]
  1163. frame_list = exception.values[0].stacktrace.frames
  1164. assert len(frame_list) == 6
  1165. import pprint
  1166. pprint.pprint(frame_list[0].__dict__)
  1167. pprint.pprint(frame_list[1].__dict__)
  1168. pprint.pprint(frame_list[2].__dict__)
  1169. pprint.pprint(frame_list[3].__dict__)
  1170. pprint.pprint(frame_list[4].__dict__)
  1171. pprint.pprint(frame_list[5].__dict__)
  1172. assert frame_list[0].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1173. assert frame_list[0].function == "bar"
  1174. assert frame_list[0].lineno == 8
  1175. assert frame_list[1].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1176. assert frame_list[1].function == "foo"
  1177. assert frame_list[1].lineno == 2
  1178. assert frame_list[2].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1179. assert frame_list[2].function == "App"
  1180. assert frame_list[2].lineno == 2
  1181. assert frame_list[3].abs_path == "app:///dist.bundle.js"
  1182. assert frame_list[3].function == "Object.<anonymous>"
  1183. assert frame_list[3].lineno == 1
  1184. assert frame_list[4].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1185. assert frame_list[4].function == "__webpack_require__"
  1186. assert frame_list[4].lineno == 19
  1187. assert frame_list[5].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1188. assert frame_list[5].function == "<unknown>"
  1189. assert frame_list[5].lineno == 16
  1190. @responses.activate
  1191. def test_no_fetch_from_http(self):
  1192. responses.add(
  1193. responses.GET,
  1194. "http://example.com/node_app.min.js",
  1195. body=load_fixture("node_app.min.js"),
  1196. content_type="application/javascript; charset=utf-8",
  1197. )
  1198. responses.add(
  1199. responses.GET,
  1200. "http://example.com/node_app.min.js.map",
  1201. body=load_fixture("node_app.min.js.map"),
  1202. content_type="application/javascript; charset=utf-8",
  1203. )
  1204. data = {
  1205. "timestamp": self.min_ago,
  1206. "message": "hello",
  1207. "platform": "node",
  1208. "exception": {
  1209. "values": [
  1210. {
  1211. "type": "Error",
  1212. "stacktrace": {
  1213. "frames": [
  1214. {
  1215. "abs_path": "node_bootstrap.js",
  1216. "filename": "node_bootstrap.js",
  1217. "lineno": 1,
  1218. "colno": 38,
  1219. },
  1220. {
  1221. "abs_path": "timers.js",
  1222. "filename": "timers.js",
  1223. "lineno": 1,
  1224. "colno": 39,
  1225. },
  1226. {
  1227. "abs_path": "webpack:///internal",
  1228. "filename": "internal",
  1229. "lineno": 1,
  1230. "colno": 43,
  1231. },
  1232. {
  1233. "abs_path": "webpack:///~/some_dep/file.js",
  1234. "filename": "file.js",
  1235. "lineno": 1,
  1236. "colno": 41,
  1237. },
  1238. {
  1239. "abs_path": "webpack:///./node_modules/file.js",
  1240. "filename": "file.js",
  1241. "lineno": 1,
  1242. "colno": 42,
  1243. },
  1244. {
  1245. "abs_path": "http://example.com/node_app.min.js",
  1246. "filename": "node_app.min.js",
  1247. "lineno": 1,
  1248. "colno": 40,
  1249. },
  1250. ]
  1251. },
  1252. }
  1253. ]
  1254. },
  1255. }
  1256. event = self.post_and_retrieve_event(data)
  1257. exception = event.interfaces["exception"]
  1258. frame_list = exception.values[0].stacktrace.frames
  1259. # This one should not process, so this one should be none.
  1260. assert exception.values[0].raw_stacktrace is None
  1261. # None of the in app should update
  1262. for x in range(6):
  1263. assert not frame_list[x].in_app
  1264. @responses.activate
  1265. def test_html_file_with_query_param_ending_with_js_extension(self):
  1266. responses.add(
  1267. responses.GET,
  1268. "http://example.com/file.html",
  1269. body=(
  1270. "<!doctype html><html><head></head><body><script>/*legit case*/</script></body></html>"
  1271. ),
  1272. )
  1273. data = {
  1274. "timestamp": self.min_ago,
  1275. "message": "hello",
  1276. "platform": "javascript",
  1277. "exception": {
  1278. "values": [
  1279. {
  1280. "type": "Error",
  1281. "stacktrace": {
  1282. "frames": [
  1283. {
  1284. "abs_path": "http://example.com/file.html?sw=iddqd1337.js",
  1285. "filename": "file.html",
  1286. "lineno": 1,
  1287. "colno": 1,
  1288. },
  1289. ]
  1290. },
  1291. }
  1292. ]
  1293. },
  1294. }
  1295. event = self.post_and_retrieve_event(data)
  1296. assert "errors" not in event.data