Changeset 1028

Show
Ignore:
Timestamp:
06/17/08 22:25:08 (21 months ago)
Author:
vasi
Message:

yaml auth

Location:
easyweb/trunk
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • easyweb/trunk

    • Property svn:ignore
      •  

        old new  
        1 test.rb 
         1auth.yaml 
         2 
  • easyweb/trunk/easyweb/authenticator.rb

    r1026 r1028  
    1 class EasyWeb::PlainAuthenticator 
     1require 'yaml' 
     2 
     3class EasyWeb::RubyAuthenticator 
    24        attr_reader :user, :password 
     5         
    36        def initialize(user, pass, &oracle) 
    47                @user = user; @password = pass; @oracle = oracle 
     
    69        def challenge(q); @oracle[q]; end 
    710end 
     11 
     12# YAML should contain: 
     13#       - user 
     14#       - password 
     15#       - challenge: 
     16#               hash of regexes matching challenge questions, to challenge answers 
     17class EasyWeb::YAMLAuthenticator 
     18        attr_reader :user, :password 
     19                 
     20        def initialize(io) 
     21                yaml = YAML.load(io) 
     22                @user = "%013d" % yaml['user'].to_i 
     23                @password = yaml['password'] 
     24                @answers = yaml['challenge'].map { |k,v| [Regexp.new(k), v] } 
     25        end 
     26         
     27        def challenge(q) 
     28                @answers.each { |re, a| return a if re === q } 
     29                nil 
     30        end 
     31end 
  • easyweb/trunk/easyweb/login.rb

    r1026 r1028  
    1010         
    1111        def login_page 
    12                 refresh = @mech.get('https://easyweb.tdcanadatrust.com//main.jsp' + 
     12                refresh = @mech.get('https://easyweb.tdcanadatrust.com/main.jsp' + 
    1313                        '?lang=english&fromIndex=true') 
    1414                md = /"(http[^"]*tdcanadatrust[^"]*)"/.match(refresh.body)