Skip to content
Browse files

Merge branch 'promote'

Conflicts:
	project.clj
	src/clojars/db.clj
	src/clojars/friend/registration.clj
	src/clojars/web/user.clj
  • Loading branch information...
2 parents c70d311 + e7bf69d commit 1dc2cc23dde43b6b19873f24593609edd06da028 @technomancy technomancy committed
View
2 README.md
@@ -42,7 +42,7 @@ it. Regardless of how you run it, you first need to do some setup:
* Debian: `apt-get install sqlite3`
* Mac OS X Homebrew: `brew install sqlite`
-3. Run the DB migrations: `lein run -m clojars.db.migrate`
+3. Run the DB migrations: `lein migrate`
To run the application using Leinigen 2:
View
75 dev-resources/hooke-1.1.1.pom
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>robert</groupId>
+ <artifactId>hooke</artifactId>
+ <packaging>jar</packaging>
+ <version>1.2.0</version>
+ <name>hooke</name>
+ <licenses>
+ <license>
+ <name>Eclipse Public License</name>
+ <url>http://www.eclipse.org/legal/epl-v10.html</url>
+ </license>
+ </licenses>
+ <scm>
+ <connection>scm:git:git://github.com/technomancy/robert-hooke.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/technomancy/robert-hooke.git</developerConnection>
+ <tag>e0d11489a2421592a545847d352f168a939eafeb</tag>
+ <url>https://github.com/technomancy/robert-hooke</url>
+ </scm>
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <testSourceDirectory>test</testSourceDirectory>
+ <resources>
+ <resource>
+ <directory>resources</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>dev-resources</directory>
+ </testResource>
+ <testResource>
+ <directory>resources</directory>
+ </testResource>
+ </testResources>
+ <directory>target</directory>
+ <outputDirectory>target/classes</outputDirectory>
+ </build>
+ <repositories>
+ <repository>
+ <id>central</id>
+ <url>http://repo1.maven.org/maven2/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ <repository>
+ <id>clojars</id>
+ <url>https://clojars.org/repo/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.clojure</groupId>
+ <artifactId>clojure</artifactId>
+ <version>1.4.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
+
+<!-- This file was autogenerated by Leiningen.
+ Please do not edit it directly; instead edit project.clj and regenerate it.
+ It should not be considered canonical data. For more information see
+ https://github.com/technomancy/leiningen -->
View
11 dev-resources/hooke-1.1.2.jar.asc
@@ -0,0 +1,11 @@
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.10 (GNU/Linux)
+
+iQEbBAABAgAGBQJQdJMAAAoJEE0jHTttgAF4mv0H+I0Cut5EbKnvCZctY9KvJJqN
+07Q4f8gwq7kPx/DGtIyd9rXTSchg0j5R/rg19MSM8yXF+LoYbrmTsqkjkiSu4Sv8
+M3bbeIfxD0rBtu2jmb6zqQcbPX3/j+urdqZKRdqeLvK3sr1fjbqUfTzyG1+hvsJR
+uP3R8a74UKDiRLhaBn/HtH0Kl8t236TGWBbVdXO57YggdXw1CJm32jjU14PUB6mp
+Vee90bFhiNv03i07c+NETmOQiiR+AohP7Iom4lYzs6IaotdejXyuyNbKlIbpDSqu
+YS9Ez0OvB60zSseht2V0eqa+/PANDIUskUr1SRVKF6sfWSCGZsWCNAbGdJb53w==
+=+70a
+-----END PGP SIGNATURE-----
View
52 dev-resources/hooke-1.1.2.pom
@@ -1,15 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>robert</groupId>
<artifactId>hooke</artifactId>
- <version>1.1.2</version>
+ <packaging>jar</packaging>
+ <version>1.2.0</version>
<name>hooke</name>
<description>Hooke your functions!</description>
+ <url>https://github.com/technomancy/robert-hooke</url>
+ <licenses>
+ <license>
+ <name>Eclipse Public License</name>
+ <url>http://www.eclipse.org/legal/epl-v10.html</url>
+ </license>
+ </licenses>
<scm>
<connection>scm:git:git://github.com/technomancy/robert-hooke.git</connection>
<developerConnection>scm:git:ssh://git@github.com/technomancy/robert-hooke.git</developerConnection>
- <tag>19ce36f7a3b0704cdcde821ebf4b4721ec903efb</tag>
+ <tag>e0d11489a2421592a545847d352f168a939eafeb</tag>
<url>https://github.com/technomancy/robert-hooke</url>
</scm>
<build>
@@ -22,34 +30,48 @@
</resources>
<testResources>
<testResource>
- <directory>test-resources</directory>
+ <directory>dev-resources</directory>
+ </testResource>
+ <testResource>
+ <directory>resources</directory>
</testResource>
</testResources>
+ <directory>target</directory>
+ <outputDirectory>target/classes</outputDirectory>
</build>
<repositories>
<repository>
<id>central</id>
- <url>http://repo1.maven.org/maven2</url>
- </repository>
- <repository>
- <id>clojure</id>
- <url>http://build.clojure.org/releases</url>
- </repository>
- <repository>
- <id>clojure-snapshots</id>
- <url>http://build.clojure.org/snapshots</url>
+ <url>http://repo1.maven.org/maven2/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
</repository>
<repository>
<id>clojars</id>
- <url>http://clojars.org/repo/</url>
+ <url>https://clojars.org/repo/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
- <version>1.3.0-beta1</version>
+ <version>1.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
+
+<!-- This file was autogenerated by Leiningen.
+ Please do not edit it directly; instead edit project.clj and regenerate it.
+ It should not be considered canonical data. For more information see
+ https://github.com/technomancy/leiningen -->
View
11 dev-resources/hooke-1.1.2.pom.asc
@@ -0,0 +1,11 @@
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.10 (GNU/Linux)
+
+iQEcBAABAgAGBQJQdJL4AAoJEE0jHTttgAF4neIH/3P2E6PcNXMJUZWVrIC+YK1b
+FdnuUqL+a8mLYOT1gJkYdnIMM+GhgfWTi6MNTOtaO7ctE1i6rPk2ulW3wCybjN4G
+UwosW1uGthnOjlMcfaOB5hzq71emwgMslmyUn3OhN5qddw4StPuBL166Hj0ebd5M
+QdKFmWLekRJDXzKZ9+cv/MJ19MI3NTrQ1q8dCmfwOJp28WnwQvhg/RMiTRr/q5wE
+RYov2zs57bbEPVH9MvYPJW3EjgxAMdxpDg+7pyrFALdiZum/o8O6BluMTrOz8gEj
+ruD3Z2avIhRVMJGISA2vK9ffdv6NSjgUNRktbi2+n4t31oJJ8xWlDg07zLUscbQ=
+=zHFU
+-----END PGP SIGNATURE-----
View
3 project.clj
@@ -32,9 +32,8 @@
:plugins [[lein-ring "0.7.3" :exclusions [thneed]]
;fix downloading -snapshot all the time
[thneed "1.0.0"]]
+ :aliases {"migrate" ["run" "-m" "clojars.db.migrate"]}
:ring {:handler clojars.web/clojars-app}
:aot [clojars.scp]
:main clojars.main
:min-lein-version "2.0.0")
-
-
View
5 src/clojars/auth.clj
@@ -16,8 +16,9 @@
{:username user :password password})))
(defn authorized? [account group]
- (let [names# (group-membernames group)]
- (or (some #{account} names#) (empty? names#))))
+ (if account
+ (let [names (group-membernames group)]
+ (or (some #{account} names) (empty? names)))))
(defmacro require-authorization [group & body]
`(if (authorized? ~'account ~group)
View
19 src/clojars/db.clj
@@ -3,9 +3,9 @@
[clojure.java.io :as io]
[clojars.config :refer [config]]
[korma.db :refer [defdb transaction rollback]]
- [korma.core :refer [defentity select group fields order
- modifier exec-raw where limit values
- raw insert update set-fields offset]])
+ [korma.core :refer [defentity select group fields order join
+ modifier exec-raw where limit values with
+ has-many raw insert update set-fields offset]])
(:import java.security.MessageDigest
java.util.Date
java.io.File
@@ -74,6 +74,11 @@
(defn group-membernames [groupname]
(map :user (select groups (fields :user) (where {:name groupname}))))
+(defn group-keys [groupname]
+ (map :pgp_key (select users (fields :pgp_key)
+ (join groups (= :users.user :groups.user))
+ (where {:groups.name groupname}))))
+
(defn jars-by-username [username]
(select jars
(where {:user username})
@@ -176,12 +181,13 @@
(* (- current-page 1) per-page)
per-page))))
-(defn add-user [email username password ssh-key]
+(defn add-user [email username password ssh-key pgp-key]
(insert users
(values {:email email
:user username
:password (bcrypt password)
:ssh_key ssh-key
+ :pgp_key pgp-key
:created (get-time)
;;TODO: remove salt field
:salt ""}))
@@ -190,11 +196,12 @@
:user username}))
(write-key-file (:key-file config)))
-(defn update-user [account email username password ssh-key]
+(defn update-user [account email username password ssh-key pgp-key]
(let [fields {:email email
:user username
:salt ""
- :ssh_key ssh-key}]
+ :ssh_key ssh-key
+ :pgp_key pgp-key}]
(update users
(set-fields (if (empty? password)
fields
View
6 src/clojars/db/migrate.clj
@@ -19,6 +19,9 @@
(sql/do-commands (str "CREATE INDEX IF NOT EXISTS jars_idx0 "
"ON jars (group_name, jar_name, created DESC)")))
+(defn add-pgp-key []
+ (sql/do-commands "ALTER TABLE users ADD COLUMN pgp_key TEXT"))
+
;; migrations mechanics
(defn run-and-record [migration]
@@ -50,4 +53,5 @@
(defn -main []
(migrate #'initial-schema
#'add-promoted-field
- #'add-jars-index))
+ #'add-jars-index
+ #'add-pgp-key))
View
7 src/clojars/friend/registration.clj
@@ -6,14 +6,15 @@
[clojars.db :refer [add-user]]
[valip.core :refer [validate]]))
-(defn register [{:keys [email username password confirm ssh-key]}]
+(defn register [{:keys [email username password confirm ssh-key pgp-key]}]
(if-let [errors (apply validate {:email email
:username username
:password password
- :ssh-key ssh-key}
+ :ssh-key ssh-key
+ :pgp-key pgp-key}
(new-user-validations confirm))]
(response (register-form (apply concat (vals errors)) email username ssh-key))
- (do (add-user email username password ssh-key)
+ (do (add-user email username password ssh-key pgp-key)
(workflow/make-auth {:identity username :username username}))))
(defn workflow [{:keys [uri request-method params]}]
View
106 src/clojars/promote.clj
@@ -1,14 +1,17 @@
(ns clojars.promote
(:require [clojars.config :refer [config]]
[clojars.maven :as maven]
+ [clojars.db :as db]
[clojure.java.io :as io]
[clojure.java.shell :as sh]
- [cemerick.pomegranate.aether :as aether]
- [clojars.db :as db]
[clojure.java.jdbc :as sql]
+ [clojure.string :as str]
+ [korma.db :as korma]
+ [cemerick.pomegranate.aether :as aether]
[korma.core :refer [select fields where update set-fields]])
(:import (java.util.concurrent LinkedBlockingQueue)
- (org.springframework.aws.maven SimpleStorageServiceWagon)))
+ (org.springframework.aws.maven SimpleStorageServiceWagon)
+ (java.io File ByteArrayInputStream PrintWriter)))
(defn file-for [group artifact version extension]
(let [filename (format "%s-%s.%s" artifact version extension)]
@@ -24,32 +27,28 @@
(conj blockers "Snapshot versions cannot be promoted")
blockers))
-(defn check-field [blockers info field]
- (if (field info)
+(defn check-field [blockers info field pred]
+ (if (pred (field info))
blockers
(conj blockers (str "Missing " (name field)))))
-(declare check-signature)
-
-(defn- fetch-key [signature err]
- (if (re-find #"Can't check signature: public key not found" err)
- (let [key (second (re-find #"using \w+ key ID (.+)" err))
- {:keys [exit]} (sh/sh "gpg" "--recv-keys" key)]
- (if (zero? exit)
- (check-signature signature)))))
-
-(defn- check-signature [signature]
- (let [err (java.io.StringWriter.)
- out (java.io.StringWriter.)
- {:keys [exit]} (binding [*err* (java.io.PrintWriter. err), *out* out]
- (sh/sh "gpg" "--verify" (str signature)))]
- (or (zero? exit)
- (fetch-key signature (str err)))))
-
-(defn signed? [blockers file]
- (if (check-signature (str file ".asc"))
- blockers
- (conj blockers (str file " is not signed."))))
+;; if you think this looks crazy, you should see what it looked like
+;; with bouncy castle.
+(defn signed-with? [file sig-file keys]
+ (let [temp-home (str (doto (File/createTempFile "clojars" "gpg")
+ .delete .mkdirs (.setReadable true true)))]
+ (sh/sh "gpg" "--homedir" temp-home "--import" :in (str/join "\n" keys))
+ (let [{:keys [exit out err]} (sh/sh "gpg" "--homedir" temp-home
+ "--verify" (str sig-file) (str file))]
+ (doseq [f (reverse (file-seq (io/file temp-home)))] (.delete f))
+ (or (zero? exit) (println "GPG error:" out "\n" err)))))
+
+(defn signed? [blockers file keys]
+ (let [sig-file (str file ".asc")]
+ (if (and (.exists (io/file sig-file))
+ (signed-with? file sig-file keys))
+ blockers
+ (conj blockers (str file " is not signed.")))))
(defn unpromoted? [blockers {:keys [group name version]}]
(let [[{:keys [promoted_at]}] (select db/jars (fields :promoted_at)
@@ -63,25 +62,25 @@
(defn blockers [{:keys [group name version]}]
(let [jar (file-for group name version "jar")
pom (file-for group name version "pom")
+ keys (db/group-keys group)
info (try (maven/pom-to-map pom)
- (catch Exception _ {}))]
- ;; TODO: convert this to a lazy seq for cheaper qualification checks
+ (catch Exception e
+ (.printStackTrace e) {}))]
(-> []
(check-version version)
(check-file jar)
(check-file pom)
- ;; TODO: check contents, not just presence
- (check-field info :description)
- (check-field info :url)
- (check-field info :licenses)
- (check-field info :scm)
+ (check-field info :description (complement empty?))
+ (check-field info :url #(re-find #"^http" (str %)))
+ (check-field info :licenses seq)
+ (check-field info :scm identity)
- (signed? jar)
- (signed? pom)
+ (signed? jar keys)
+ (signed? pom keys)
(unpromoted? info))))
-(def releases {:url "s3://clojars/releases/"
+(def releases {:url (config :releases-url)
:username (config :releases-access-key)
:passphrase (config :releases-secret-key)})
@@ -102,27 +101,26 @@
:repository {"releases" releases})))
(defn promote [{:keys [group name version] :as info}]
- (sql/with-connection (config :db)
- (sql/transaction
- (let [blockers (blockers info)]
- (if (empty? blockers)
- (do
- (println "Promoting" info)
- (update db/jars
- (set-fields {:promoted_at (java.util.Date.)})
- (where {:group_name group :jar_name name :version version}))
- (deploy-to-s3 info))
- blockers)))))
+ (korma/transaction
+ (println "checking" group "/" name "for promotion...")
+ (let [blockers (blockers info)]
+ (if (empty? blockers)
+ (when (config :releases-secret-key)
+ (println "Promoting" info)
+ (deploy-to-s3 info)
+ ;; TODO: this doesn't seem to be happening. db locked?
+ (update db/jars
+ (set-fields {:promoted_at (java.util.Date.)})
+ (where {:group_name group :jar_name name :version version})))
+ (do (println "...failed.")
+ blockers)))))
(defonce queue (LinkedBlockingQueue.))
(defn start []
(.start (Thread. #(loop []
- (try (promote (.take queue))
- (catch Exception e
- (.printStackTrace e)))
+ (locking #'promote
+ (try (promote (.take queue))
+ (catch Exception e
+ (.printStackTrace e))))
(recur)))))
-
-;; TODO: probably worth periodically queueing all non-promoted
-;; releases into here to catch things that fall through the cracks,
-;; say if the JVM is restarted before emptying this queue.
View
16 src/clojars/web/jar.clj
@@ -5,7 +5,9 @@
[hiccup.core :refer [h]]
[hiccup.element :refer [link-to]]
[clojars.maven :refer [jar-to-pom-map commit-url]]
+ [clojars.auth :refer [authorized?]]
[clojars.db :refer [find-jar jar-exists]]
+ [clojars.promote :refer [blockers]]
[ring.util.codec :refer [url-encode]]))
(defn url-for [jar]
@@ -34,6 +36,19 @@
(try (link-to url text)
(catch Exception e text)))
+(defn promotion-details [account jar]
+ (if (authorized? account (:group_name jar))
+ (list [:h3 "promotion"]
+ (if (:promoted_at jar)
+ [:p (str "Promoted at " (java.util.Date. (:promoted_at jar)))]
+ (if-let [issues (seq (blockers (clojure.set/rename-keys
+ jar {:group_name :group
+ :jar_name :name})))]
+ [:ul#blockers
+ (for [i issues]
+ [:li i])]
+ [:p "No blockers; redeploy to promote."])))))
+
(defn show-jar [account jar recent-versions count]
(html-doc account (str (:jar_name jar) " " (:version jar))
[:h1 (jar-link jar)]
@@ -63,6 +78,7 @@
[:span {:title (str (java.util.Date. (:created jar)))} (simple-date (:created jar))]
(if-let [url (commit-url pom)]
[:span.commit-url " with " (link-to url "this commit")])]
+ (promotion-details account jar)
(dependency-section "dependencies" "dependencies"
(remove #(not= (:scope %) "compile") (:dependencies pom)))
(when-not pom
View
35 src/clojars/web/user.clj
@@ -18,7 +18,7 @@
[valip.predicates :as pred])
(:import [org.apache.commons.mail SimpleEmail]))
-(defn register-form [ & [errors email username ssh-key]]
+(defn register-form [ & [errors email username ssh-key pgp-key]]
(html-doc nil "Register"
[:h1 "Register"]
(error-list errors)
@@ -36,15 +36,21 @@
" (" (link-to
"http://wiki.github.com/ato/clojars-web/ssh-keys"
"what's this?") ")"
- (text-area :ssh-key ssh-key)
- [:p.hint "Entering multiple keys? Put them on separate lines."]
- (submit-button "Register"))))
+ (text-area :ssh-key ssh-key)
+ [:p.hint "Entering multiple SSH keys? Put them on separate lines."]
+ (label :pgp-key "PGP public key:")
+ (text-area :pgp-key pgp-key)
+ (submit-button "Register"))))
(defn conj-when [coll test x]
(if test
(conj coll x)
coll))
+(defn valid-pgp-key? [key]
+ (and (.startsWith key "-----BEGIN PGP PUBLIC KEY BLOCK-----")
+ (.endsWith key "-----END PGP PUBLIC KEY BLOCK-----")))
+
(defn valid-ssh-key? [key]
(every? #(re-matches #"(ssh-\w+ \S+|\d+ \d+ \D+).*\s*" %) (split-keys key)))
@@ -55,9 +61,10 @@
"letters, numbers, hyphens and underscores.")]
[:username pred/present? "Username can't be blank"]
[:password #(= % confirm) "Password and confirm password must match"]
- [:ssh-key #(or (blank? %)
- (valid-ssh-key? %))
- "Invalid SSH public key"]])
+ [:ssh-key #(or (blank? %) (valid-ssh-key? %))
+ "Invalid SSH public key"]
+ [:pgp-key #(or (blank? %) (valid-pgp-key? %))
+ "Invalid PGP public key"]])
(defn new-user-validations [confirm]
(concat [[:password pred/present? "Password can't be blank"]
@@ -82,17 +89,20 @@
(password-field :confirm)
(label :ssh-key "SSH public key:")
(text-area :ssh-key (user :ssh_key))
- [:p.hint "Entering multiple keys? Put them on separate lines."]
+ [:p.hint "Entering multiple SSH keys? Put them on separate lines."]
+ (label :pgp-key "PGP public key:")
+ (text-area :pgp-key (user :pgp_key))
(submit-button "Update")))))
-(defn update-profile [account {:keys [email password confirm ssh-key]}]
+(defn update-profile [account {:keys [email password confirm ssh-key pgp-key]}]
(if-let [errors (apply validate {:email email
:username account
:password password
- :ssh-key ssh-key}
+ :ssh-key ssh-key
+ :pgp-key pgp-key}
(update-user-validations confirm))]
(profile-form account (apply concat (vals errors)))
- (do (update-user account email account password ssh-key)
+ (do (update-user account email account password ssh-key pgp-key)
(redirect "/profile"))))
(defn show-user [account user]
@@ -133,7 +143,8 @@
(defn forgot-password [{:keys [email-or-username]}]
(when-let [user (find-user-by-user-or-email email-or-username)]
(let [new-password (rand-string 15)]
- (update-user (user :user) (user :email) (user :user) new-password (user :ssh_key))
+ (update-user (user :user) (user :email) (user :user) new-password
+ (user :ssh_key) (user :pgp_key))
(send-mail (user :email)
"Password reset for Clojars"
(str "Hello,\n\nYour new password for Clojars is: " new-password "\n\nKeep it safe this time."))))
View
31 test-resources/pubring.gpg
@@ -0,0 +1,31 @@
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Version: GnuPG v1.4.10 (GNU/Linux)
+
+mQENBFBEo6YBCACv0iWDO5fdM0i5XRcxJ8yZecKPKDyJ8wsnHq1oI2/ZM5sCilMA
+eiZ4gAQbLG2xkwR/A/Cdu2OWl44m2P4tPkV7Pg75MnjYFYsMCZf8OvRugXpNYmNK
+OLKY4ydsJDKSo+nEAmR1ePuxj/IdJUjlUA77hgREZJb/BaqKEJ9JuH1kLg967p1/
+4fjQ4+LapuB3cKQdObqxDlMxTHKO0lOwpabHJBpZL+q9bAhjcT/Ij9clU3aIG+w+
+PWvov+3wjKLA7WLoHCCQEkdnuulvoIfTZN6rvhWbUEoTJJPVcexxAbwIEgtRTxm6
+50H6lWX58i2+W8GLL+4f0OuMMnRe7WKVMoFJABEBAAG0F0FsaWNlIDxhbGljZUBh
+bGljZS5jb20+iQE4BBMBAgAiBQJQRKOmAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIe
+AQIXgAAKCRBNIx07bYABeG1ZCACcAWeaoxZp3dvBaXBOHEL77eFDBafarZHJPKaM
+1RAhMnBXI4FxfgXWyUm+Hdr0wcZevyPQaHnUV/HN2ne24fJJUFxoCsKR0FEKj3g5
+n8T0IDK6b8FsL/o04fc7OFABvCX8LSF5t9NM4+pTzxwz0kJv25tqzy9wqMxb2kUH
+BpxKsDw5jKhvnjictgDajzKbjgvqwXJL6XiyRSsWQGUnzz17yyrzlpxIOAX3jQkv
+9uG5bkvSm1SIAMz0Sc4bu+nJmr/S47TTbLhoqIkLP7+xmopfJR+fLYlE04br/yoF
+10ZkrboZ9NpW5U/ku7xbAoySLJuI7b3Bx2eGwnq3Fl/AxgJ2uQENBFBEo6YBCADU
+iIXu+Y18Zia6wAFk1+o3cbLgbh4YF6AnYCwIadxFYEKtPhiHhvrzyM2I4CPRp8ib
+VAuHkZ1+M6Z1sKcEJ8nEMAZhW3COBevQVmgnVWprf+IUZMHMVF1zzefYqJyR0dg/
+faq4jpr3dg4Tl1QzpKMfu5FibQYEZJ/WixBMf60AybvtohPENSdgQorlrXryNy3H
+BuXPeFiAUiLB1lXf+Y95bIASZeIb0jyId2z0m4fgvTsL+0eEerla8BcIQL7Dcurm
+9zNuzRuqzP7l564+thyhmmmoPg8uv17nOXriOFkdg6VtBCrS/iSC1BZ7liCiWUMJ
+1YWWDPSvBIhdffddUWn/ABEBAAGJAR8EGAECAAkFAlBEo6YCGwwACgkQTSMdO22A
+AXgiIAf/VdceyGR7uFHp1T/IJpnK5uxX1sD2vzUdaSHl7OAxrS5QZy4Dh8Femope
++wsCd60n/vNngxAxnPn0cF444It1cKY7fEMzclkVolm5qqzMOsIgfuyAKTz7C7Uw
+pPLHghqqlKWr5rfCBHqEPs28XBsY256j0UXp5WqdxXBFlJTr3yv5ctppsYQjmQjo
+V3djzajC8SDdZJpuywYP27V5TqjoiZ1Bama0O1GuokKLHdN0/BqaXnM/dCoZNUQi
+JZ0XONv7klUFq+JGYsLsoQdRrftG2x5+aCQPuM0K07RG8BwLTkEBpwZsGCR0ZW2s
+JoCpAvvMaeSzQYGG0M3jhDhiAbcpFQ==
+=tell
+-----END PGP PUBLIC KEY BLOCK-----
+
View
4 test/clojars/test/test_helper.clj
@@ -38,10 +38,10 @@
(force migrate)
(let [file (File. (:repo config/config))]
(delete-file-recursively file))
- (f)
(jdbc/with-connection (kdb/get-connection @kdb/_default)
(jdbc/do-commands
"delete from users;"
"delete from jars;"
"delete from deps;"
- "delete from groups;")))))
+ "delete from groups;"))
+ (f))))
View
22 test/clojars/test/unit/db.clj
@@ -14,8 +14,9 @@
name "testuser"
password "password"
ssh-key "asdf"
+ pgp-key "aoeu"
ms (long 0)]
- (is (db/add-user email name password ssh-key))
+ (is (db/add-user email name password ssh-key pgp-key))
(are [x] (submap {:email email
:user name
:ssh_key ssh-key}
@@ -32,20 +33,23 @@
name "testuser"
password "password"
ssh-key "asdf"
+ pgp-key "aoeu"
ms (long 0)
email2 "test2@example.com"
name2 "testuser2"
password2 "password2"
- ssh-key2 "asdf2"]
+ ssh-key2 "asdf2"
+ pgp-key2 "aoeu2"]
(binding [db/get-time (fn [] (java.sql.Timestamp. ms))]
;;TODO: What should be done about the key-file?
- (is (db/add-user email name password ssh-key))
+ (is (db/add-user email name password ssh-key pgp-key))
(binding [db/get-time (fn [] (java.sql.Timestamp. (long 1)))]
;;TODO: What should be done about the key-file?
- (is (db/update-user name email2 name2 password2 ssh-key2))
+ (is (db/update-user name email2 name2 password2 ssh-key2 pgp-key2))
(are [x] (submap {:email email2
:user name2
:ssh_key ssh-key2
+ :pgp_key pgp-key2
:created ms}
x)
(db/find-user name2)
@@ -57,9 +61,10 @@
(let [email "test@example.com"
name "testuser"
password "password"
- ssh-key "asdf"]
+ ssh-key "asdf"
+ pgp-key "aoeu"]
;;TODO: What should be done about the key-file?
- (is (db/add-user email name password ssh-key))
+ (is (db/add-user email name password ssh-key pgp-key))
(is (= ["testuser"]
(db/group-membernames (str "org.clojars." name))))
(is (= ["org.clojars.testuser"]
@@ -69,9 +74,10 @@
(let [email "test@example.com"
name "testuser"
password "password"
- ssh-key "asdf"]
+ ssh-key "asdf"
+ pgp-key "aoeu"]
;;TODO: What should be done about the key-file?
- (is (db/add-user email name password ssh-key))
+ (is (db/add-user email name password ssh-key pgp-key))
(is (db/add-member "test-group" name))
(is (= ["testuser"]
(db/group-membernames "test-group")))
View
60 test/clojars/test/unit/promote.clj
@@ -2,21 +2,59 @@
(:require [clojure.test :refer :all]
[clojars.promote :refer :all]
[clojure.java.io :as io]
- [clojars.maven :as maven]))
+ [clojars.maven :as maven]
+ [clojars.db :as db]
+ [clojars.test.test-helper :as help]))
-;; TODO: need to seed the test repo for these tests now
+(help/use-fixtures)
-#_(deftest test-snapshot-blockers
+(defn copy-resource [version & [extension]]
+ (let [extension (or extension "pom")]
+ (.mkdirs (.getParentFile (file-for "robert" "hooke" version "")))
+ (io/copy (io/reader (io/resource (str "hooke-" version "." extension)))
+ (file-for "robert" "hooke" version extension))))
+
+(deftest test-snapshot-blockers
(is (= ["Snapshot versions cannot be promoted"
"Missing file hooke-1.2.0-SNAPSHOT.jar"
"Missing file hooke-1.2.0-SNAPSHOT.pom"]
- (blockers {:group "robert" :name "hooke" :version "1.2.0-SNAPSHOT"}))))
+ (take 3 (blockers {:group "robert" :name "hooke"
+ :version "1.2.0-SNAPSHOT"})))))
+
+(deftest test-metadata-blockers
+ (copy-resource "1.1.1")
+ (is (clojure.set/subset? #{"Missing url" "Missing description"}
+ (set (blockers {:group "robert" :name "hooke"
+ :version "1.1.1"})))))
+
+(deftest test-unsigned
+ (copy-resource "1.1.2")
+ ;; TODO: requires test profile; breaks in repl
+ (is (= #{"data/test_repo/robert/hooke/1.1.2/hooke-1.1.2.pom is not signed."
+ "data/test_repo/robert/hooke/1.1.2/hooke-1.1.2.jar is not signed."
+ "Missing file hooke-1.1.2.jar"}
+ (set (blockers {:group "robert" :name "hooke"
+ :version "1.1.2"})))))
+
+(deftest test-success
+ (copy-resource "1.1.2")
+ (io/copy "dummy hooke jar file"
+ (file-for "robert" "hooke" "1.1.2" "jar"))
+ (copy-resource "1.1.2" "jar.asc")
+ (copy-resource "1.1.2" "pom.asc")
+ (db/add-user "test@ex.com" "testuser" "password" "asdf"
+ (slurp "test-resources/pubring.gpg"))
+ (db/add-member "robert" "testuser")
+ (is (empty? (blockers {:group "robert" :name "hooke" :version "1.1.2"}))))
-#_(deftest test-metadata-blockers
- (.mkdirs (.getParentFile (file-for "robert" "hooke" "1.1.2" "pom")))
- (io/copy (.getPath (io/resource "hooke-1.1.2.pom"))
- (file-for "robert" "hooke" "1.1.2" "pom"))
- (spit (file-for "robert" "hooke" "1.1.2" "pom") "")
- (spit (file-for "robert" "hooke" "1.1.2" "jar") "")
- (is (= ["Missing url"]
+(deftest test-failed-signature
+ (copy-resource "1.1.2")
+ (io/copy "dummy hooke jar file corrupted"
+ (file-for "robert" "hooke" "1.1.2" "jar"))
+ (copy-resource "1.1.2" "jar.asc")
+ (copy-resource "1.1.2" "pom.asc")
+ (db/add-user "test@ex.com" "testuser" "password" "asdf"
+ (slurp "test-resources/pubring.gpg"))
+ (db/add-member "robert" "testuser")
+ (is (= ["data/test_repo/robert/hooke/1.1.2/hooke-1.1.2.jar is not signed."]
(blockers {:group "robert" :name "hooke" :version "1.1.2"}))))

0 comments on commit 1dc2cc2

Please sign in to comment.
Something went wrong with that request. Please try again.