0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-01 01:21:21 -05:00

Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
Andrey Antukh 2021-05-25 23:25:27 +02:00
commit febaec1b1e
5 changed files with 43 additions and 41 deletions

View file

@ -84,7 +84,6 @@
:allow-demo-users true :allow-demo-users true
:registration-enabled true :registration-enabled true
:registration-domain-whitelist ""
:telemetry-enabled false :telemetry-enabled false
:telemetry-uri "https://telemetry.penpot.app/" :telemetry-uri "https://telemetry.penpot.app/"
@ -161,7 +160,7 @@
(s/def ::profile-complaint-threshold ::us/integer) (s/def ::profile-complaint-threshold ::us/integer)
(s/def ::public-uri ::us/string) (s/def ::public-uri ::us/string)
(s/def ::redis-uri ::us/string) (s/def ::redis-uri ::us/string)
(s/def ::registration-domain-whitelist ::us/string) (s/def ::registration-domain-whitelist ::us/set-of-str)
(s/def ::registration-enabled ::us/boolean) (s/def ::registration-enabled ::us/boolean)
(s/def ::rlimits-image ::us/integer) (s/def ::rlimits-image ::us/integer)
(s/def ::rlimits-password ::us/integer) (s/def ::rlimits-password ::us/integer)

View file

@ -60,9 +60,10 @@
(ex/raise :type :restriction (ex/raise :type :restriction
:code :registration-disabled)) :code :registration-disabled))
(when-not (email-domain-in-whitelist? (cfg/get :registration-domain-whitelist) (:email params)) (when-let [domains (cfg/get :registration-domain-whitelist)]
(ex/raise :type :validation (when-not (email-domain-in-whitelist? domains (:email params))
:code :email-domain-is-not-allowed)) (ex/raise :type :validation
:code :email-domain-is-not-allowed)))
(when-not (:terms-privacy params) (when-not (:terms-privacy params)
(ex/raise :type :validation (ex/raise :type :validation
@ -137,14 +138,15 @@
::audit/profile-id (:id profile)}))))) ::audit/profile-id (:id profile)})))))
(defn email-domain-in-whitelist? (defn email-domain-in-whitelist?
"Returns true if email's domain is in the given whitelist or if given "Returns true if email's domain is in the given whitelist or if
whitelist is an empty string." given whitelist is an empty string."
[whitelist email] [domains email]
(if (str/empty-or-nil? whitelist) (if (or (empty? domains)
(nil? domains))
true true
(let [domains (str/split whitelist #",\s*") (let [[_ candidate] (-> (str/lower email)
domain (second (str/split email #"@" 2))] (str/split #"@" 2))]
(contains? (set domains) domain)))) (contains? domains candidate))))
(def ^:private sql:profile-existence (def ^:private sql:profile-existence
"select exists (select * from profile "select exists (select * from profile

View file

@ -179,10 +179,10 @@
)) ))
(t/deftest registration-domain-whitelist (t/deftest registration-domain-whitelist
(let [whitelist "gmail.com, hey.com, ya.ru"] (let [whitelist #{"gmail.com" "hey.com" "ya.ru"}]
(t/testing "allowed email domain" (t/testing "allowed email domain"
(t/is (true? (profile/email-domain-in-whitelist? whitelist "username@ya.ru"))) (t/is (true? (profile/email-domain-in-whitelist? whitelist "username@ya.ru")))
(t/is (true? (profile/email-domain-in-whitelist? "" "username@somedomain.com")))) (t/is (true? (profile/email-domain-in-whitelist? #{} "username@somedomain.com"))))
(t/testing "not allowed email domain" (t/testing "not allowed email domain"
(t/is (false? (profile/email-domain-in-whitelist? whitelist "username@somedomain.com")))))) (t/is (false? (profile/email-domain-in-whitelist? whitelist "username@somedomain.com"))))))

View file

@ -137,29 +137,34 @@
;; --- SPEC: email ;; --- SPEC: email
(def email-re #"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+")
(let [re #"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+" (s/def ::email
cfn (fn [v] (s/conformer
(if (string? v) (fn [v]
(if-let [matches (re-seq re v)] (if (string? v)
(first matches) (if-let [matches (re-seq email-re v)]
(do ::s/invalid)) (first matches)
::s/invalid))] (do ::s/invalid))
(s/def ::email (s/conformer cfn str))) ::s/invalid))
str))
;; --- SPEC: set-of-str ;; --- SPEC: set-of-str
(letfn [(conformer [s]
(cond
(string? s) (into #{} (str/split s #"\s*,\s*"))
(set? s) (if (every? string? s)
s
::s/invalid)
:else ::s/invalid))
(unformer [s] (s/def ::set-of-str
(str/join "," s))] (s/conformer
(s/def ::set-of-str (s/conformer conformer unformer))) (fn [s]
(let [xform (comp
(filter string?)
(remove str/empty?)
(remove str/blank?))]
(cond
(string? s) (->> (str/split s #"\s*,\s*")
(into #{} xform))
(set? s) (into #{} xform s)
:else ::s/invalid)))
(fn [s]
(str/join "," s))))
;; --- Macros ;; --- Macros

View file

@ -12,17 +12,13 @@ goog.provide("app.common.uuid_impl");
goog.scope(function() { goog.scope(function() {
const core = cljs.core; const core = cljs.core;
const global = goog.global;
const self = app.common.uuid_impl; const self = app.common.uuid_impl;
const fill = (() => { const fill = (() => {
if (typeof window === "object" && typeof window.crypto !== "undefined") { if (typeof global.crypto !== "undefined") {
return (buf) => { return (buf) => {
window.crypto.getRandomValues(buf); global.crypto.getRandomValues(buf);
return buf;
};
} else if (typeof self === "object" && typeof self.crypto !== "undefined") {
return (buf) => {
self.crypto.getRandomValues(buf);
return buf; return buf;
}; };
} else if (typeof require === "function") { } else if (typeof require === "function") {
@ -34,7 +30,7 @@ goog.scope(function() {
}; };
} else { } else {
// FALLBACK // FALLBACK
console.warn("No high quality RNG available, switching back to Math.random."); console.warn("No SRNG available, switching back to Math.random.");
return (buf) => { return (buf) => {
for (let i = 0, r; i < buf.length; i++) { for (let i = 0, r; i < buf.length; i++) {