nginxinc/nginx-ldap-auth

backend-sample-app.py concat issue on Python 3

joshmarvel opened this issue · 1 comments

backend-sample-app.py line 124 attempts to concatinate bytes literals and strings. On line 123 convert enc from a string to bytes literal. I purpose the following fix.
- enc = enc.decode()
+ enc = bytes(enc.decode(), encoding='utf-8')
self.send_header('Set-Cookie', b'nginxauth=' + enc + b'; httponly')

I tried your patch but it didn't work for me (although maybe for you). The following patch did work for me:

diff --git a/backend-sample-app.py b/backend-sample-app.py
index 970c3ab..0b7b17b 100755
--- a/backend-sample-app.py
+++ b/backend-sample-app.py
@@ -121,7 +121,7 @@ class AppHandler(BaseHTTPRequestHandler):
             enc = base64.b64encode(ensure_bytes(user + ':' + passwd))
             if sys.version_info.major == 3:
                 enc = enc.decode()
-            self.send_header('Set-Cookie', b'nginxauth=' + enc + b'; httponly')
+            self.send_header('Set-Cookie', 'nginxauth=' + enc + '; httponly')
 
             self.send_header('Location', target)
             self.end_headers()