Use sinatra to set up basic auth HTTP server
authorJohn Duarte <john.duarte@puppetlabs.com>
Thu, 15 May 2014 20:21:13 +0000 (13:21 -0700)
committerJohn Duarte <john.duarte@puppetlabs.com>
Sun, 18 May 2014 18:38:20 +0000 (11:38 -0700)
spec/acceptance/beaker/git/basic_auth/basic_auth_checkout_http.rb

index f2486cd..69e1941 100644 (file)
@@ -8,6 +8,7 @@ http_server_script = 'basic_auth_http_daemon.rb'
 
 hosts.each do |host|
   ruby = '/opt/puppet/bin/ruby' if host.is_pe? || 'ruby'
+  gem = '/opt/puppet/bin/gem' if host.is_pe? || 'gem'
   tmpdir = host.tmpdir('vcsrepo')
   step 'setup - create repo' do
     install_package(host, 'git')
@@ -18,23 +19,19 @@ hosts.each do |host|
 
   step 'setup - start http server' do
     script =<<-EOF
-    require 'webrick'
+    require 'sinatra'
+
+    set :bind, '0.0.0.0'
+    set :static, true
+    set :public_folder, '#{tmpdir}'
 
-    authenticate = Proc.new do |req, res|
-      WEBrick::HTTPAuth.basic_auth(req, res, '') do |user, password|
-        user == '#{user}' && password == '#{password}'
-      end
-    end
 
-    server = WEBrick::HTTPServer.new(
-    :Port               => 8000,
-    :DocumentRoot       => "#{tmpdir}",
-    :DocumentRootOptions=> {:HandlerCallback => authenticate},
-    )
-    WEBrick::Daemon.start
-    server.start
+    use Rack::Auth::Basic do |username, password|
+        username == '#{user}' && password == '#{password}'
+    end
     EOF
     create_remote_file(host, "#{tmpdir}/#{http_server_script}", script)
+    on(host, "#{gem} install sinatra")
     on(host, "#{ruby} #{tmpdir}/#{http_server_script} &")
   end
 
@@ -47,7 +44,7 @@ hosts.each do |host|
     pp = <<-EOS
     vcsrepo { "#{tmpdir}/#{repo_name}":
       ensure => present,
-      source => "http://#{host}:8000/testrepo.git",
+      source => "http://#{host}:4567/testrepo.git",
       provider => git,
       basic_auth_username => '#{user}',
       basic_auth_password => '#{password}',