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

pulibrary / tigerdata-app / d7ce1bf9-25b8-4b3e-b9dd-43f9a26f2d96

17 Oct 2025 05:51PM UTC coverage: 91.054%. Remained the same
d7ce1bf9-25b8-4b3e-b9dd-43f9a26f2d96

Pull #2055

circleci

jrgriffiniii
- Ensuring that `parallelism` is set to 4
- Separating `system` RSpec spec suites in the CI build
- Using an `inconsistent` RSpec tag to mark inconsistently failing tests
- Ensuring that CI does not run for `inconsistent` tests
Pull Request #2055: Ensuring that `parallelism` is set to 4 for CircleCI and separates `system` and inconsistently-failing tests into separate CI jobs

2738 of 3007 relevant lines covered (91.05%)

380.37 hits per line

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

100.0
/app/services/princeton_users.rb
1
# frozen_string_literal: true
2
class PrincetonUsers
2✔
3
  CHARS_AND_NUMS =  ('a'..'z').to_a + (0..9).to_a + ['-']
2✔
4
  RDSS_DEVELOPERS = %w[bs3097 jrg5 cac9 hc8719 rl3667 kl37 pp9425 jh6441].freeze
2✔
5

6
  class << self
2✔
7

8

9
    # Returns a list of Users that match the given query
10
    def user_list_query(query)
2✔
11
      tokens = query.downcase.strip.split(/[^a-zA-Z\d]/).compact_blank
25✔
12
      return [] if tokens.count == 0
25✔
13

14
      user_query = tokens.inject(User.all) do |partial_query, token|
24✔
15
                     search_token = '%'+User.sanitize_sql_like(token)+'%'
37✔
16
                     partial_query.where("(LOWER(display_name) like ?) OR (LOWER(uid) like ?)", search_token, search_token)
37✔
17
                   end.order(:display_name)
18
      user_query.map{|user| { uid: user.uid, name: user.display_name, display_name: user.display_name_safe } }
49✔
19
    end
20

21
    def load_rdss_developers
2✔
22
      RDSS_DEVELOPERS.each do |netid|
2✔
23
        create_user_from_ldap_by_uid(netid)
9✔
24
        rescue TigerData::LdapError
25
        raise TigerData::LdapError, "Unable to create user from LDAP. Are you connected to VPN?"
1✔
26
      end
27
    end
28

29
    # Creates users from LDAP data, starting with the given uid prefix.
30
    def create_users_from_ldap(current_uid_start: "", ldap_connection: default_ldap_connection)
2✔
31
      CHARS_AND_NUMS.each do |char|
5✔
32
        filter =(~ Net::LDAP::Filter.eq( "pustatus", "guest" )) & Net::LDAP::Filter.eq("uid", "#{current_uid_start}#{char}*")
185✔
33
        people = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
185✔
34
        if ldap_connection.get_operation_result.message == "Success"
185✔
35
          people.each{|person| user_from_ldap(person)}
188✔
36
        else
37
          create_users_from_ldap(current_uid_start: "#{current_uid_start}#{char}", ldap_connection:)
1✔
38
        end
39
      end
40
    end
41

42
    def create_user_from_ldap_by_uid(uid, ldap_connection: default_ldap_connection)
2✔
43
      filter = Net::LDAP::Filter.eq('uid', uid)
8✔
44
      person = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
8✔
45
      raise TigerData::LdapError, "More than one user matches supplied uid: #{uid}" if person.length > 1
8✔
46
      raise TigerData::LdapError, "No user with uid #{uid} found" if person.empty?
8✔
47
      user_from_ldap(person.first)
8✔
48
    end
49

50
  # Creates or updates a User from an LDAP entry.
51
  # @param ldap_person [Net::LDAP::Entry] an LDAP entry representing a person
52
  # @return [User, nil] the created or updated User, or nil if the LDAP entry is missing a edupersonprincipalname
53
    def user_from_ldap(ldap_person)
2✔
54
      return if check_for_malformed_ldap_entries(ldap_person)
16✔
55
      uid = ldap_person[:uid].first.downcase
13✔
56
      current_entries = User.where(uid:)
13✔
57
      if current_entries.empty?
13✔
58
        User.create(uid: , display_name: ldap_person[:pudisplayname].first,
12✔
59
                    family_name: ldap_person[:sn].first, given_name: ldap_person[:givenname].first,
60
                    email: ldap_person[:edupersonprincipalname].first, provider: "cas")
61
      else
62
        user = current_entries.first
1✔
63
        if user.display_name.blank?
1✔
64
          user.display_name = ldap_person[:pudisplayname].first
1✔
65
          user.family_name = ldap_person[:sn].first
1✔
66
          user.given_name = ldap_person[:givenname].first
1✔
67
          user.provider = "cas"
1✔
68
          user.save
1✔
69
        end
70
        user
1✔
71
      end
72
    end
73

74
    # If any required LDAP fields are missing, return true
75
    # @param ldap_person [Net::LDAP::Entry] an LDAP entry representing a person
76
    # @return [Boolean] true if the LDAP entry is missing required fields, false otherwise
77
    def check_for_malformed_ldap_entries(ldap_person)
2✔
78
      uid_blank = ldap_person[:uid].blank?
17✔
79
      edupersonprincipalname_blank = ldap_person[:edupersonprincipalname].blank?
17✔
80
      malformed = uid_blank || edupersonprincipalname_blank
17✔
81
      malformed
17✔
82
    end
83

84
    def default_ldap_connection
2✔
85
      @default_ldap_connection ||= Net::LDAP.new host: "ldap.princeton.edu", base: "o=Princeton University,c=US", port: 636,
9✔
86
                                                  encryption: {
87
                                                    method: :simple_tls,
88
                                                    tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
89
                                                  }
90
    end
91
  end
92
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