test/test_parse.rb in rest-graph-1.7.0 vs test/test_parse.rb in rest-graph-1.8.0

- old
+ new

@@ -56,18 +56,21 @@ end should 'parse json correctly' do rg = RestGraph.new - rg.parse_json!('bad json').should == nil + rg.parse_json!('bad json') .should == nil rg.parse_json!('{"no":"sig"}').should == nil rg.parse_json!('{"feed":"me","sig":"bddd192cf27f22c05f61c8bea24fa4b7"}'). should == nil rg = RestGraph.new(:secret => 'bread') rg.parse_json!('{"feed":"me","sig":"20393e7823730308938a86ecf1c88b14"}'). should == {'feed' => 'me', 'sig' => "20393e7823730308938a86ecf1c88b14"} + rg.data.empty?.should == false + rg.parse_json!('bad json') + rg.data.empty?.should == true end should 'parse signed_request' do secret = 'aloha' json = RestGraph.json_encode('ooh' => 'dir', 'moo' => 'bar') @@ -83,27 +86,30 @@ rg.data['ooh'].should == 'dir' rg.data['moo'].should == 'bar' signed_request = "#{encode[sig[0..-4]+'bad']}.#{json_encoded}" rg.parse_signed_request!(signed_request).should == nil + rg.data .should == {} end should 'fallback to ruby-hmac if Digest.new raise an runtime error' do key, data = 'top', 'secret' - mock(OpenSSL::Digest::Digest).new('sha256'){ raise 'boom' } - RestGraph.hmac_sha256(key, data).should == - OpenSSL::HMAC.digest('sha256', key, data) + digest = OpenSSL::HMAC.digest('sha256', key, data) + mock(OpenSSL::HMAC).digest('sha256', key, data){ raise 'boom' } + RestGraph.hmac_sha256(key, data).should == digest end should 'generate correct fbs with correct sig' do RestGraph.new(:access_token => 'fake', :secret => 's').fbs.should == "access_token=fake&sig=#{Digest::MD5.hexdigest('access_token=fakes')}" end should 'parse fbs from facebook response which lacks sig...' do rg = RestGraph.new(:access_token => 'a', :secret => 'z') rg.parse_fbs!(rg.fbs) .should.kind_of?(Hash) + rg.data.empty?.should == false rg.parse_fbs!(rg.fbs.sub(/sig\=\w+/, 'sig=abc')).should == nil + rg.data.empty?.should == true end should 'generate correct fbs with additional parameters' do rg = RestGraph.new(:access_token => 'a', :secret => 'z') rg.data['expires'] = '1234'