File: 0035-avoid-415-emptyjson.patch

package info (click to toggle)
pagure 5.14.1%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,008 kB
  • sloc: python: 125,295; javascript: 22,012; makefile: 208; sh: 191
file content (65 lines) | stat: -rw-r--r-- 1,976 bytes parent folder | download | duplicates (2)
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
Description: Don't require JSON to be marked as such

(in particular, this allows requests where having *any*
body data is optional)

Origin: upstream 7235ae9ab0adcbe9def07fe4b6397a8edebb5393
Author: Dominik Wombacher
Forwarded: not-needed

--- a/pagure/flask_app.py
+++ b/pagure/flask_app.py
@@ -20,6 +20,7 @@ import warnings
 from six.moves.urllib.parse import urljoin
 
 import flask
+from flask.wrappers import Request
 import pygit2
 
 from whitenoise import WhiteNoise
@@ -61,11 +62,22 @@ if pagure_config.get("PAGURE_CI_SERVICES
     pagure.lib.query.set_pagure_ci(pagure_config["PAGURE_CI_SERVICES"])
 
 
+# Enforce behavior of 'get_json' to return json even if
+# Content-Type application/json is missing as in werkzeug < v2.1.0
+# https://github.com/pallets/flask/issues/4552#issuecomment-1109785314
+class AnyJsonRequest(Request):
+    def on_json_loading_failed(self, e):
+        if e is not None:
+            return super().on_json_loading_failed(e)
+
+
 def create_app(config=None):
     """ Create the flask application. """
     app = flask.Flask(__name__)
     app.config = pagure_config
 
+    app.request_class = AnyJsonRequest
+
     if config:
         app.config.update(config)
 
--- a/tests/test_pagure_flask_api_boards.py
+++ b/tests/test_pagure_flask_api_boards.py
@@ -158,7 +158,9 @@ class PagureFlaskApiBoardstests(tests.Si
         )
 
     def test_api_board_create_no_data(self):
-        headers = {"Authorization": "token aaabbbcccddd"}
+        headers = {
+            "Authorization": "token aaabbbcccddd",
+        }
         data = {}
         output = self.app.post(
             "/api/0/test/boards", headers=headers, data=data
@@ -497,9 +499,6 @@ class PagureFlaskApiBoardsWithBoardtests
         }
 
         # Remove the board
-        headers = {
-            "Authorization": "token aaabbbcccddd",
-        }
         data = {}
         output = self.app.post(
             "/api/0/test/boards/delete", headers=headers, data=data