pocket-lib.el
pocket-lib.el copied to clipboard
Fix login loop
Bug
When initially logging in using pocket-lib-get
, I get the following error:
(error "pocket-lib: Unable to get request token: (error pocket-lib: Unable to get request token: (error pocket-lib: Unable to get
...
pocket-lib: Unable to get request token: (excessive-lisp-nesting 1601)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))")
Cause
It seems that pocket-lib--authorize
calls pocket-lib--request
which calls pocket-lib--authorize
Fix
The inner calls (in pocket-lib--request-token
and pocket-lib--access-token
) should pass :no-auth 't
to break the loop.
Also, pocket-lib--request-token
should return the cached token when present, otherwise it passes nil
to pocket-lib--access-token
.
Tests
After applying the fixes, the authorization instructions work as described.
Here are some ERTs that illustrate the problems and fixes
(require 'ert)
(require 'pocket-lib)
;; should return the token, but loops
(ert-deftest pocket-lib--request-token-test-initial ()
"Should return a string token on initial run."
(setq pocket-lib--request-token nil) ;; could do (pocket-lib-reset-auth)
(should (stringp (pocket-lib--request-token))))
;; should return cached token, but returns nil
(ert-deftest pocket-lib--request-token-test-cached ()
"Should return the cached token."
(let ((cached-token "foo"))
(setq pocket-lib--request-token cached-token)
(should (equal cached-token (pocket-lib--request-token)))))
;; works as is
(ert-deftest pocket-lib--access-token-test-initial ()
"Should put url in the kill ring."
(let ((request-token "foo"))
(setq pocket-lib--access-token nil)
(setq pocket-lib--access-token-have-opened-browser nil)
(should-error (pocket-lib--access-token request-token))
(should (equal (concat "https://getpocket.com/auth/authorize?request_token=" request-token) (car kill-ring)))))
;; should raise with "bad token", but loops
(ert-deftest pocket-lib--access-token-test-repeat ()
"Should authorize."
(let ((request-token "foo"))
(setq pocket-lib--access-token nil)
(setq pocket-lib--access-token-have-opened-browser 't)
(let ((err (should-error (pocket-lib--access-token request-token))))
(should (string-prefix-p "pocket-lib--access-token: Unable to get access token" (nth 1 err))))))