Skip to content

Commit 8eee62d

Browse files
Miscellaneous small fixes (nlohmann#3643)
* serve_header: suppress lgtm warning * serve_header: fix exit code * serve_header: replace deprecated ssl.wrap_socket() * Add checks to unit test readme * Add lgtm configuration file
1 parent f1e3407 commit 8eee62d

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

.lgtm.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
path_classifiers:
2+
thirdparty:
3+
- /tools/amalgamate
4+
- /tools/cpplint

tests/src/unit-readme.cpp

+16-17
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ TEST_CASE("README" * doctest::skip())
106106
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal)
107107

108108
// or even nicer with a raw string literal
109-
auto j2 = R"(
110-
{
111-
"happy": true,
112-
"pi": 3.141
113-
}
114-
)"_json;
109+
auto j2 = R"({
110+
"happy": true,
111+
"pi": 3.141
112+
})"_json;
115113

116114
// or explicitly
117115
auto j3 = json::parse(R"({"happy": true, "pi": 3.141})");
@@ -160,10 +158,10 @@ TEST_CASE("README" * doctest::skip())
160158
CHECK(foo == true);
161159

162160
// other stuff
163-
j.size(); // 3 entries
164-
j.empty(); // false
165-
j.type(); // json::value_t::array
166-
j.clear(); // the array is empty again
161+
CHECK(j.size() == 3); // 3 entries
162+
CHECK_FALSE(j.empty()); // false
163+
CHECK(j.type() == json::value_t::array); // json::value_t::array
164+
j.clear(); // the array is empty again
167165

168166
// create an object
169167
json o;
@@ -172,6 +170,7 @@ TEST_CASE("README" * doctest::skip())
172170
o["baz"] = 3.141;
173171

174172
// find an entry
173+
CHECK(o.find("foo") != o.end());
175174
if (o.find("foo") != o.end())
176175
{
177176
// there is an entry with key "foo"
@@ -266,20 +265,20 @@ TEST_CASE("README" * doctest::skip())
266265
{
267266
// a JSON value
268267
json j_original = R"({
269-
"baz": ["one", "two", "three"],
270-
"foo": "bar"
271-
})"_json;
268+
"baz": ["one", "two", "three"],
269+
"foo": "bar"
270+
})"_json;
272271

273272
// access members with a JSON pointer (RFC 6901)
274273
j_original["/baz/1"_json_pointer];
275274
// "two"
276275

277276
// a JSON patch (RFC 6902)
278277
json j_patch = R"([
279-
{ "op": "replace", "path": "/baz", "value": "boo" },
280-
{ "op": "add", "path": "/hello", "value": ["world"] },
281-
{ "op": "remove", "path": "/foo"}
282-
])"_json;
278+
{ "op": "replace", "path": "/baz", "value": "boo" },
279+
{ "op": "add", "path": "/hello", "value": ["world"] },
280+
{ "op": "remove", "path": "/foo"}
281+
])"_json;
283282

284283
// apply the patch
285284
json j_result = j_original.patch(j_patch);

tools/serve_header/serve_header.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def stop(self):
240240
self.observer.stop()
241241
self.observer.join()
242242

243-
class HeaderRequestHandler(SimpleHTTPRequestHandler):
243+
class HeaderRequestHandler(SimpleHTTPRequestHandler): # lgtm[py/missing-call-to-init]
244244
def __init__(self, request, client_address, server):
245245
"""."""
246246
self.worktrees = server.worktrees
@@ -388,11 +388,11 @@ def server_bind(self):
388388
if https.get('enabled', True):
389389
cert_file = https.get('cert_file', 'localhost.pem')
390390
key_file = https.get('key_file', 'localhost-key.pem')
391-
ssl.minimum_version = ssl.TLSVersion.TLSv1_3
392-
ssl.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
393-
httpd.socket = ssl.wrap_socket(httpd.socket,
394-
certfile=cert_file, keyfile=key_file,
395-
server_side=True, ssl_version=ssl.PROTOCOL_TLS)
391+
ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
392+
ssl_ctx.minimum_version = ssl.TLSVersion.TLSv1_2
393+
ssl_ctx.maximum_version = ssl.TLSVersion.MAXIMUM_SUPPORTED
394+
ssl_ctx.load_cert_chain(cert_file, key_file)
395+
httpd.socket = ssl_ctx.wrap_socket(httpd.socket, server_side=True)
396396
scheme = 'HTTPS'
397397
host, port = httpd.socket.getsockname()[:2]
398398
log.info(f'serving {scheme} on {host} port {port}')
@@ -402,8 +402,8 @@ def server_bind(self):
402402
except KeyboardInterrupt:
403403
log.info('exiting')
404404
except Exception:
405-
log.exception('an error occurred:')
406405
ec = 1
406+
log.exception('an error occurred:')
407407
finally:
408408
if worktrees is not None:
409409
worktrees.stop()

0 commit comments

Comments
 (0)