diff options
author | halcy <halcy@ARARAGI-KUN> | 2022-11-19 02:34:01 +0200 |
---|---|---|
committer | halcy <halcy@ARARAGI-KUN> | 2022-11-19 02:34:01 +0200 |
commit | 853cd82ecb9e1d25f395514b3bb1616071d43493 (patch) | |
tree | a0812b4fa12fadd299886615669f86be6f7bd2cf /tests | |
parent | f26bf0db1dfc93fafa344977bd999a334a55cd36 (diff) | |
download | mastodon.py-853cd82ecb9e1d25f395514b3bb1616071d43493.tar.gz |
add ability to get detailed signup error from create_account
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cassettes/test_app_account_create_invalid.yaml | 245 | ||||
-rw-r--r-- | tests/cassettes/test_push_set.yaml | 122 | ||||
-rw-r--r-- | tests/test_create_app.py | 23 |
3 files changed, 266 insertions, 124 deletions
diff --git a/tests/cassettes/test_app_account_create_invalid.yaml b/tests/cassettes/test_app_account_create_invalid.yaml new file mode 100644 index 0000000..bbf4843 --- /dev/null +++ b/tests/cassettes/test_app_account_create_invalid.yaml | |||
@@ -0,0 +1,245 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: client_name=mastodon.py+generated+test+app&scopes=read+write+follow+push&redirect_uris=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob | ||
4 | headers: | ||
5 | Accept: | ||
6 | - '*/*' | ||
7 | Accept-Encoding: | ||
8 | - gzip, deflate | ||
9 | Connection: | ||
10 | - keep-alive | ||
11 | Content-Length: | ||
12 | - '122' | ||
13 | Content-Type: | ||
14 | - application/x-www-form-urlencoded | ||
15 | User-Agent: | ||
16 | - python-requests/2.28.1 | ||
17 | method: POST | ||
18 | uri: http://localhost:3000/api/v1/apps | ||
19 | response: | ||
20 | body: | ||
21 | string: '{"id":"4","name":"mastodon.py generated test app","website":null,"redirect_uri":"urn:ietf:wg:oauth:2.0:oob","client_id":"OueO_7-PGuI_wJwqr3gJCO3Mfp-CnB7ntLm2BDNgwoE","client_secret":"i74hCQQyscpk-AoXt8gL1lBYLlgsQw7r-vP_cuKWquA","vapid_key":"BFu6DBpfcm8_h8gm3rHUkfaOLg7azvYN_auFI4KcNuh5SLBVMhTkKKvUaLENtA_c6v5Hmrucvh0WwsN1o9NFQRU="}' | ||
22 | headers: | ||
23 | Cache-Control: | ||
24 | - no-store | ||
25 | Content-Security-Policy: | ||
26 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
27 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
28 | style-src ''self'' http://localhost:3000 ''nonce-eWGkzakxkoJqETI+J7AOfA==''; | ||
29 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
30 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
31 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
32 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
33 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
34 | worker-src ''self'' blob: http://localhost:3000' | ||
35 | Content-Type: | ||
36 | - application/json; charset=utf-8 | ||
37 | ETag: | ||
38 | - W/"e57c57d0ecbadb4122581beb6057bf7b" | ||
39 | Referrer-Policy: | ||
40 | - strict-origin-when-cross-origin | ||
41 | Transfer-Encoding: | ||
42 | - chunked | ||
43 | Vary: | ||
44 | - Accept, Origin | ||
45 | X-Content-Type-Options: | ||
46 | - nosniff | ||
47 | X-Download-Options: | ||
48 | - noopen | ||
49 | X-Frame-Options: | ||
50 | - SAMEORIGIN | ||
51 | X-Permitted-Cross-Domain-Policies: | ||
52 | - none | ||
53 | X-Request-Id: | ||
54 | - c5d33842-2156-4850-ac91-154f71f72d2e | ||
55 | X-Runtime: | ||
56 | - '0.017495' | ||
57 | X-XSS-Protection: | ||
58 | - 1; mode=block | ||
59 | status: | ||
60 | code: 200 | ||
61 | message: OK | ||
62 | - request: | ||
63 | body: null | ||
64 | headers: | ||
65 | Accept: | ||
66 | - '*/*' | ||
67 | Accept-Encoding: | ||
68 | - gzip, deflate | ||
69 | Connection: | ||
70 | - keep-alive | ||
71 | User-Agent: | ||
72 | - mastodonpy | ||
73 | method: GET | ||
74 | uri: http://localhost:3000/api/v1/instance/ | ||
75 | response: | ||
76 | body: | ||
77 | string: '{"uri":"localhost:3000","title":"Mastodon","short_description":"","description":"","email":"","version":"4.0.0rc2","urls":{"streaming_api":"ws://localhost:4000"},"stats":{"user_count":4,"status_count":5,"domain_count":0},"thumbnail":"http://localhost:3000/packs/media/images/preview-6399aebd96ccf025654e2977454f168f.png","languages":["en"],"registrations":true,"approval_required":false,"invites_enabled":true,"configuration":{"accounts":{"max_featured_tags":10},"statuses":{"max_characters":500,"max_media_attachments":4,"characters_reserved_per_url":23},"media_attachments":{"supported_mime_types":["image/jpeg","image/png","image/gif","image/heic","image/heif","image/webp","image/avif","video/webm","video/mp4","video/quicktime","video/ogg","audio/wave","audio/wav","audio/x-wav","audio/x-pn-wave","audio/vnd.wave","audio/ogg","audio/vorbis","audio/mpeg","audio/mp3","audio/webm","audio/flac","audio/aac","audio/m4a","audio/x-m4a","audio/mp4","audio/3gpp","video/x-ms-asf"],"image_size_limit":10485760,"image_matrix_limit":16777216,"video_size_limit":41943040,"video_frame_rate_limit":60,"video_matrix_limit":2304000},"polls":{"max_options":4,"max_characters_per_option":50,"min_expiration":300,"max_expiration":2629746}},"contact_account":null,"rules":[]}' | ||
78 | headers: | ||
79 | Cache-Control: | ||
80 | - max-age=180, public | ||
81 | Content-Security-Policy: | ||
82 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
83 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
84 | style-src ''self'' http://localhost:3000 ''nonce-pTVYgmBqNUhkaog/3BIWrg==''; | ||
85 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
86 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
87 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
88 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
89 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
90 | worker-src ''self'' blob: http://localhost:3000' | ||
91 | Content-Type: | ||
92 | - application/json; charset=utf-8 | ||
93 | Date: | ||
94 | - Sat, 19 Nov 2022 00:05:11 GMT | ||
95 | ETag: | ||
96 | - W/"58e74f5c697f043d86089eae87509b84" | ||
97 | Referrer-Policy: | ||
98 | - strict-origin-when-cross-origin | ||
99 | Transfer-Encoding: | ||
100 | - chunked | ||
101 | Vary: | ||
102 | - Accept, Origin | ||
103 | X-Content-Type-Options: | ||
104 | - nosniff | ||
105 | X-Download-Options: | ||
106 | - noopen | ||
107 | X-Frame-Options: | ||
108 | - SAMEORIGIN | ||
109 | X-Permitted-Cross-Domain-Policies: | ||
110 | - none | ||
111 | X-Request-Id: | ||
112 | - 3f3580e9-a01c-4cb3-a8ff-e933a5b0a878 | ||
113 | X-Runtime: | ||
114 | - '0.038202' | ||
115 | X-XSS-Protection: | ||
116 | - 1; mode=block | ||
117 | status: | ||
118 | code: 200 | ||
119 | message: OK | ||
120 | - request: | ||
121 | body: scope=read+write+follow+push&client_id=OueO_7-PGuI_wJwqr3gJCO3Mfp-CnB7ntLm2BDNgwoE&client_secret=i74hCQQyscpk-AoXt8gL1lBYLlgsQw7r-vP_cuKWquA&grant_type=client_credentials | ||
122 | headers: | ||
123 | Accept: | ||
124 | - '*/*' | ||
125 | Accept-Encoding: | ||
126 | - gzip, deflate | ||
127 | Connection: | ||
128 | - keep-alive | ||
129 | Content-Length: | ||
130 | - '170' | ||
131 | Content-Type: | ||
132 | - application/x-www-form-urlencoded | ||
133 | User-Agent: | ||
134 | - mastodonpy | ||
135 | method: POST | ||
136 | uri: http://localhost:3000/oauth/token | ||
137 | response: | ||
138 | body: | ||
139 | string: '{"access_token":"dDfMnIWbtYShiuOouwPaH1j8ZzGRdcg39Ns0nV5jXpo","token_type":"Bearer","scope":"read | ||
140 | write follow push","created_at":1668816311}' | ||
141 | headers: | ||
142 | Cache-Control: | ||
143 | - no-store | ||
144 | Content-Security-Policy: | ||
145 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
146 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
147 | style-src ''self'' http://localhost:3000 ''nonce-2oP2TTFLzbSaiZa7hgho0w==''; | ||
148 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
149 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
150 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
151 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
152 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
153 | worker-src ''self'' blob: http://localhost:3000' | ||
154 | Content-Type: | ||
155 | - application/json; charset=utf-8 | ||
156 | ETag: | ||
157 | - W/"d29d21f6cdf89562d22826c8794a7259" | ||
158 | Pragma: | ||
159 | - no-cache | ||
160 | Referrer-Policy: | ||
161 | - strict-origin-when-cross-origin | ||
162 | Transfer-Encoding: | ||
163 | - chunked | ||
164 | Vary: | ||
165 | - Accept, Origin | ||
166 | X-Content-Type-Options: | ||
167 | - nosniff | ||
168 | X-Download-Options: | ||
169 | - noopen | ||
170 | X-Frame-Options: | ||
171 | - SAMEORIGIN | ||
172 | X-Permitted-Cross-Domain-Policies: | ||
173 | - none | ||
174 | X-Request-Id: | ||
175 | - 10f9efb8-85eb-4b30-ad16-9656fe53fd44 | ||
176 | X-Runtime: | ||
177 | - '0.022478' | ||
178 | X-XSS-Protection: | ||
179 | - 1; mode=block | ||
180 | status: | ||
181 | code: 200 | ||
182 | message: OK | ||
183 | - request: | ||
184 | body: username=coolguy73878&password=&email=email%40localhost73878&locale=en&client_id=OueO_7-PGuI_wJwqr3gJCO3Mfp-CnB7ntLm2BDNgwoE&client_secret=i74hCQQyscpk-AoXt8gL1lBYLlgsQw7r-vP_cuKWquA | ||
185 | headers: | ||
186 | Accept: | ||
187 | - '*/*' | ||
188 | Accept-Encoding: | ||
189 | - gzip, deflate | ||
190 | Authorization: | ||
191 | - Bearer dDfMnIWbtYShiuOouwPaH1j8ZzGRdcg39Ns0nV5jXpo | ||
192 | Connection: | ||
193 | - keep-alive | ||
194 | Content-Length: | ||
195 | - '182' | ||
196 | Content-Type: | ||
197 | - application/x-www-form-urlencoded | ||
198 | User-Agent: | ||
199 | - mastodonpy | ||
200 | method: POST | ||
201 | uri: http://localhost:3000/api/v1/accounts | ||
202 | response: | ||
203 | body: | ||
204 | string: '{"error":"Validation failed: Password can''t be blank, Service agreement | ||
205 | must be accepted","details":{"password":[{"error":"ERR_BLANK","description":"can''t | ||
206 | be blank"}],"agreement":[{"error":"ERR_ACCEPTED","description":"must be accepted"}]}}' | ||
207 | headers: | ||
208 | Cache-Control: | ||
209 | - no-store | ||
210 | Content-Security-Policy: | ||
211 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
212 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
213 | style-src ''self'' http://localhost:3000 ''nonce-OtVYUk9hlx5v/TcbXUduUA==''; | ||
214 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
215 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
216 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
217 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
218 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
219 | worker-src ''self'' blob: http://localhost:3000' | ||
220 | Content-Type: | ||
221 | - application/json; charset=utf-8 | ||
222 | Referrer-Policy: | ||
223 | - strict-origin-when-cross-origin | ||
224 | Transfer-Encoding: | ||
225 | - chunked | ||
226 | Vary: | ||
227 | - Accept, Origin | ||
228 | X-Content-Type-Options: | ||
229 | - nosniff | ||
230 | X-Download-Options: | ||
231 | - noopen | ||
232 | X-Frame-Options: | ||
233 | - SAMEORIGIN | ||
234 | X-Permitted-Cross-Domain-Policies: | ||
235 | - none | ||
236 | X-Request-Id: | ||
237 | - 48f3d7ec-0b4f-48ce-bf0c-acbec7479c71 | ||
238 | X-Runtime: | ||
239 | - '0.561200' | ||
240 | X-XSS-Protection: | ||
241 | - 1; mode=block | ||
242 | status: | ||
243 | code: 422 | ||
244 | message: Unprocessable Entity | ||
245 | version: 1 | ||
diff --git a/tests/cassettes/test_push_set.yaml b/tests/cassettes/test_push_set.yaml deleted file mode 100644 index 4995277..0000000 --- a/tests/cassettes/test_push_set.yaml +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | interactions: | ||
2 | - request: | ||
3 | body: subscription%5Bendpoint%5D=https%3A%2F%2Fexample.com&subscription%5Bkeys%5D%5Bp256dh%5D=BKFO5w6Uf%2B%2F2wo89ovbphk5Zrb0mcAKjZrIyrX66f2IAijRtuXx4yK6J9hR%2FemKnF2DyQcyx7%2F4IGhKHBk0OTEk%3D&subscription%5Bkeys%5D%5Bauth%5D=6T8gVmd01DhQUbejRj%2Bxmg%3D%3D&policy=none&data%5Balerts%5D%5Bfollow%5D=1&data%5Balerts%5D%5Bfavourite%5D=1&data%5Balerts%5D%5Breblog%5D=1&data%5Balerts%5D%5Bmention%5D=1&data%5Balerts%5D%5Bpoll%5D=1&data%5Balerts%5D%5Bfollow_request%5D=1&data%5Balerts%5D%5Bstatus%5D=1 | ||
4 | headers: | ||
5 | Accept: | ||
6 | - '*/*' | ||
7 | Accept-Encoding: | ||
8 | - gzip, deflate | ||
9 | Authorization: | ||
10 | - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN | ||
11 | Connection: | ||
12 | - keep-alive | ||
13 | Content-Length: | ||
14 | - '489' | ||
15 | Content-Type: | ||
16 | - application/x-www-form-urlencoded | ||
17 | User-Agent: | ||
18 | - tests/v311 | ||
19 | method: POST | ||
20 | uri: http://localhost:3000/api/v1/push/subscription | ||
21 | response: | ||
22 | body: | ||
23 | string: '{"id":5,"endpoint":"https://example.com","alerts":{"mention":true,"status":true,"reblog":true,"follow":true,"follow_request":true,"favourite":true,"poll":true},"server_key":"BFu6DBpfcm8_h8gm3rHUkfaOLg7azvYN_auFI4KcNuh5SLBVMhTkKKvUaLENtA_c6v5Hmrucvh0WwsN1o9NFQRU="}' | ||
24 | headers: | ||
25 | Cache-Control: | ||
26 | - no-store | ||
27 | Content-Security-Policy: | ||
28 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
29 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
30 | style-src ''self'' http://localhost:3000 ''nonce-bz+9uelNbajqElylgkM2Gg==''; | ||
31 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
32 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
33 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
34 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
35 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
36 | worker-src ''self'' blob: http://localhost:3000' | ||
37 | Content-Type: | ||
38 | - application/json; charset=utf-8 | ||
39 | ETag: | ||
40 | - W/"083c3b807a4d145ec452ffd03c768d76" | ||
41 | Referrer-Policy: | ||
42 | - strict-origin-when-cross-origin | ||
43 | Transfer-Encoding: | ||
44 | - chunked | ||
45 | Vary: | ||
46 | - Accept, Origin | ||
47 | X-Content-Type-Options: | ||
48 | - nosniff | ||
49 | X-Download-Options: | ||
50 | - noopen | ||
51 | X-Frame-Options: | ||
52 | - SAMEORIGIN | ||
53 | X-Permitted-Cross-Domain-Policies: | ||
54 | - none | ||
55 | X-Request-Id: | ||
56 | - abb4aec7-a93a-4a99-ba4c-5a290bbbf782 | ||
57 | X-Runtime: | ||
58 | - '0.027761' | ||
59 | X-XSS-Protection: | ||
60 | - 1; mode=block | ||
61 | status: | ||
62 | code: 200 | ||
63 | message: OK | ||
64 | - request: | ||
65 | body: null | ||
66 | headers: | ||
67 | Accept: | ||
68 | - '*/*' | ||
69 | Accept-Encoding: | ||
70 | - gzip, deflate | ||
71 | Authorization: | ||
72 | - Bearer __MASTODON_PY_TEST_ACCESS_TOKEN | ||
73 | Connection: | ||
74 | - keep-alive | ||
75 | User-Agent: | ||
76 | - tests/v311 | ||
77 | method: GET | ||
78 | uri: http://localhost:3000/api/v1/push/subscription | ||
79 | response: | ||
80 | body: | ||
81 | string: '{"id":5,"endpoint":"https://example.com","alerts":{"mention":true,"status":true,"reblog":true,"follow":true,"follow_request":true,"favourite":true,"poll":true},"server_key":"BFu6DBpfcm8_h8gm3rHUkfaOLg7azvYN_auFI4KcNuh5SLBVMhTkKKvUaLENtA_c6v5Hmrucvh0WwsN1o9NFQRU="}' | ||
82 | headers: | ||
83 | Cache-Control: | ||
84 | - no-store | ||
85 | Content-Security-Policy: | ||
86 | - 'base-uri ''none''; default-src ''none''; frame-ancestors ''none''; font-src | ||
87 | ''self'' http://localhost:3000; img-src ''self'' https: data: blob: http://localhost:3000; | ||
88 | style-src ''self'' http://localhost:3000 ''nonce-4kBQ0XWCASsxXi+/Z0W5jA==''; | ||
89 | media-src ''self'' https: data: http://localhost:3000; frame-src ''self'' | ||
90 | https:; manifest-src ''self'' http://localhost:3000; connect-src ''self'' | ||
91 | data: blob: http://localhost:3000 http://localhost:3000 ws://localhost:4000 | ||
92 | ws://localhost:3035 http://localhost:3035; script-src ''self'' ''unsafe-inline'' | ||
93 | ''unsafe-eval'' http://localhost:3000; child-src ''self'' blob: http://localhost:3000; | ||
94 | worker-src ''self'' blob: http://localhost:3000' | ||
95 | Content-Type: | ||
96 | - application/json; charset=utf-8 | ||
97 | ETag: | ||
98 | - W/"083c3b807a4d145ec452ffd03c768d76" | ||
99 | Referrer-Policy: | ||
100 | - strict-origin-when-cross-origin | ||
101 | Transfer-Encoding: | ||
102 | - chunked | ||
103 | Vary: | ||
104 | - Accept, Origin | ||
105 | X-Content-Type-Options: | ||
106 | - nosniff | ||
107 | X-Download-Options: | ||
108 | - noopen | ||
109 | X-Frame-Options: | ||
110 | - SAMEORIGIN | ||
111 | X-Permitted-Cross-Domain-Policies: | ||
112 | - none | ||
113 | X-Request-Id: | ||
114 | - eeb007da-a24b-4e31-b962-30ef0ba3bc16 | ||
115 | X-Runtime: | ||
116 | - '0.008203' | ||
117 | X-XSS-Protection: | ||
118 | - 1; mode=block | ||
119 | status: | ||
120 | code: 200 | ||
121 | message: OK | ||
122 | version: 1 | ||
diff --git a/tests/test_create_app.py b/tests/test_create_app.py index 8a7ea62..c7282df 100644 --- a/tests/test_create_app.py +++ b/tests/test_create_app.py | |||
@@ -70,5 +70,24 @@ def test_app_account_create(): | |||
70 | # We can also test resending (marginally) | 70 | # We can also test resending (marginally) |
71 | test_app_api.email_resend_confirmation() | 71 | test_app_api.email_resend_confirmation() |
72 | 72 | ||
73 | 73 | @pytest.mark.vcr(match_on=['path']) | |
74 | 74 | def test_app_account_create_invalid(): | |
75 | suffix = str(time.time()).replace(".", "")[-5:] | ||
76 | |||
77 | test_app = test_app = Mastodon.create_app( | ||
78 | "mastodon.py generated test app", | ||
79 | api_base_url="http://localhost:3000/" | ||
80 | ) | ||
81 | |||
82 | test_app_api = Mastodon( | ||
83 | test_app[0], | ||
84 | test_app[1], | ||
85 | api_base_url="http://localhost:3000/" | ||
86 | ) | ||
87 | test_token, error = test_app_api.create_account("coolguy" + suffix, "", "email@localhost" + suffix, agreement=False, return_detailed_error=True) | ||
88 | assert test_token is None | ||
89 | assert "details" in error | ||
90 | assert "password" in error.details | ||
91 | assert "password" in error.details | ||
92 | assert not "username" in error.details | ||
93 | \ No newline at end of file | ||