Skip to content

Commit 7c65393

Browse files
committed
Allow deploying using email address
We document that the username is required to deploy, but allow users to log in via their email address, which leads some users to think that their email address is their username. This expands deployment to support using the email address to match what we allow at login. This fixes #620.
1 parent c673317 commit 7c65393

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/clojars/auth.clj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@
108108
(.after (db/get-time) expires_at)))
109109

110110
(defn token-credential-fn [db]
111-
(fn [{:keys [username password]}]
111+
(fn [{username-or-email :username password :password}]
112112
(log/with-context {:tag :authentication
113-
:username username
113+
:username username-or-email
114114
:type :token}
115115
(let [password-hash (when password
116-
(db/hash-deploy-token password))]
117-
(if-let [token (and password
116+
(db/hash-deploy-token password))
117+
username (:user (db/find-user-by-user-or-email db username-or-email))]
118+
(if-let [token (and username
119+
password
118120
(->> (db/find-user-tokens-by-username db username)
119121
(remove :disabled)
120122
(filter #(let [{:keys [token_hash]} %]

test/clojars/integration/uploads_test.clj

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
help/test-port))
4141

4242
(defn deploy
43-
[{:keys [artifact-map coordinates jar-file password pom-file transfer-listener]
44-
:or {transfer-listener (fn [])}}]
43+
[{:keys [artifact-map coordinates jar-file password pom-file transfer-listener username]
44+
:or {transfer-listener (fn [])
45+
username "dantheman"}}]
4546
;; HttpWagon uses a static, inaccessible http client that caches cookies, so
4647
;; we have to clear sessions on each deploy to mimic having new prucesses
4748
;; deploying.
@@ -52,7 +53,7 @@
5253
:jar-file jar-file
5354
:pom-file pom-file
5455
:repository {"test" {:url (repo-url)
55-
:username "dantheman"
56+
:username username
5657
:password password}}
5758
:local-repo help/local-repo
5859
:transfer-listener transfer-listener))
@@ -124,6 +125,18 @@
124125
(within [:td.last-used]
125126
(has (text? (common/format-timestamp now)))))))
126127

128+
(deftest user-can-deploy-using-email-address
129+
(-> (session (help/app-from-system))
130+
(register-as "dantheman" "test@example.org" "password"))
131+
(let [token (create-deploy-token (session (help/app-from-system)) "dantheman" "password" "testing")]
132+
(deploy
133+
{:coordinates '[org.clojars.dantheman/test "0.0.1"]
134+
:jar-file (io/file (io/resource "test.jar"))
135+
:pom-file (help/rewrite-pom (io/file (io/resource "test-0.0.1/test.pom"))
136+
{:groupId "org.clojars.dantheman"})
137+
:username "test@example.org"
138+
:password token})))
139+
127140
(deftest deploying-with-a-scoped-token
128141
(-> (session (help/app-from-system))
129142
(register-as "dantheman" "test@example.org" "password"))

0 commit comments

Comments
 (0)