annotate test/mocks/open_id_authentication_mock.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@0 1 # Mocks out OpenID
Chris@0 2 #
Chris@0 3 # http://www.northpub.com/articles/2007/04/02/testing-openid-support
Chris@909 4 module OpenIdAuthentication
Chris@0 5
Chris@909 6 EXTENSION_FIELDS = {'email' => 'user@somedomain.com',
Chris@0 7 'nickname' => 'cool_user',
Chris@909 8 'country' => 'US',
Chris@0 9 'postcode' => '12345',
Chris@0 10 'fullname' => 'Cool User',
Chris@909 11 'dob' => '1970-04-01',
Chris@0 12 'language' => 'en',
Chris@909 13 'timezone' => 'America/New_York'}
Chris@0 14
Chris@0 15 protected
Chris@0 16
Chris@0 17 def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
Chris@0 18 if User.find_by_identity_url(identity_url) || identity_url.include?('good')
Chris@0 19 # Don't process registration fields unless it is requested.
Chris@0 20 unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
Chris@0 21 extension_response_fields = {}
Chris@0 22
Chris@0 23 options[:required].each do |field|
Chris@0 24 extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
Chris@0 25 end unless options[:required].nil?
Chris@0 26
Chris@0 27 options[:optional].each do |field|
Chris@0 28 extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
Chris@0 29 end unless options[:optional].nil?
Chris@0 30 end
Chris@0 31
Chris@0 32 yield Result[:successful], identity_url , extension_response_fields
Chris@0 33 else
Chris@909 34 logger.info "OpenID authentication failed: #{identity_url}"
Chris@0 35 yield Result[:failed], identity_url, nil
Chris@0 36 end
Chris@0 37 end
Chris@0 38
Chris@0 39 private
Chris@0 40
Chris@0 41 def add_simple_registration_fields(open_id_response, fields)
Chris@0 42 open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
Chris@0 43 open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
Chris@0 44 end
Chris@0 45 end