File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed
tests/adapter_tests_async Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -29,19 +29,25 @@ def to_sanic_response(bolt_resp: BoltResponse) -> HTTPResponse:
29
29
body = bolt_resp .body ,
30
30
headers = bolt_resp .first_headers_without_set_cookie (),
31
31
)
32
+
32
33
for cookie in bolt_resp .cookies ():
33
- for name , c in cookie .items ():
34
- resp .cookies [name ] = c .value
34
+ for key , c in cookie .items ():
35
35
expire_value = c .get ("expires" )
36
- if expire_value is not None and expire_value != "" :
37
- expire = datetime .strptime (expire_value , "%a, %d %b %Y %H:%M:%S %Z" )
38
- resp .cookies [name ]["expires" ] = expire
39
- resp .cookies [name ]["path" ] = c .get ("path" )
40
- resp .cookies [name ]["domain" ] = c .get ("domain" )
41
- if c .get ("max-age" ) is not None and len (c .get ("max-age" )) > 0 : # type: ignore[arg-type]
42
- resp .cookies [name ]["max-age" ] = int (c .get ("max-age" )) # type: ignore[arg-type]
43
- resp .cookies [name ]["secure" ] = True
44
- resp .cookies [name ]["httponly" ] = True
36
+ expires = datetime .strptime (expire_value , "%a, %d %b %Y %H:%M:%S %Z" ) if expire_value else None
37
+ max_age = int (c ["max-age" ]) if c .get ("max-age" ) else None
38
+ path = str (c .get ("path" )) if c .get ("path" ) else "/"
39
+ domain = str (c .get ("domain" )) if c .get ("domain" ) else None
40
+ resp .add_cookie (
41
+ key = key ,
42
+ value = c .value ,
43
+ expires = expires ,
44
+ path = path ,
45
+ domain = domain ,
46
+ max_age = max_age ,
47
+ secure = True ,
48
+ httponly = True ,
49
+ )
50
+
45
51
return resp
46
52
47
53
Original file line number Diff line number Diff line change @@ -218,6 +218,8 @@ async def endpoint(req: Request):
218
218
_ , response = await api .asgi_client .get (url = "/slack/install" )
219
219
assert response .status_code == 200
220
220
assert response .headers .get ("content-type" ) == "text/html; charset=utf-8"
221
+ assert response .headers .get ("set-cookie" ) is not None
222
+ assert response .headers .get ("set-cookie" ).endswith ("; Path=/; Max-Age=600; SameSite=Lax; Secure; HttpOnly" ) is True
221
223
222
224
# NOTE: Although sanic-testing 0.6 does not have this value,
223
225
# Sanic apps properly generate the content-length header
You can’t perform that action at this time.
0 commit comments