Skip to content

Commit

Permalink
raise error on expired token
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 10, 2021
1 parent 136666a commit b42d0fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def collect_data(options = {})
# missing data raise errors
# return OpenStruct.new(body: { "errors" => [{ "title" => "Missing data" }] }) if work.data.nil?

# orcid_token has expired
return OpenStruct.new(body: { "errors" => [{ "status" => 401, "title" => "token has expired." }] }) if user.orcid_expires_at < Date.today

# validate data
return OpenStruct.new(body: { "errors" => work.validation_errors.map { |error| { "title" => error } } }) if work.validation_errors.present?

Expand Down
7 changes: 7 additions & 0 deletions spec/models/claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
expect(response.body).to eq("reason" => "No user and/or ORCID token", "skip" => true)
end

it "expired token" do
user = FactoryBot.create(:valid_user, orcid_expires_at: Time.zone.now - 7.days)
subject = FactoryBot.create(:claim, user: user, orcid: "0000-0001-6528-2027", doi: "10.14454/v6e2-yc93", source_id: "orcid_update")
response = subject.collect_data
expect(response.body).to eq("errors"=>[{"status"=>401, "title"=>"token has expired."}])
end

# TODO
# it "invalid token" do
# user = FactoryBot.create(:invalid_user, orcid_token: "123")
Expand Down

0 comments on commit b42d0fe

Please sign in to comment.