remi-rackbox 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 1
4
- :patch: 5
4
+ :patch: 6
@@ -72,11 +72,32 @@ class RackBox
72
72
  input = RackBox.build_query options[:params]
73
73
  end
74
74
 
75
+ # add HTTP BASIC AUTH support
76
+ #
77
+ # TODO: DRY this up!
78
+ #
79
+ if options[:auth]
80
+ options[:http_basic_authentication] = options[:auth]
81
+ options.delete :auth
82
+ end
83
+ if options[:basic_auth]
84
+ options[:http_basic_authentication] = options[:basic_auth]
85
+ options.delete :basic_auth
86
+ end
87
+ if options[:http_basic_authentication]
88
+ username, password = options[:http_basic_authentication]
89
+ options.delete :http_basic_authentication
90
+ require 'base64'
91
+ # for some reason, nase64 encoding adds a \n
92
+ encoded_username_and_password = Base64.encode64("#{ username }:#{ password }").sub(/\n$/, '')
93
+ options['HTTP_AUTHORIZATION'] = "Basic #{ encoded_username_and_password }"
94
+ end
95
+
75
96
  headers = options.dup
76
97
  headers.delete :data if headers[:data]
77
98
  headers.delete :params if headers[:params]
78
99
  headers.delete :method if headers[:method]
79
-
100
+
80
101
  # merge input
81
102
  headers[:input] = input
82
103
 
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe RackBox, 'basic auth' do
4
+
5
+ it 'should be able to add HTTP BASIC AUTH to a request' do
6
+ app = lambda {|env| [200, {}, "i require http basic auth"] }
7
+ app = Rack::Auth::Basic.new(app){|u,p| u == 'remi' && p == 'testing' }
8
+
9
+ RackBox.request( app, '/' ).status.should == 401
10
+ RackBox.request( app, '/' ).headers.should == { 'WWW-Authenticate' => 'Basic realm=""' }
11
+
12
+ # response = RackBox.request( app, '/', 'Authentication' => 'Basic: ^' )
13
+
14
+ response = RackBox.request( app, '/', :http_basic_authentication => %w( remi testing ) )
15
+ response.status.should == 200
16
+ response.body.should == "i require http basic auth"
17
+
18
+ # :basic_auth shortcut
19
+ response = RackBox.request( app, '/', :basic_auth => %w( remi testing ) )
20
+ response.status.should == 200
21
+ response.body.should == "i require http basic auth"
22
+
23
+ # :auth shortcut
24
+ response = RackBox.request( app, '/', :auth => %w( remi testing ) )
25
+ response.status.should == 200
26
+ response.body.should == "i require http basic auth"
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remi-rackbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - remi
@@ -65,6 +65,7 @@ files:
65
65
  - lib/rackbox/test.rb
66
66
  - lib/rackbox/rackbox.rb
67
67
  - lib/rackbox/matchers.rb
68
+ - spec/basic_auth_spec.rb
68
69
  - spec/request_method_spec.rb
69
70
  - spec/posting_data_spec.rb
70
71
  - spec/rackbox_build_query_spec.rb
@@ -163,9 +164,6 @@ files:
163
164
  - examples/rails/README
164
165
  - examples/rails/doc
165
166
  - examples/rails/doc/README_FOR_APP
166
- - examples/rails/log
167
- - examples/rails/log/test.log
168
- - examples/rails/log/development.log
169
167
  - rails_generators/blackbox_spec
170
168
  - rails_generators/blackbox_spec/blackbox_spec_generator.rb
171
169
  - rails_generators/blackbox_spec/USAGE