fix(web/panettone): Don't add extra padding when already padded

Because of math being upsetting, we were adding 4 padding characters to
an already-properly-padded base64 string, which broke tazjin.

This also breaks this function out into panettone.util, and adds a test
for it.

Change-Id: I7bc8a440ad9d0917272dd9f2e341081ea14693da
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5782
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2022-05-28 14:17:36 -04:00 committed by clbot
parent b39ca017c0
commit 1fbed8e317
5 changed files with 20 additions and 8 deletions

View file

@ -78,12 +78,6 @@ the user, however email addresses are temporarily not available."
;; TODO(tazjin): Figure out actual displayName mapping in tokens.
:displayname username)))
(defun add-missing-base64-padding (s)
"Add any missing padding characters to the (un-padded) base64 string `S', such
that it can be successfully decoded by the `BASE64' package"
;; I apologize
(format nil "~A~v@{~A~:*~}" s (- 4 (mod (length s) 4)) "="))
(defun fetch-token (code)
"Fetches the access token on completion of user authentication through
the OAuth2 endpoint and returns the resulting user object."
@ -117,5 +111,5 @@ the OAuth2 endpoint and returns the resulting user object."
;; lisp base64 library doesn't know how to deal with
;; that - we need to add those extra padding
;; characters here.
(add-missing-base64-padding payload)))))
(panettone.util:add-missing-base64-padding payload)))))
(claims-to-user claims))))))