Files
RestKit/Tests/Server/lib/restkit/network/authentication.rb
Blake Watters 4142ffdb42 Reorganization and cleanups of Unit Tests
* Reorganized tests to accommodate split into Logic & Application.
* Eliminated 'Spec' naming in favor of 'Test' as the suite is entirely based on SenTest.
* Pulled majority of testing support classes up into the library and documented them.
* Introduced RKApplicationTests app for running the RKTableController UI tests
2012-02-10 17:32:23 -05:00

38 lines
1.3 KiB
Ruby

module RestKit
module Network
class Authentication < Sinatra::Base
AUTH_USERNAME = 'restkit'
AUTH_PASSWORD = 'authentication'
AUTH_REALM = 'RestKit'
AUTH_OPAQUE = '7e7e7e7e7e'
get '/authentication/none' do
"Success!"
end
get '/authentication/basic' do
@auth ||= Rack::Auth::Basic::Request.new(request.env)
puts "Auth was provided: #{@auth.provided?}"
puts "Credentials: #{@auth.credentials}" if @auth.provided?
unless @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [AUTH_USERNAME, AUTH_PASSWORD]
response['WWW-Authenticate'] = %(Basic realm="#{AUTH_REALM}")
throw(:halt, [401, "Access Denied.\n"])
end
end
get '/authentication/digest' do
app = lambda do |env|
[ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ]
end
auth = Rack::Auth::Digest::MD5.new(app) do |username|
username == AUTH_USERNAME ? Digest::MD5.hexdigest("#{AUTH_USERNAME}:#{AUTH_REALM}:#{AUTH_PASSWORD}") : nil
end
auth.realm = AUTH_REALM
auth.opaque = AUTH_OPAQUE
auth.passwords_hashed = true
auth.call(request.env)
end
end
end
end