test_plugin.py 54 KB

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