File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
lib/rspec_api_documentation Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 1
1
require 'active_support/core_ext/object/to_query'
2
+ require 'base64'
2
3
3
4
module RspecApiDocumentation
4
5
class Curl < Struct . new ( :method , :path , :data , :headers )
@@ -40,7 +41,11 @@ def url
40
41
41
42
def headers
42
43
filter_headers ( super ) . map do |k , v |
43
- "\\ \n \t -H \" #{ format_full_header ( k , v ) } \" "
44
+ if k == "HTTP_AUTHORIZATION" && v =~ /^Basic/
45
+ "\\ \n \t -u #{ format_auth_header ( v ) } "
46
+ else
47
+ "\\ \n \t -H \" #{ format_full_header ( k , v ) } \" "
48
+ end
44
49
end . join ( " " )
45
50
end
46
51
@@ -55,6 +60,10 @@ def post_data
55
60
56
61
private
57
62
63
+ def format_auth_header ( value )
64
+ ::Base64 . decode64 ( value . split ( ' ' , 2 ) . last || '' )
65
+ end
66
+
58
67
def format_header ( header )
59
68
header . gsub ( /^HTTP_/ , '' ) . titleize . split . join ( "-" )
60
69
end
Original file line number Diff line number Diff line change 171
171
curl . output ( host )
172
172
end
173
173
end
174
+
175
+ describe "Basic Authentication" do
176
+ let ( :method ) { "GET" }
177
+ let ( :path ) { "/" }
178
+ let ( :data ) { "" }
179
+ let ( :headers ) do
180
+ {
181
+ "HTTP_AUTHORIZATION" => %{Basic dXNlckBleGFtcGxlLm9yZzpwYXNzd29yZA==} ,
182
+ }
183
+ end
184
+
185
+ it { should_not =~ /-H "Authorization: Basic dXNlckBleGFtcGxlLm9yZzpwYXNzd29yZA=="/ }
186
+ it { should =~ /-u user@example\. org:password/ }
187
+ end
174
188
end
You can’t perform that action at this time.
0 commit comments