aboutsummaryrefslogtreecommitdiff
path: root/test/mastodon-auth-tests.el
diff options
context:
space:
mode:
authorH Durer <h.duerer@gmail.com>2018-03-10 16:23:23 +0000
committerJohnson Denen <johnson.denen@gmail.com>2018-08-10 22:20:04 -0400
commit12b4620c34a490b324e08d8bb56f77b2ec926f59 (patch)
tree4650a0d8e05341e21dd8afdb04602b8d867b560e /test/mastodon-auth-tests.el
parentae32d2f725dc90e3acb70a03d0a6fd2e4e660ccf (diff)
Optionally use auth-source-search for fetching and saving password. (#181)
* Use auth-source-search for fetching and saving password This gives users the ability to save their password to either the gpg-encrypted ~/.authinfo.gpg or ~/.authinfo so that they don't have to provide username/password each time * Add a new custom var to decide whether to use the auth-source package or not.
Diffstat (limited to 'test/mastodon-auth-tests.el')
-rw-r--r--test/mastodon-auth-tests.el53
1 files changed, 38 insertions, 15 deletions
diff --git a/test/mastodon-auth-tests.el b/test/mastodon-auth-tests.el
index 719a56c..5108f9a 100644
--- a/test/mastodon-auth-tests.el
+++ b/test/mastodon-auth-tests.el
@@ -1,22 +1,45 @@
(require 'el-mock)
-(ert-deftest generate-token ()
+(ert-deftest generate-token--no-storing-credentials ()
"Should make `mastdon-http--post' request to generate auth token."
(with-mock
- (let ((mastodon-instance-url "https://instance.url"))
- (mock (mastodon-client) => '(:client_id "id" :client_secret "secret"))
- (mock (read-string "Email: ") => "foo@bar.com")
- (mock (read-passwd "Password: ") => "password")
- (mock (mastodon-http--post "https://instance.url/oauth/token"
- '(("client_id" . "id")
- ("client_secret" . "secret")
- ("grant_type" . "password")
- ("username" . "foo@bar.com")
- ("password" . "password")
- ("scope" . "read write follow"))
- nil
- :unauthenticated))
- (mastodon-auth--generate-token))))
+ (let ((mastodon-auth-source-file "")
+ (mastodon-instance-url "https://instance.url"))
+ (mock (mastodon-client) => '(:client_id "id" :client_secret "secret"))
+ (mock (read-string "Email: ") => "foo@bar.com")
+ (mock (read-passwd "Password: ") => "password")
+ (mock (mastodon-http--post "https://instance.url/oauth/token"
+ '(("client_id" . "id")
+ ("client_secret" . "secret")
+ ("grant_type" . "password")
+ ("username" . "foo@bar.com")
+ ("password" . "password")
+ ("scope" . "read write follow"))
+ nil
+ :unauthenticated))
+ (mastodon-auth--generate-token))))
+
+(ert-deftest generate-token--storing-credentials ()
+ "Should make `mastdon-http--post' request to generate auth token."
+ (with-mock
+ (let ((mastodon-auth-source-file "~/.authinfo")
+ (mastodon-instance-url "https://instance.url"))
+ (mock (mastodon-client) => '(:client_id "id" :client_secret "secret"))
+ (mock (auth-source-search :create t
+ :host "https://instance.url"
+ :port 443
+ :require '(:user :secret))
+ => '((:user "foo@bar.com" :secret (lambda () "password"))))
+ (mock (mastodon-http--post "https://instance.url/oauth/token"
+ '(("client_id" . "id")
+ ("client_secret" . "secret")
+ ("grant_type" . "password")
+ ("username" . "foo@bar.com")
+ ("password" . "password")
+ ("scope" . "read write follow"))
+ nil
+ :unauthenticated))
+ (mastodon-auth--generate-token))))
(ert-deftest get-token ()
"Should generate token and return JSON response."