Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions src/main/com/yetanalytics/lrs/pedestal/routes/documents.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,18 @@
lrs
ctx
auth-identity params))]
(if (and (or
;; In 2.0, no headers ok for no doc
(= "2.0.0"
(:com.yetanalytics.lrs/version ctx))
;; prior tests seem to want this for everything but
;; profiles
(not (#{:xapi.activities.profile.PUT.request/params
:xapi.agents.profile.PUT.request/params}
params-type)))
(not (:error doc-res))
(nil? (:document doc-res)))
(if (and (not (:error doc-res))
(or
;; State resources are exempt from concurrency
;; header requirements in all xAPI versions
(= :xapi.activities.state.PUT.request/params
params-type)
(and (nil? (:document doc-res))
(or (= "2.0.0"
(:com.yetanalytics.lrs/version ctx))
(not (#{:xapi.activities.profile.PUT.request/params
:xapi.agents.profile.PUT.request/params}
params-type))))))
(put-response ctx
(a/<! (lrs/set-document-async
lrs
Expand Down Expand Up @@ -344,17 +345,18 @@
lrs
ctx
auth-identity params)]
(if (and (or
;; In 2.0, no headers ok for no doc
(= "2.0.0"
(:com.yetanalytics.lrs/version ctx))
;; prior tests seem to want this for everything but
;; profiles
(not (#{:xapi.activities.profile.PUT.request/params
:xapi.agents.profile.PUT.request/params}
params-type)))
(not (:error doc-res))
(nil? (:document doc-res)))
(if (and (not (:error doc-res))
(or
;; State resources are exempt from concurrency
;; header requirements in all xAPI versions
(= :xapi.activities.state.PUT.request/params
params-type)
(and (nil? (:document doc-res))
(or (= "2.0.0"
(:com.yetanalytics.lrs/version ctx))
(not (#{:xapi.activities.profile.PUT.request/params
:xapi.agents.profile.PUT.request/params}
params-type))))))
(put-response ctx
(lrs/set-document
lrs
Expand Down
40 changes: 40 additions & 0 deletions src/test/com/yetanalytics/lrs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,43 @@
"2.0.0" 200)
(finally
(http/stop lrs))))))

(def agent-json
"{\"objectType\":\"Agent\",\"account\":{\"homePage\":\"http://www.example.com/agentId/1\",\"name\":\"Rick James\"}}")

(defn- put-document
"PUT a document to the given url with query-params, version header, and body."
[url query-params version body]
(curl/put
url
{:basic-auth ["username" "password"]
:headers {"X-Experience-API-Version" version
"Content-Type" "application/octet-stream"}
:query-params query-params
:body body
:throw false}))

(deftest document-concurrency-test
(testing "Document PUT concurrency without If-Match/If-None-Match headers"
(let [server (support/test-server :port 8081)]
(try
(http/start server)
;; https://github.com/adlnet/xAPI-Spec/blob/1.0.3/xAPI-Communication.md?plain=1#L1424
;; State resources: xAPI 1.0.3 and 2.0 exempt state from concurrency
;; header requirements, so PUTs without headers should always go through.
(testing "xAPI 2.0.0 - state: PUTs without concurrency headers go through"
(let [params {"activityId" "http://www.example.com/activity/1"
"agent" agent-json
"stateId" "concurrency-test-200-state"}
url "http://localhost:8081/xapi/activities/state"]
(is (= 204 (:status (put-document url params "2.0.0" "first"))))
(is (= 204 (:status (put-document url params "2.0.0" "second"))))))
(testing "xAPI 1.0.3 - state: PUTs without concurrency headers go through"
(let [params {"activityId" "http://www.example.com/activity/2"
"agent" agent-json
"stateId" "concurrency-test-103-state"}
url "http://localhost:8081/xapi/activities/state"]
(is (= 204 (:status (put-document url params "1.0.3" "first"))))
(is (= 204 (:status (put-document url params "1.0.3" "second"))))))
(finally
(http/stop server))))))