Permalink
Browse files

Adding test for character encoding / body length issue

  • Loading branch information...
1 parent 5f383ff commit 7e2aa8cfbed3e8194d0525fd2899a8255676c436 @ciaranj ciaranj committed Jun 25, 2011
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/oauth.js
View
@@ -306,6 +306,36 @@ vows.describe('OAuth').addBatch({
}
},
'if the post_body is a string' : {
+ "and it contains non ascii (7/8bit) characters" : {
+ "the content length should be the byte count, and not the string length" : function(oa) {
+ var testString= "Tôi yêu node";
+ var testStringLength= testString.length;
+ var testStringBytesLength= Buffer.byteLength(testString);
+ assert.notEqual(testStringLength, testStringBytesLength); // Make sure we're testing a string that differs between byte-length and char-length!
+
+ var op= oa._createClient;
+ try {
+ var callbackCalled= false;
+ oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
+ assert.equal(headers["Content-length"], testStringBytesLength);
+ return {
+ write: function(data){
+ callbackCalled= true;
+ assert.equal(data, testString);
+ },
+ on: function() {},
+ end: function() {
+ }
+ };
+ }
+ var request= oa.post("http://foo.com/blah", "token", "token_secret", "Tôi yêu node")
+ assert.equal(callbackCalled, true);
+ }
+ finally {
+ oa._createClient= op;
+ }
+ }
+ },
"and no post_content_type is specified" : {
"It should be written as is, with a content length specified, and the encoding should be set to be x-www-form-urlencoded" : function(oa) {
var op= oa._createClient;

0 comments on commit 7e2aa8c

Please sign in to comment.