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 11require 'active_support/core_ext/object/to_query'
2+ require 'base64'
23
34module RspecApiDocumentation
45 class Curl < Struct . new ( :method , :path , :data , :headers )
@@ -40,7 +41,11 @@ def url
4041
4142 def headers
4243 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
4449 end . join ( " " )
4550 end
4651
@@ -55,6 +60,10 @@ def post_data
5560
5661 private
5762
63+ def format_auth_header ( value )
64+ ::Base64 . decode64 ( value . split ( ' ' , 2 ) . last || '' )
65+ end
66+
5867 def format_header ( header )
5968 header . gsub ( /^HTTP_/ , '' ) . titleize . split . join ( "-" )
6069 end
Original file line number Diff line number Diff line change 171171 curl . output ( host )
172172 end
173173 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
174188end
You can’t perform that action at this time.
0 commit comments