diff --git a/src/raven_clj/core.clj b/src/raven_clj/core.clj index c5f14b2..2a4fac1 100644 --- a/src/raven_clj/core.clj +++ b/src/raven_clj/core.clj @@ -26,7 +26,7 @@ [ts key secret] (->> ["Sentry sentry_version=2.0" (format "sentry_client=%s" sentry-client) - (format "sentry_timestamp=%s" ts) + (format "sentry_timestamp=%d" ts) (format "sentry_key=%s" key) (when secret (format "sentry_secret=%s" secret))] @@ -68,7 +68,7 @@ {:level "error" :platform "clojure" :server_name (.getHostName (InetAddress/getLocalHost)) - :ts (str (Timestamp. (.getTime (Date.))))} + :ts (.getTime (Date.))} event-info {:event_id (generate-uuid)}))) diff --git a/test/raven_clj/core_test.clj b/test/raven_clj/core_test.clj index e43c7fd..2051b21 100644 --- a/test/raven_clj/core_test.clj +++ b/test/raven_clj/core_test.clj @@ -20,7 +20,7 @@ (deftest test-make-sentry-header (testing "sentry header" - (let [ts (str (Timestamp. (.getTime (Date.)))) + (let [ts (.getTime (Date.)) key "b70a31b3510c4cf793964a185cfe1fd0" secret "b7d80b520139450f903720eb7991bf3d" client-version (version) @@ -30,13 +30,30 @@ "includes sentry version") (is (.contains hdr (str "sentry_client=raven-clj/" client-version)) "includes client version") - (is (.contains hdr (format "sentry_timestamp=%s" ts)) + (is (.contains hdr (format "sentry_timestamp=%d" ts)) "includes timestamp") (is (.contains hdr (str "sentry_key=" key)) "includes key") (is (.contains hdr (str "sentry_secret=" secret)) "includes secret") - (is (= hdr (format "Sentry sentry_version=2.0, sentry_client=raven-clj/%s, sentry_timestamp=%s, sentry_key=%s, sentry_secret=%s" client-version ts key secret)))))) + (is (= hdr (format "Sentry sentry_version=2.0, sentry_client=raven-clj/%s, sentry_timestamp=%d, sentry_key=%s, sentry_secret=%s" client-version ts key secret))))) + + (testing "sentry header without secret" + (let [ts (.getTime (Date.)) + key "b70a31b3510c4cf793964a185cfe1fd0" + secret nil + client-version (version) + hdr (make-sentry-header ts key secret)] + + (is (.contains hdr "sentry_version=2.0") + "includes sentry version") + (is (.contains hdr (str "sentry_client=raven-clj/" client-version)) + "includes client version") + (is (.contains hdr (format "sentry_timestamp=%d" ts)) + "includes timestamp") + (is (.contains hdr (str "sentry_key=" key)) + "includes key") + (is (= hdr (format "Sentry sentry_version=2.0, sentry_client=raven-clj/%s, sentry_timestamp=%d, sentry_key=%s" client-version ts key)))))) (deftest test-send-packet (testing "send-packet" @@ -45,7 +62,7 @@ :secret "secret" :uri "uri" :project-id "project-id" - :ts "ts"}] + :ts 123456789}] (with-redefs [http/post (fn [url opts] (reset! actual-opts opts))] (send-packet packet) @@ -62,6 +79,13 @@ :uri "https://example.com" :project-id 1}))) + (testing "dsn parsing without secret" + (is (= (parse-dsn "https://b70a31b3510c4cf793964a185cfe1fd0@example.com/1") + {:key "b70a31b3510c4cf793964a185cfe1fd0" + :secret nil + :uri "https://example.com" + :project-id 1}))) + (testing "dsn parsing with path" (is (= (parse-dsn "https://b70a31b3510c4cf793964a185cfe1fd0:b7d80b520139450f903720eb7991bf3d@example.com/sentry/1") {:key "b70a31b3510c4cf793964a185cfe1fd0"