test_plugin.py 55 KB

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