-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SOA-17] Sanitize posts text content (#18)
* feat 🎸 (be): add save/update hook for basic post content sanitization * test 🧪: added post model content parsing functional tests
- Loading branch information
1 parent
550e3fb
commit 72e213f
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { UserFactory } from '#database/factories/user_factory' | ||
import Post from '#models/post' | ||
import { faker } from '@faker-js/faker' | ||
import { test } from '@japa/runner' | ||
|
||
test.group('Posts content parsing', () => { | ||
const link = 'https://www.youtube.com/watch?v=jEeQC6I8nlY' | ||
const contentWithLink = faker.lorem.sentence() + ' ' + link | ||
|
||
const contentWithScript = "<body onload=alert('test1')>" | ||
|
||
test('Sucessfully parses the post content on create', async ({ assert }) => { | ||
const user = await UserFactory.create() | ||
|
||
const postWithScript = await Post.create({ | ||
userId: user.id, | ||
content: contentWithScript, | ||
}) | ||
|
||
const postWithLink = await Post.create({ | ||
userId: user.id, | ||
content: contentWithLink, | ||
}) | ||
|
||
assert.equal(postWithScript.content, "<body onload=alert('test1')>") | ||
assert.equal(postWithLink.content, contentWithLink) | ||
assert.equal(postWithLink.link, link) | ||
}) | ||
|
||
test('Sucessfully parses the post content on update', async ({ assert }) => { | ||
const user = await UserFactory.create() | ||
|
||
const postWithScript = await Post.create({ | ||
userId: user.id, | ||
content: faker.lorem.sentence(), | ||
}) | ||
|
||
const postWithLink = await Post.create({ | ||
userId: user.id, | ||
content: faker.lorem.sentence(), | ||
}) | ||
|
||
postWithScript.content = contentWithScript | ||
|
||
postWithLink.content = contentWithLink | ||
|
||
await postWithScript.save() | ||
await postWithLink.save() | ||
|
||
assert.equal(postWithScript.content, "&lt;body onload=alert('test1')&gt;") | ||
assert.equal(postWithLink.content, contentWithLink) | ||
assert.equal(postWithLink.link, link) | ||
}) | ||
}) |