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

pulibrary / tigerdata-app / d3b493b9-2850-48c1-a36e-b776d88c055f

05 Aug 2025 06:27PM UTC coverage: 75.677% (-0.03%) from 75.703%
d3b493b9-2850-48c1-a36e-b776d88c055f

push

circleci

web-flow
Set the provider to cas for new ldap users (#1688)

fixes #1591

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

1 existing line in 1 file now uncovered.

2181 of 2882 relevant lines covered (75.68%)

178.61 hits per line

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

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

6
  class << self
1✔
7
      
8
    # Return the list of Users who are already in the database.
9
    def user_list
1✔
10
      Rails.cache.fetch("princeton_user_list", expires_in: 6.hours) do
41✔
11
        @user_list = User.all.map { |user| { uid: user.uid, name: user.display_name } }
84✔
12
      end
13
    end
14

15
    def load_rdss_developers
1✔
16
      RDSS_DEVELOPERS.each do |netid|
×
17
        create_user_from_ldap_by_uid(netid)
×
18
      end
19
    end
20

21
    # Creates users from LDAP data, starting with the given uid prefix.
22
    def create_users_from_ldap(current_uid_start: "", ldap_connection: default_ldap_connection)
1✔
23
      CHARS_AND_NUMS.each do |char|
4✔
24
        filter =(~ Net::LDAP::Filter.eq( "pustatus", "guest" )) & Net::LDAP::Filter.eq("uid", "#{current_uid_start}#{char}*")
148✔
25
        people = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
148✔
26
        if ldap_connection.get_operation_result.message == "Success"
148✔
27
          people.each{|person| user_from_ldap(person)}
150✔
28
        else
29
          create_users_from_ldap(current_uid_start: "#{current_uid_start}#{char}", ldap_connection:)
1✔
30
        end
31
      end
32
    end
33

34
    def create_user_from_ldap_by_uid(uid, ldap_connection: default_ldap_connection)
1✔
35
      filter = Net::LDAP::Filter.eq('uid', uid)
×
36
      person = ldap_connection.search(filter:, attributes: [:pudisplayname, :givenname, :sn, :uid, :edupersonprincipalname]);
×
37
      raise TigerData::LdapError, "More than one user matches supplied uid: #{uid}" if person.length > 1
×
38
      raise TigerData::LdapError, "No user with uid #{uid} found" if person.empty?
×
39
      user_from_ldap(person.first)
×
40
    end
41

42
    def user_from_ldap(ldap_person)
1✔
43
      return if ldap_person[:edupersonprincipalname].blank?
3✔
44
      uid = ldap_person[:uid].first.downcase
2✔
45
      current_entries = User.where(uid:)
2✔
46
      if current_entries.empty?
2✔
47
        User.create(uid: , display_name: ldap_person[:pudisplayname].first, 
2✔
48
                    family_name: ldap_person[:sn].first, given_name: ldap_person[:givenname].first, 
49
                    email: ldap_person[:edupersonprincipalname].first, provider: "cas")
50
      else
51
        user = current_entries.first
×
52
        if user.display_name.blank?
×
53
          user.display_name = ldap_person[:pudisplayname].first
×
54
          user.family_name = ldap_person[:sn].first
×
55
          user.given_name = ldap_person[:givenname].first
×
NEW
56
          user.provider = "cas"
×
UNCOV
57
          user.save
×
58
        end
59
      end
60
    end
61

62
    def default_ldap_connection
1✔
63
      @default_ldap_connection ||= Net::LDAP.new host: "ldap.princeton.edu", base: "o=Princeton University,c=US", port: 636,
×
64
                                                  encryption: {
65
                                                    method: :simple_tls,
66
                                                    tls_options: OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
67
                                                  }
68
    end
69
  end
70
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