• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orcid_princeton_hanami / fc91ec04-17e3-41a9-ab4b-9c4c1cc2d9bb

25 Jul 2025 05:17PM UTC coverage: 96.539% (-3.5%) from 100.0%
fc91ec04-17e3-41a9-ab4b-9c4c1cc2d9bb

push

circleci

carolyncole
Orcid url for the sandbox

1 of 1 new or added line in 1 file covered. (100.0%)

19 existing lines in 4 files now uncovered.

530 of 549 relevant lines covered (96.54%)

8.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/app/repos/token_repo.rb
1
# frozen_string_literal: true
2

3
module OrcidPrinceton
1✔
4
  module Repos
1✔
5
    # class for setting timestamps on tokens and encrypting the token before inserting the data into the database
6
    class TokenRepo < OrcidPrinceton::DB::Repo
1✔
7
      def get(id)
1✔
8
        token = tokens.by_pk(id).one!
6✔
9
        decrypt_openssl_token(token)
6✔
10
      end
11

12
      def last = decrypt_openssl_token(tokens.last)
1✔
13

14
      def create(attributes)
1✔
15
        attributes[:created_at] = Time.now
1✔
16
        attributes[:updated_at] = Time.now
1✔
17
        tokens.changeset(:create, encrypt_openssl_token(attributes)).commit
1✔
18
      end
19

20
      def update(id, attributes)
1✔
21
        attributes[:updated_at] = Time.now
1✔
22
        tokens.by_pk(id).changeset(:update, encrypt_openssl_token(attributes)).commit
1✔
UNCOV
23
        get(id)
×
24
      end
25

26
      def expire_now(id)
1✔
27
        tokens.by_pk(id).changeset(:update, { expiration: Time.now }).commit
2✔
28
      end
29

30
      # Create a token from an omniauth hash.
31
      # @param credentials [OmniAuth::AuthHash] The credentials hash from the omniauth response.
32
      # @param user [User] The user to associate the token with.
33
      # @return [Token] The token that was created.
34
      def create_from_omniauth(credentials, user)
1✔
35
        create(
1✔
36
          token: credentials.token,
37
          expiration: Time.at(credentials.expires_at),
38
          user_id: user.id,
39
          token_type: 'ORC',
40
          orcid: user.orcid
41
          # TODO: ADD REFRESH TOKEN
42
          # refresh_token: credentials.refresh_token
43
        )
44
      end
45

46
      private
1✔
47

48
      def decrypt_openssl_token(token)
1✔
49
        if token.openssl_token
6✔
UNCOV
50
          token.attributes[:token] = OrcidPrinceton::Service::EncryptionHelper.new.decrypt(token.openssl_token)
×
51
        end
52
        token
6✔
53
      end
54

55
      def encrypt_openssl_token(attributes)
1✔
56
        if attributes.key?(:token)
2✔
57
          openssl_token = OrcidPrinceton::Service::EncryptionHelper.new.encrypt(attributes.delete(:token))
2✔
UNCOV
58
          attributes[:openssl_token] = openssl_token
×
UNCOV
59
          attributes[:token] = ''
×
60
        end
UNCOV
61
        attributes
×
62
      end
63
    end
64
  end
65
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc