Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6638: ajax-auth-6658.diff

File ajax-auth-6658.diff, 3.4 kB (added by madrobby, 2 years ago)

for playing with the authorization header

  • test/unit/ajax.html

    old new  
    2929<script type="text/javascript" language="javascript" charset="utf-8"> 
    3030// <![CDATA[ 
    3131  var responderCounter = 0; 
     32  var auth = ''; 
    3233 
    3334  new Test.Unit.Runner({ 
    3435     
    3536    setup: function(){ 
     37      auth = ''; 
    3638      $('content').update(''); 
    3739      $('content2').update(''); 
    3840    }, 
     
    7173      }); 
    7274    }}, 
    7375     
     76    testAuthorization: function() {with(this) { 
     77      new Ajax.Request("/auth", { 
     78        asynchronous: true, 
     79        requestHeaders: {'Authorization': 'Basic Zm9vOmJhcg=='}, 
     80        onComplete: function(response) { eval(response.responseText) } 
     81      }); 
     82      wait(1000,function(){ 
     83        assertEqual('Basic Zm9vOmJhcg==', auth); // foo:bar 
     84      }); 
     85    }}, 
     86     
    7487    testUpdater: function() {with(this) { 
    7588      assertEqual("", $("content").innerHTML); 
    7689       
  • test/lib/jstest.rb

    old new  
    125125  end 
    126126end 
    127127 
     128class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler 
     129  def do_GET(req, res) 
     130    super 
     131    res['etag'] = nil 
     132    res['last-modified'] = Time.now + 1000 
     133    res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0"' 
     134    res['Pragma'] = 'no-cache' 
     135    res['Expires'] = Time.now - 1000 
     136  end 
     137end 
     138 
    128139class JavaScriptTestTask < ::Rake::TaskLib 
    129140 
    130141  def initialize(name=:test) 
     
    141152      @queue.push(req.query['result']) 
    142153      res.body = "OK" 
    143154    end 
     155     
     156    # return for HTTP authorization test 
     157    @server.mount_proc("/auth") do |req, res| 
     158      res.body = "auth = '#{req["Authorization"]}'" 
     159    end 
     160     
    144161    yield self if block_given? 
    145162    define 
    146163  end 
     
    174191  def mount(path, dir=nil) 
    175192    dir = Dir.pwd + path unless dir 
    176193 
    177     @server.mount(path, WEBrick::HTTPServlet::FileHandler, dir) 
     194    # i said: don't cache 
     195    @server.mount(path, NonCachingFileHandler, dir) 
    178196  end 
    179197 
    180198  # test should be specified as a url 
  • src/ajax.js

    old new  
    9898       
    9999    try { 
    100100      Ajax.Responders.dispatch('onCreate', this, this.transport); 
    101      
    102       this.transport.open(this.options.method.toUpperCase(), this.url,  
    103         this.options.asynchronous, this.options.username,  
    104         this.options.password); 
     101       
     102      this.transport.open(this.options.method.toUpperCase(), this.url, 
     103        this.options.asynchronous); 
    105104 
    106105      if (this.options.asynchronous) 
    107106        setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10); 
     
    117116      /* Force Firefox to handle ready state 4 for synchronous requests */ 
    118117      if (!this.options.asynchronous && this.transport.overrideMimeType) 
    119118        this.onStateChange(); 
    120          
    121119    } 
    122120    catch (e) { 
    123121      this.dispatchException(e); 
  • CHANGELOG

    old new  
     1*SVN* 
     2 
    13* Add $w() to easily create arrays from strings like Ruby's %w, fixes #5682 [glazedginger, brendon.aaron] 
    24 
    35* Add Element.toggleClassName() to toggle CSS classes on elements, fixes #6759 [Tobie]