|
28 | 28 | pairs.should include('session=1') |
29 | 29 | end |
30 | 30 |
|
| 31 | + it 'should imply secure=true when the key parameter is set' do |
| 32 | + rsa = mock('OpenSSL::PKey::RSA', :private_encrypt => 'signature') |
| 33 | + digest = mock('OpenSSL::Digest::SHA1', :hexdigest => 'digest') |
| 34 | + OpenSSL::Digest::SHA1.expects(:new).returns(digest).at_least_once |
| 35 | + OpenSSL::PKey::RSA.expects(:new).with('secret-key').returns(rsa).at_least_once |
| 36 | + |
| 37 | + pairs = parse_authentication_url(nil, :key => 'secret-key').query.split('&') |
| 38 | + |
| 39 | + pairs.should include('secure=1') |
| 40 | + pairs.should include('sig=c2lnbmF0dXJl%0A') # ['signature'].pack('m') |
| 41 | + pairs.should_not include('key=secret-key') |
| 42 | + end |
| 43 | + |
| 44 | + it 'should accept File or IO key parameter' do |
| 45 | + rsa = mock('OpenSSL::PKey::RSA', :private_encrypt => 'signature') |
| 46 | + digest = mock('OpenSSL::Digest::SHA1', :hexdigest => 'digest') |
| 47 | + OpenSSL::Digest::SHA1.expects(:new).returns(digest).at_least_once |
| 48 | + OpenSSL::PKey::RSA.expects(:new).with(File.open(File.join(File.dirname(__FILE__), 'myrsakey.pem')).read).returns(rsa).at_least_once |
| 49 | + |
| 50 | + pairs = parse_authentication_url(nil, :key => File.open(File.join(File.dirname(__FILE__), 'myrsakey.pem'))).query.split('&') |
| 51 | + |
| 52 | + pairs.should include('secure=1') |
| 53 | + pairs.should include('sig=c2lnbmF0dXJl%0A') # ['signature'].pack('m') |
| 54 | + pairs.should_not include('key=secret-key') |
| 55 | + end |
| 56 | + |
| 57 | + it 'should accept OpenSSL::Pkey::RSA key parameter' do |
| 58 | + digest = mock('OpenSSL::Digest::SHA1', :hexdigest => 'digest') |
| 59 | + OpenSSL::Digest::SHA1.expects(:new).returns(digest).at_least_once |
| 60 | + |
| 61 | + pairs = parse_authentication_url(nil, :key => OpenSSL::PKey::RSA.new(File.open(File.join(File.dirname(__FILE__), 'myrsakey.pem')).read)).query.split('&') |
| 62 | + |
| 63 | + pairs.should include('secure=1') |
| 64 | + pairs.should include('sig=nhzzbfqHUOhN6iE%2BkyHQabRvtfc3pbxKQt4hHqlNtBZVliswTFfVIISFPo5Z%0Ads6YVeAKdqAAZuVFUwMDihA83ihIf8spWN%2BrKpeLxAhrUCM69oihD7csdedG%0AbN9TCToIp4q9tJj2o4SsAgxs3dK55Nc1vhCOlVB7mIbxM%2B8YGL4%3D%0A') # based on 'digest' data |
| 65 | + pairs.should_not include('key=secret-key') |
| 66 | + end |
| 67 | + |
31 | 68 | it 'skips parameters that have nil value' do |
32 | 69 | query = parse_authentication_url(nil, :secure => nil).query |
33 | 70 | query.should_not include('next') |
|
0 commit comments