<commit_before>require 'camping/db'

module CASServer::Models
  
  module Consumable
    def consume!
      self.consumed = Time.now
      self.save!
    end
  end
  
  class Ticket < Base
    def to_s
      ticket
    end
    
    def self.cleanup_expired(expiry_time)
      transaction do
        expired_tickets = find(:all, 
          :conditions => ["created_on < ?", Time.now - expiry_time])
          
        $LOG.debug("Destroying #{expired_tickets.size} expired #{self}"+
          "#{'s' if expired_tickets.size > 1}.") if expired_tickets.size > 0
      
        expired_tickets.each do |t|
          t.destroy
        end
      end
    end
  end
  
  class LoginTicket < Ticket
    set_table_name 'casserver_lt'
    include Consumable
  end
  
  class ServiceTicket < Ticket
    set_table_name 'casserver_st'
    include Consumable
    
    def matches_service?(service)
      # We ignore the trailing slash in URLs, since 
      # "http://www.google.com/" and "http://www.google.com" are almost
      # certainly the same service.
      self.service.gsub(/\/$/, '') == service.gsub(/\/$/, '')
    end<commit_msg>strip CAS-related parameters from service when comparing url with matches_service?<commit_after>require 'camping/db'

module CASServer::Models
  
  module Consumable
    def consume!
      self.consumed = Time.now
      self.save!
    end
  end
  
  class Ticket < Base
    def to_s
      ticket
    end
    
    def self.cleanup_expired(expiry_time)
      transaction do
        expired_tickets = find(:all, 
          :conditions => ["created_on < ?", Time.now - expiry_time])
          
        $LOG.debug("Destroying #{expired_tickets.size} expired #{self}"+
          "#{'s' if expired_tickets.size > 1}.") if expired_tickets.size > 0
      
        expired_tickets.each do |t|
          t.destroy
        end
      end
    end
  end
  
  class LoginTicket < Ticket
    set_table_name 'casserver_lt'
    include Consumable
  end
  
  class ServiceTicket < Ticket
    set_table_name 'casserver_st'
    include Consumable
    
    def matches_service?(service)
      # Remove CAS-related parameters from the service URL, since they really shoudln't
      # be there (some misbehaving clients include them in the service URL).
      ['service', 'ticket', 'gateway', 'renew'].each do |p|
        service.gsub!(Regexp.new("#{p}=[^&]*"), '')
      end
      
      # We ignore the trailing slash and ? in URLs, since 
      # "http://www.google.com/" and "http://www.google.com" are almost
      # certainly the same service.
      self.service.gsub(/[\/\?]$/, '') == service.gsub(/[\/\?]$/, '')
    end
{'fraction_non_alphanumeric': 0.1119147316330415, 'fraction_numerical': 0.0015226494099733537, 'mean_word_length': 2.2524752475247523, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3183770', 'n_tokens_mistral': 857, 'n_tokens_neox': 831, 'n_words': 211}