facebook-stub 0.0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/Readme.md +56 -0
- data/builder/concat +8 -0
- data/facebook-stub.gemspec +24 -0
- data/facebook-stub.js +529 -0
- data/lib/facebook-stub.rb +54 -0
- data/lib/facebook-stub/rails/action_view_helper.rb +20 -0
- data/lib/facebook-stub/version.rb +5 -0
- data/src/facebook.js +307 -0
- data/src/libs/base64_encode.js +54 -0
- data/src/libs/cookie.js +107 -0
- data/src/libs/sha256.js +11 -0
- data/src/libs/utf8_encode.js +50 -0
- data/test/test.html +19 -0
- metadata +84 -0
data/src/libs/sha256.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
|
2
|
+
* PUB 180-2 as well as the corresponding HMAC implementation as defined in
|
3
|
+
* FIPS PUB 198a
|
4
|
+
*
|
5
|
+
* Version 1.3 Copyright Brian Turek 2008-2010
|
6
|
+
* Distributed under the BSD License
|
7
|
+
* See http://jssha.sourceforge.net/ for more information
|
8
|
+
*
|
9
|
+
* Several functions taken from Paul Johnson
|
10
|
+
*/
|
11
|
+
(function(){var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotr=function(x,n){return(x>>>n)|(x<<(32-n))},shr=function(x,n){return x>>>n},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},sigma0=function(x){return rotr(x,2)^rotr(x,13)^rotr(x,22)},sigma1=function(x){return rotr(x,6)^rotr(x,11)^rotr(x,25)},gamma0=function(x){return rotr(x,7)^rotr(x,18)^shr(x,3)},gamma1=function(x){return rotr(x,17)^rotr(x,19)^shr(x,10)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_4=function(a,b,c,d){var e=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16);return((msw&0xFFFF)<<16)|(e&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA2=function(j,k,l){var a,b,c,d,e,f,g,h,T1,T2,H,lengthPosition,i,t,K,W=[],appendedMessageLength;if(l==="SHA-224"||l==="SHA-256"){lengthPosition=(((k+65)>>9)<<4)+15;K=[0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0x0FC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x06CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2];if(l==="SHA-224"){H=[0xc1059ed8,0x367cd507,0x3070dd17,0xf70e5939,0xffc00b31,0x68581511,0x64f98fa7,0xbefa4fa4]}else{H=[0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19]}}j[k>>5]|=0x80<<(24-k%32);j[lengthPosition]=k;appendedMessageLength=j.length;for(i=0;i<appendedMessageLength;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];f=H[5];g=H[6];h=H[7];for(t=0;t<64;t+=1){if(t<16){W[t]=j[t+i]}else{W[t]=safeAdd_4(gamma1(W[t-2]),W[t-7],gamma0(W[t-15]),W[t-16])}T1=safeAdd_5(h,sigma1(e),ch(e,f,g),K[t],W[t]);T2=safeAdd_2(sigma0(a),maj(a,b,c));h=g;g=f;f=e;e=safeAdd_2(d,T1);d=c;c=b;b=a;a=safeAdd_2(T1,T2)}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4]);H[5]=safeAdd_2(f,H[5]);H[6]=safeAdd_2(g,H[6]);H[7]=safeAdd_2(h,H[7])}switch(l){case"SHA-224":return[H[0],H[1],H[2],H[3],H[4],H[5],H[6]];case"SHA-256":return H;default:return[]}},jsSHA=function(a,b){this.sha224=null;this.sha256=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a,b){var c=null,message=this.strToHash.slice();switch(b){case"HEX":c=binb2hex;break;case"B64":c=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case"SHA-224":if(null===this.sha224){this.sha224=coreSHA2(message,this.strBinLen,a)}return c(this.sha224);case"SHA-256":if(null===this.sha256){this.sha256=coreSHA2(message,this.strBinLen,a)}return c(this.sha256);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,b,c,d){var e,keyToUse,i,retVal,keyBinLen,hashBitSize,keyWithIPad=[],keyWithOPad=[];switch(d){case"HEX":e=binb2hex;break;case"B64":e=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(c){case"SHA-224":hashBitSize=224;break;case"SHA-256":hashBitSize=256;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(64<(keyBinLen/8)){keyToUse=coreSHA2(keyToUse,keyBinLen,c);keyToUse[15]&=0xFFFFFF00}else if(64>(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA2(keyWithIPad.concat(this.strToHash),512+this.strBinLen,c);retVal=coreSHA2(keyWithOPad.concat(retVal),512+hashBitSize,c);return(e(retVal))}};window.FBWorld.Helpers.jsSHA=jsSHA}());
|
@@ -0,0 +1,50 @@
|
|
1
|
+
FBWorld.Helpers.utf8_encode = function (argString) {
|
2
|
+
// http://kevin.vanzonneveld.net
|
3
|
+
// + original by: Webtoolkit.info (http://www.webtoolkit.info/)
|
4
|
+
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
5
|
+
// + improved by: sowberry
|
6
|
+
// + tweaked by: Jack
|
7
|
+
// + bugfixed by: Onno Marsman
|
8
|
+
// + improved by: Yves Sucaet
|
9
|
+
// + bugfixed by: Onno Marsman
|
10
|
+
// + bugfixed by: Ulrich
|
11
|
+
// + bugfixed by: Rafal Kukawski
|
12
|
+
// * example 1: utf8_encode('Kevin van Zonneveld');
|
13
|
+
// * returns 1: 'Kevin van Zonneveld'
|
14
|
+
|
15
|
+
if (argString === null || typeof argString === "undefined") {
|
16
|
+
return "";
|
17
|
+
}
|
18
|
+
|
19
|
+
var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
20
|
+
var utftext = "",
|
21
|
+
start, end, stringl = 0;
|
22
|
+
|
23
|
+
start = end = 0;
|
24
|
+
stringl = string.length;
|
25
|
+
for (var n = 0; n < stringl; n++) {
|
26
|
+
var c1 = string.charCodeAt(n);
|
27
|
+
var enc = null;
|
28
|
+
|
29
|
+
if (c1 < 128) {
|
30
|
+
end++;
|
31
|
+
} else if (c1 > 127 && c1 < 2048) {
|
32
|
+
enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
|
33
|
+
} else {
|
34
|
+
enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
|
35
|
+
}
|
36
|
+
if (enc !== null) {
|
37
|
+
if (end > start) {
|
38
|
+
utftext += string.slice(start, end);
|
39
|
+
}
|
40
|
+
utftext += enc;
|
41
|
+
start = end = n + 1;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
if (end > start) {
|
46
|
+
utftext += string.slice(start, stringl);
|
47
|
+
}
|
48
|
+
|
49
|
+
return utftext;
|
50
|
+
}
|
data/test/test.html
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<script src="../facebook-stub.js" type="text/javascript" charset="utf-8"></script>
|
4
|
+
<script type="text/javascript" charset="utf-8">
|
5
|
+
FB.init({appId: 12345});
|
6
|
+
FBWorld.setSecret('awesome');
|
7
|
+
FBWorld.loggedIn();
|
8
|
+
FBWorld.connected();
|
9
|
+
</script>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1>Facebook Test</h1>
|
13
|
+
|
14
|
+
<p>
|
15
|
+
Warning: If you are accessing this from a file:// url, it <span style="color: #f00">will <span style="font-size: 150%">FAIL</span></span>!
|
16
|
+
</p>
|
17
|
+
|
18
|
+
</body>
|
19
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facebook-stub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 73
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
- 1
|
11
|
+
version: 0.0.1.1
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Change.org
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2012-01-20 00:00:00 -08:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description: facebook-stub is a gem for stubbing out the Facebook JavaScript API in acceptance and integration tests.
|
24
|
+
email:
|
25
|
+
- techops@change.org
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Rakefile
|
36
|
+
- Readme.md
|
37
|
+
- builder/concat
|
38
|
+
- facebook-stub.gemspec
|
39
|
+
- facebook-stub.js
|
40
|
+
- lib/facebook-stub.rb
|
41
|
+
- lib/facebook-stub/rails/action_view_helper.rb
|
42
|
+
- lib/facebook-stub/version.rb
|
43
|
+
- src/facebook.js
|
44
|
+
- src/libs/base64_encode.js
|
45
|
+
- src/libs/cookie.js
|
46
|
+
- src/libs/sha256.js
|
47
|
+
- src/libs/utf8_encode.js
|
48
|
+
- test/test.html
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: ""
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project: facebook-stub
|
79
|
+
rubygems_version: 1.5.3
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Stub out the FB JS API
|
83
|
+
test_files:
|
84
|
+
- test/test.html
|