facebook_registration 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -12,4 +12,9 @@
12
12
 
13
13
  === 1.0.3 / 2011-09-07
14
14
 
15
- * Missing MIT-LICENSE added.
15
+ * Missing MIT-LICENSE added.
16
+
17
+ === 1.0.4 / 2011-12-27
18
+
19
+ * Enabling to work with Rails3.
20
+ * Adding Test Cases.
data/README.rdoc CHANGED
@@ -13,14 +13,12 @@ facebook_registration is a ruby library for displaying new Facebook Registration
13
13
 
14
14
 
15
15
  === Using Gem in Rails
16
- Once you installed the gem, you will need to configure your Facebook app in config/facebooker.yml.
17
-
18
- You can copy facebooker.yml file which one is already available in this Root directory.
16
+ In previous versions, we must specify our FB app keys in a YAML file. But in this version we can directly specify the APP-ID, Secret key etc within the app whenever needed like below:
19
17
 
20
18
 
21
19
  === Initializing Registration Form
22
20
 
23
- <%= init_fb_registration %>
21
+ <%= init_fb_registration('YOUR-FACEBOOK-APP-ID') %>
24
22
 
25
23
 
26
24
  === Displaying Facebook Registration Form
@@ -50,7 +48,7 @@ For more form field specifications refer these urls:
50
48
 
51
49
  So in our case, you can parse the Facebook profile informations in the action fb_registration as follows:
52
50
 
53
- FacebookRegistration::SignedRequest.parse(params["signed_request"])
51
+ FacebookRegistration::SignedRequest.parse(params["signed_request"], 'YOUR-FACEBOOK-SECRET-KEY')
54
52
 
55
53
  it will return the output as follows:
56
54
 
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{facebook_registration}
5
- s.version = "1.0.3"
5
+ s.version = "1.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Veerasundaravel Thirugnanasundaram"]
9
- s.date = %q{2011-09-07}
9
+ s.date = %q{2011-12-27}
10
10
  s.description = %q{facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration].}
11
11
  s.email = ["veerasundaravel@gmail.com"]
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", ]
13
- s.files = ["CHANGELOG.rdoc", "README.rdoc", "MIT-LICENSE", "facebook_registration.gemspec", "facebooker.yml", "lib/facebook_registration.rb", "lib/helpers/helpers.rb", "lib/rails/signed_request.rb"]
13
+ s.files = ["CHANGELOG.rdoc", "README.rdoc", "MIT-LICENSE", "facebook_registration.gemspec", "lib/facebook_registration.rb", "lib/helpers/helpers.rb", "lib/rails/signed_request.rb", "test/test_fb_registration.rb", "test/test_fb_registration_helper.rb"]
14
14
  s.homepage = %q{http://veerasundaravel.wordpress.com/2011/01/27/facebook-registration-plugin-in-rails/}
15
15
  s.rdoc_options = ["--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{facebook_registration}
18
18
  s.rubygems_version = %q{1.3.5}
19
19
  s.summary = %q{facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration]. by Veerasundaravel Thirugnanasundaram}
20
- s.test_files = []
20
+ s.test_files = ["test/test_fb_registration.rb", "test/test_fb_registration_helper.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -1,32 +1,2 @@
1
- module FacebookRegistration
2
- @facebook_configuration = {}
3
- @raw_facebook_configuration = {}
4
- @current_adapter = nil
5
- @set_asset_host_to_callback_url = true
6
- @path_prefix = nil
7
- @use_curl = false
8
-
9
- class << self
10
-
11
- def load_configuration(facebook_yaml_file)
12
- return false unless File.exist?(facebook_yaml_file)
13
- @raw_facebook_configuration = YAML.load(ERB.new(File.read(facebook_yaml_file)).result)
14
- if defined? RAILS_ENV
15
- @raw_facebook_configuration = @raw_facebook_configuration[RAILS_ENV]
16
- end
17
- @raw_facebook_configuration
18
- end
19
-
20
- def facebook_config
21
- @facebook_configuration
22
- end
23
- end
24
- end
25
-
26
- facebook_config = "#{RAILS_ROOT}/config/facebooker.yml"
27
- FACEBOOK_CONFIG = FacebookRegistration.load_configuration(facebook_config)
28
-
29
- if defined? Rails
30
- require 'helpers/helpers'
31
- require 'rails/signed_request'
32
- end
1
+ require 'helpers/helpers'
2
+ require 'rails/signed_request'
@@ -1,4 +1,4 @@
1
- module FacebookRegistration
1
+ module FacebookRegistrationHelper
2
2
  def self.included(base)
3
3
  base.send :include, InstanceMethods
4
4
  end
@@ -7,9 +7,9 @@ module FacebookRegistration
7
7
  module InstanceMethods
8
8
  DefaultValues = {"fields" =>"name,email,password", "redirect-uri"=>"http://localhost:3000/fb_registration", "fb_only" => false, "width" => "100%", "height" => nil, "onvalidate" =>nil}
9
9
 
10
- def init_fb_registration
11
- raise "Must set Application ID for initializing" unless defined?(FACEBOOK_CONFIG) && FACEBOOK_CONFIG["app_id"]
12
- "<div id=\"fb-root\"></div> \n <script src=\"http://connect.facebook.net/en_US/all.js#appId=#{FACEBOOK_CONFIG["app_id"]}&xfbml=1\"></script> \n <script src=\"http://code.jquery.com/jquery-1.4.4.min.js\"></script>"
10
+ def init_fb_registration(app_id=nil)
11
+ raise "Must set Application ID for initializing" unless app_id
12
+ "<div id=\"fb-root\"></div> \n <script src=\"http://connect.facebook.net/en_US/all.js#appId=#{app_id}&xfbml=1\"></script> \n <script src=\"http://code.jquery.com/jquery-1.4.4.min.js\"></script>"
13
13
  end
14
14
 
15
15
  def fb_registration_form(options={})
@@ -26,5 +26,5 @@ end
26
26
 
27
27
  end
28
28
 
29
- ActionView::Base.send(:include, FacebookRegistration) if defined?(ActionView::Base)
29
+ ActionView::Base.send(:include, FacebookRegistrationHelper) if defined?(ActionView::Base)
30
30
 
@@ -4,40 +4,37 @@ require 'base64'
4
4
  require 'yajl'
5
5
 
6
6
  module FacebookRegistration
7
- class SignedRequest
8
- def self.parse(params)
9
- if params.is_a?(Hash)
10
- signed_request = params.delete('signed_request')
11
- else
12
- signed_request = params
13
- end
14
-
15
- unless signed_request
16
- raise "Missing signed_request param"
17
- end
18
-
19
- signature, signed_params = signed_request.split('.')
20
-
21
- unless signed_request_is_valid?(FACEBOOK_CONFIG['secret_key'], signature, signed_params)
22
- raise "Invalid signature"
23
- end
24
-
25
- signed_params = Yajl::Parser.new.parse(base64_url_decode(signed_params))
26
-
27
- return signed_params
7
+ class SignedRequest
8
+ def self.parse(params, secret_key=nil)
9
+ if params.is_a?(Hash)
10
+ signed_request = (params.delete('signed_request') || params.delete(:signed_request))
11
+ else
12
+ signed_request = params
28
13
  end
14
+ unless signed_request
15
+ raise "Missing signed_request param"
16
+ end
17
+ unless secret_key
18
+ raise "Missing Facebook secret key"
19
+ end
20
+ signature, signed_params = signed_request.split('.')
21
+ unless signed_request_is_valid?(secret_key, signature, signed_params)
22
+ raise "Invalid signature"
23
+ end
24
+ signed_params = Yajl::Parser.new.parse(base64_url_decode(signed_params))
25
+ return signed_params
26
+ end
29
27
 
30
- private
31
-
32
- def self.signed_request_is_valid?(secret, signature, params)
33
- signature = base64_url_decode(signature)
34
- expected_signature = OpenSSL::HMAC.digest('SHA256', secret, params.tr("-_", "+/"))
35
- return signature == expected_signature
36
- end
28
+ private
29
+ def self.signed_request_is_valid?(secret_key, signature, params)
30
+ signature = base64_url_decode(signature)
31
+ expected_signature = OpenSSL::HMAC.digest('SHA256', secret_key, params.to_s.tr("-_", "+/"))
32
+ return signature == expected_signature
33
+ end
37
34
 
38
- def self.base64_url_decode(str)
39
- str = str + "=" * (6 - str.size % 6) unless str.size % 6 == 0
40
- return Base64.decode64(str.tr("-_", "+/"))
41
- end
35
+ def self.base64_url_decode(str)
36
+ str = str + "=" * (6 - str.size % 6) unless str.size % 6 == 0
37
+ return Base64.decode64(str.tr("-_", "+/"))
42
38
  end
43
- end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'facebook_registration'
3
+
4
+ class FacebookRegistrationSignedRequestTest < Test::Unit::TestCase
5
+ def test_signed_request_is_initialized
6
+ assert FacebookRegistration::SignedRequest
7
+ end
8
+
9
+ def test_parse_should_raise_error_for_missing_secret_key
10
+ begin
11
+ FacebookRegistration::SignedRequest.parse({:signed_request => "vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0"})
12
+ rescue Exception => e
13
+ assert_equal "Missing Facebook secret key", e.message
14
+ end
15
+ end
16
+
17
+ def test_parse_should_raise_error_for_missing_signed_request
18
+ #Testing for missing value
19
+ begin
20
+ FacebookRegistration::SignedRequest.parse({:invalid_key => "some-dummy-data"}, 'valid-secret-key')
21
+ rescue Exception => e
22
+ assert_equal "Missing signed_request param", e.message
23
+ end
24
+
25
+ #Testing for invalid key
26
+ begin
27
+ FacebookRegistration::SignedRequest.parse({:signed_request => "some-dummy-data"}, 'valid-secret-key')
28
+ rescue Exception => e
29
+ assert_equal "Invalid signature", e.message
30
+ end
31
+ end
32
+
33
+ # TODO - Missing Success TestCases
34
+ # We need some valid signed_request parameter from facebook to test the remaining functionalities.
35
+ # So here we test only failure test cases.
36
+
37
+ end
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+ require 'facebook_registration'
3
+ include FacebookRegistrationHelper
4
+
5
+ class FacebookRegistrationTest < Test::Unit::TestCase
6
+ def test_default_values_is_defined
7
+ assert defined? DefaultValues
8
+ end
9
+
10
+ def test_default_values_assignment
11
+ assert_equal "name,email,password", DefaultValues["fields"]
12
+ assert_equal "http://localhost:3000/fb_registration", DefaultValues["redirect-uri"]
13
+ assert_equal false, DefaultValues["fb_only"]
14
+ end
15
+
16
+ def test_init_fb_registration_should_raise_error
17
+ begin
18
+ init_fb_registration
19
+ rescue Exception => e
20
+ assert_equal "Must set Application ID for initializing", e.message
21
+ end
22
+ end
23
+
24
+ def test_init_fb_registration_should_not_through_error_for_valid_input
25
+ assert init_fb_registration('some-api-key')
26
+ end
27
+
28
+ def test_init_fb_registration_should_return_fb_scripts
29
+ fb_scripts = init_fb_registration('some-api-key')
30
+ assert_match /<div id="fb-root"><\/div>/, fb_scripts
31
+ assert_match /http:\/\/connect.facebook.net\/en_US\/all.js#appId=some-api-key/, fb_scripts
32
+ end
33
+
34
+ def test_fb_registration_form_should_return_fb_registration_tags
35
+ form_text = fb_registration_form
36
+ assert_match /<fb:registration/, form_text
37
+ assert_match /<\/fb:registration>/, form_text
38
+ end
39
+
40
+ def test_fb_registration_form_should_use_default_values
41
+ form_text = fb_registration_form
42
+ assert_match /fields = "#{DefaultValues["fields"]}"/, form_text
43
+ assert_match /fb_only = "#{DefaultValues["fb_only"]}"/, form_text
44
+ end
45
+
46
+ def test_fb_registration_form_should_use_passed_values_instead_of_default_values
47
+ form_text = fb_registration_form("redirect-uri" => "http://test.localhost.com/fb_signup", "fb_only" => true)
48
+ assert_match /fb_only = "true"/, form_text
49
+ assert_match /redirect-uri = "http:\/\/test.localhost.com\/fb_signup"/, form_text
50
+ end
51
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook_registration
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Veerasundaravel Thirugnanasundaram
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-07 00:00:00 +05:30
18
+ date: 2011-12-27 00:00:00 +05:30
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,10 +49,11 @@ files:
49
49
  - README.rdoc
50
50
  - MIT-LICENSE
51
51
  - facebook_registration.gemspec
52
- - facebooker.yml
53
52
  - lib/facebook_registration.rb
54
53
  - lib/helpers/helpers.rb
55
54
  - lib/rails/signed_request.rb
55
+ - test/test_fb_registration.rb
56
+ - test/test_fb_registration_helper.rb
56
57
  has_rdoc: true
57
58
  homepage: http://veerasundaravel.wordpress.com/2011/01/27/facebook-registration-plugin-in-rails/
58
59
  licenses: []
@@ -88,5 +89,6 @@ rubygems_version: 1.4.2
88
89
  signing_key:
89
90
  specification_version: 1
90
91
  summary: facebook_registration is a ruby library for displaying new Facebook Registration form and to parse to signed_request[http://developers.facebook.com/docs/plugins/registration]. by Veerasundaravel Thirugnanasundaram
91
- test_files: []
92
-
92
+ test_files:
93
+ - test/test_fb_registration.rb
94
+ - test/test_fb_registration_helper.rb
data/facebooker.yml DELETED
@@ -1,14 +0,0 @@
1
- development:
2
- app_id: xxxxxxxxxxxxxxx
3
- api_key: xxxxxxxxxxxxxxx
4
- secret_key: xxxxxxxxxxxxxxx
5
-
6
- production:
7
- app_id: xxxxxxxxxxxxxxx
8
- api_key: xxxxxxxxxxxxxxx
9
- secret_key: xxxxxxxxxxxxxxx
10
-
11
- test:
12
- app_id: xxxxxxxxxxxxxxx
13
- api_key: xxxxxxxxxxxxxxx
14
- secret_key: xxxxxxxxxxxxxxx