mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Add user role checks, see #14
Squashed commit of the following:
commit 393c481a21fa97881be2b6859e9acaa8ab7abb7f
Author: Arne Schlüter <arne@schlueter.is>
Date: Wed Sep 5 12:04:56 2018 +0200
Consider user roles when building up the navigation
commit d631cba1174ecf42b682664bf57c41b88b7f5ed4
Author: Arne Schlüter <arne@schlueter.is>
Date: Wed Sep 5 11:52:05 2018 +0200
Save user roles on login
commit e68ced335ccc11a2daebbf12bb4061a53935c268
Author: Arne Schlüter <arne@schlueter.is>
Date: Wed Sep 5 10:25:19 2018 +0200
Rename dispatch to muted-dispatch for easier disambiguation
This commit is contained in:
parent
3b58648b82
commit
5cbb83a22d
12 changed files with 180 additions and 53 deletions
|
|
@ -60,7 +60,7 @@
|
|||
(is (true? (api/is-error? (:auth-failure responses)))))
|
||||
(testing "Should pass on good responses"
|
||||
(is (false? (api/is-error? (:ok responses))))
|
||||
(is (false? (api/is-error? (:auth-success responses))))))
|
||||
(is (false? (api/is-error? (:ping-success responses))))))
|
||||
|
||||
(deftest content-type
|
||||
(testing "Should detect whether the data we look at represents a song"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
[airsonic-ui.db :as db]
|
||||
[airsonic-ui.routes :as routes]
|
||||
[airsonic-ui.events :as events]
|
||||
[airsonic-ui.subs :as subs]))
|
||||
[airsonic-ui.subs :as subs]
|
||||
))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
|
|
@ -53,10 +54,11 @@
|
|||
request (:http-xhrio fx)]
|
||||
(testing "uses correct server url"
|
||||
(let [uri (:uri request)]
|
||||
(is (true? (str/starts-with? uri (:server fixtures/credentials))))
|
||||
(is (true? (str/includes? uri "/ping")))
|
||||
(is (true? (str/includes? uri (str "p=" (:p fixtures/credentials)))))
|
||||
(is (true? (str/includes? uri (str "u=" (:u fixtures/credentials)))))))
|
||||
(is (str/starts-with? uri (:server fixtures/credentials)))
|
||||
(is (str/includes? uri "/getUser"))
|
||||
(is (str/includes? uri (str "p=" (:p fixtures/credentials))))
|
||||
(is (str/includes? uri (str "u=" (:u fixtures/credentials))))
|
||||
(is (str/includes? uri (str "username=" (:u fixtures/credentials))))))
|
||||
(testing "invokes correct callback on server response"
|
||||
(is (= [:credentials/authentication-response fixtures/credentials] (:on-success request))))
|
||||
(testing "invokes correct callback when server is not reachable"
|
||||
|
|
@ -66,9 +68,12 @@
|
|||
(testing "On success"
|
||||
(let [cofx (-> (has-previous-session)
|
||||
(events/authentication-response [:credentials/authentication-response (:auth-success fixtures/responses)])
|
||||
(events/authentication-success [:credentials/authentication-success]))]
|
||||
(events/authentication-success [:credentials/authentication-success fixtures/credentials (:auth-success fixtures/responses)]))]
|
||||
(testing "should mark the credentials as verified"
|
||||
(is (true? (get-in cofx [:db :credentials :verified?]))))))
|
||||
(is (true? (get-in cofx [:db :credentials :verified?]))))
|
||||
(testing "should store the credentials in localstorage"
|
||||
(let [stored-credentials (get-in cofx [:store :credentials])]
|
||||
(is (= fixtures/credentials stored-credentials))))))
|
||||
(testing "On failure"
|
||||
(let [cofx (-> (has-previous-session)
|
||||
(events/authentication-response [:credentials/authentication-response (:auth-failure fixtures/responses)])
|
||||
|
|
|
|||
|
|
@ -14,8 +14,29 @@
|
|||
:scanning false}
|
||||
:status "ok"
|
||||
:version "1.15.0"}}
|
||||
:auth-success {:subsonic-response {:status "ok"
|
||||
:ping-success {:subsonic-response {:status "ok"
|
||||
:version "1.15.0"}}
|
||||
:auth-success {:subsonic-response
|
||||
{:status "ok",
|
||||
:version "1.15.0",
|
||||
:user
|
||||
{:videoConversionRole false,
|
||||
:playlistRole true,
|
||||
:shareRole true,
|
||||
:podcastRole true,
|
||||
:email "admin@example.com",
|
||||
:streamRole true,
|
||||
:folder [0],
|
||||
:username "admin",
|
||||
:scrobblingEnabled false,
|
||||
:adminRole true,
|
||||
:settingsRole true,
|
||||
:commentRole true,
|
||||
:jukeboxRole true,
|
||||
:coverArtRole true,
|
||||
:downloadRole true,
|
||||
:maxBitRate 320,
|
||||
:uploadRole true}}}
|
||||
:auth-failure {:subsonic-response {:status "failed"
|
||||
:version "1.15.0"
|
||||
:error {:code 40
|
||||
|
|
|
|||
|
|
@ -21,3 +21,13 @@
|
|||
(testing "Should add classes to the innermost child of a nested hiccup element"
|
||||
(is (= :p>input.input (helpers/add-classes :p>input :input)))
|
||||
(is (= :div.field>p>input.input.has-background-red (helpers/add-classes :div.field>p>input.input :has-background-red)))))
|
||||
|
||||
(deftest kebabify
|
||||
(testing "Should turn camelCased and PascalCased strings into kebab-cased keywords"
|
||||
(is (= :hello-world (helpers/kebabify "HelloWorld")))
|
||||
(is (= :how-are-you (helpers/kebabify "howAreYou")))
|
||||
(is (= :foobar (helpers/kebabify "foobar"))))
|
||||
(testing "Should kebab-case camelCased and PascalCased keywords"
|
||||
(is (= :hello-world (helpers/kebabify :HelloWorld)))
|
||||
(is (= :how-are-you (helpers/kebabify :howAreYou)))
|
||||
(is (= :foobar (helpers/kebabify :foobar)))))
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
(:require [cljs.test :refer [deftest testing is]]
|
||||
[airsonic-ui.fixtures :as fixtures]
|
||||
[airsonic-ui.api.helpers :as api]
|
||||
[airsonic-ui.events :as events]
|
||||
[airsonic-ui.subs :as subs]))
|
||||
|
||||
(deftest booting
|
||||
|
|
@ -33,3 +34,34 @@
|
|||
fixtures/song
|
||||
48)
|
||||
(subs/cover-url [credentials] [:subs/cover-image fixtures/song 48]))))))
|
||||
|
||||
(def successful-auth-db
|
||||
"For the details see event_test.cljs"
|
||||
(-> {:store {:credentials fixtures/credentials}}
|
||||
(events/initialize-app [::events/initialize-app])
|
||||
(events/authentication-response [:credentials/authentication-response (:auth-success fixtures/responses)])
|
||||
(events/authentication-success [:credentials/authentication-success fixtures/credentials (:auth-success fixtures/responses)])
|
||||
(:db)))
|
||||
|
||||
(deftest user-roles
|
||||
(testing "Should be available after a successful authentication"
|
||||
(let [user-roles (-> (subs/user-info successful-auth-db [:user/info])
|
||||
(subs/user-roles [:user/roles]))]
|
||||
(is (set? user-roles))
|
||||
(is (every? keyword? user-roles))
|
||||
(is (not (user-roles :username)) "and contain only roles")))
|
||||
(testing "Should indicate whether a user has a given role"
|
||||
(letfn [(role [role]
|
||||
(-> (subs/user-info successful-auth-db [:user/info])
|
||||
(subs/user-roles [:user/roles])
|
||||
(disj :admin) ; <- makes sure we're not allowed everything
|
||||
(subs/user-role [:user/role role])))]
|
||||
(is (some? (role :stream)))
|
||||
(is (not (some? (role :video-conversion))))))
|
||||
(testing "Should allow everything to an admin"
|
||||
(letfn [(admin-role [role]
|
||||
(-> (subs/user-info successful-auth-db [:user/info])
|
||||
(subs/user-roles [:user/roles])
|
||||
(subs/user-role [:user/role role])))]
|
||||
(is (some? (admin-role :stream)))
|
||||
(is (some? (admin-role :video-conversion))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue