-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest_person_identifiers.py
More file actions
105 lines (87 loc) · 3.79 KB
/
Copy pathtest_person_identifiers.py
File metadata and controls
105 lines (87 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from django.test import TestCase
from people.models import PersonIdentifier
from people.tests.factories import PersonFactory
class TestPersonIdentifiers(TestCase):
def setUp(self):
self.person = PersonFactory(pk=1)
def test_str(self):
pi = PersonIdentifier.objects.create(
person=self.person,
value="democlub",
value_type="twitter_username",
internal_identifier="2324",
)
self.assertEqual(str(pi), "1: twitter_username (democlub)")
def test_get_value_html_twitter(self):
pi = PersonIdentifier.objects.create(
person=self.person,
value="democlub",
value_type="twitter_username",
internal_identifier="2324",
)
# Test the value HTML
self.assertEqual(
pi.get_value_html,
"""<a href="https://twitter.com/democlub" rel="nofollow">democlub</a>""",
)
# Test the value type HTML
self.assertEqual(pi.get_value_type_html, "Twitter")
def test_get_value_html_instagram(self):
pi = PersonIdentifier.objects.create(
person=self.person,
value="https://www.instagram.com/democlub",
value_type="instagram_url",
internal_identifier="2324",
)
# Test the value HTML
self.assertEqual(
pi.get_value_html,
"""<a href="https://www.instagram.com/democlub" rel="nofollow">https://www.instagram.com/democlub</a>""",
)
# Test the value type HTML
self.assertEqual(pi.get_value_type_html, "Instagram")
def test_get_value_html_mastodon(self):
pi = PersonIdentifier.objects.create(
person=self.person,
value="https://mastodon.social/@symroe",
value_type="mastodon_username",
internal_identifier="2325",
)
# Test the value type HTML
self.assertEqual(pi.value, "https://mastodon.social/@symroe")
def test_get_value_html_url(self):
pi = PersonIdentifier.objects.create(
person=self.person,
value="https://example.com/",
value_type="homepage",
)
self.assertEqual(
pi.get_value_html,
"""<a href="https://example.com/" rel="nofollow">https://example.com/</a>""",
)
def test_get_value_html_attempted_xss(self):
pi = PersonIdentifier.objects.create(
person=self.person,
value="<script>alert('foo');</script>",
value_type="homepage",
)
self.assertEqual(
pi.get_value_html,
"""<script>alert('foo');</script>""",
)
def test_get_value_html_bad_strings(self):
"""
Some strings from https://github.com/minimaxir/big-list-of-naughty-strings/blob/master/blns.txt
:return:
"""
bad_strings = {
"Œ„´‰ˇÁ¨ˆØ∏”’": "Œ„´‰ˇÁ¨ˆØ∏”’",
"👾 🙇 💁 🙅 🙆 🙋 🙎 🙍": "👾 🙇 💁 🙅 🙆 🙋 🙎 🙍",
"<script>alert('123');</script>": "&lt;script&gt;alert(&#39;123&#39;);&lt;/script&gt;",
"<IMG SRC=javascript:alert('XSS')>": "<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>",
}
for bad, expected in bad_strings.items():
pi = PersonIdentifier(
person=self.person, value=bad, value_type="homepage"
)
self.assertEqual(pi.get_value_html, expected)