From c4dc53389ecc155a569361399198ea7eb25ca082 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 12 Oct 2016 10:49:46 -0500 Subject: [PATCH] Remove extraneous files. --- .gitignore | 1 + Makefile | 7 -- oauth-1.0a.js => oauth.js | 0 package.json | 28 ----- test/README.md | 34 ----- test/getParameterString.js | 21 ---- test/options/consumer.js | 14 --- test/options/last_ampersand.js | 55 --------- test/options/multiple_values.js | 54 -------- test/options/nonce_length.js | 40 ------ test/options/parameter_seperator.js | 102 --------------- test/options/signature_method.js | 36 ------ test/services/bitbucket.js | 76 ------------ test/services/flickr.js | 184 ---------------------------- test/services/linkedin.js | 50 -------- test/services/openbank.js | 49 -------- test/services/twitter.js | 179 --------------------------- test/twitter_sample_data.js | 94 -------------- 18 files changed, 1 insertion(+), 1023 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile rename oauth-1.0a.js => oauth.js (100%) delete mode 100644 package.json delete mode 100644 test/README.md delete mode 100644 test/getParameterString.js delete mode 100644 test/options/consumer.js delete mode 100644 test/options/last_ampersand.js delete mode 100644 test/options/multiple_values.js delete mode 100644 test/options/nonce_length.js delete mode 100644 test/options/parameter_seperator.js delete mode 100644 test/options/signature_method.js delete mode 100644 test/services/bitbucket.js delete mode 100644 test/services/flickr.js delete mode 100644 test/services/linkedin.js delete mode 100644 test/services/openbank.js delete mode 100644 test/services/twitter.js delete mode 100644 test/twitter_sample_data.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 21bdcc8..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -test: - mocha --recursive --reporter spec --slow 1 - -coveralls: - istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec --recursive && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage - -.PHONY: test \ No newline at end of file diff --git a/oauth-1.0a.js b/oauth.js similarity index 100% rename from oauth-1.0a.js rename to oauth.js diff --git a/package.json b/package.json deleted file mode 100644 index 2a16af9..0000000 --- a/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "oauth-1.0a", - "version": "2.0.0", - "description": "OAuth 1.0a Request Authorization for Node and Browser.", - "scripts": { - "test": "make test" - }, - "main": "oauth-1.0a.js", - "repository": "https://github.com/ddo/oauth-1.0a.git", - "keywords": [ - "oauth", - "1.0a", - "oauth1.0a", - "authorize", - "signature", - "nonce", - "consumer" - ], - "author": "Ddo", - "license": "MIT", - "devDependencies": { - "mocha": "~1.17.0", - "chai": "~1.8.1", - "request": "~2.33.0", - "istanbul": "^0.2.7", - "coveralls": "^2.10.0" - } -} diff --git a/test/README.md b/test/README.md deleted file mode 100644 index c8b63b2..0000000 --- a/test/README.md +++ /dev/null @@ -1,34 +0,0 @@ -##Core testing - -``twitter_sample_data.js`` - -##Services - -* Twitter -* Flickr -* Linkedin -* Bitbucket -* Openbankproject - -##Setup - -Please these define Node environment variables: - -* ``TWITTER_CONSUMER_PUBLIC`` -* ``TWITTER_CONSUMER_SECRET`` -* ``TWITTER_TOKEN_PUBLIC`` -* ``TWITTER_TOKEN_SECRET`` -* ``FLICKR_CONSUMER_PUBLIC`` -* ``FLICKR_CONSUMER_SECRET`` -* ``FLICKR_TOKEN_PUBLIC`` -* ``FLICKR_SECRET_SECRET`` -* ``LINKEDIN_CONSUMER_PUBLIC`` -* ``LINKEDIN_CONSUMER_SECRET`` -* ``BITBUCKET_CONSUMER_PUBLIC`` -* ``BITBUCKET_CONSUMER_SECRET`` -* ``OPENBANK_CONSUMER_PUBLIC`` -* ``OPENBANK_CONSUMER_SECRET`` - -##Run test - -``make test`` \ No newline at end of file diff --git a/test/getParameterString.js b/test/getParameterString.js deleted file mode 100644 index 9fd28f4..0000000 --- a/test/getParameterString.js +++ /dev/null @@ -1,21 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../oauth-1.0a'); -var crypto = require('crypto'); - -describe("#getParameterString", function() { - var oauth = new OAuth({ - consumer: {}, - }); - - var request = { - url: 'https://api.twitter.com/1/statuses/update.json?&', - }; - - var oauth_data = {}; - - describe("#getParameterStringEmptyGetParam", function() { - it("should be equal to Twitter example", function() { - expect(oauth.getParameterString(request, oauth_data)).to.equal('='); - }); - }); -}); \ No newline at end of file diff --git a/test/options/consumer.js b/test/options/consumer.js deleted file mode 100644 index 6ee5406..0000000 --- a/test/options/consumer.js +++ /dev/null @@ -1,14 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../../oauth-1.0a'); - -//TODO: check alphabet and numberic only - -describe("consumer option", function() { - describe("required option", function() { - it("should throw error on undefined", function() { - expect(function() { - oauth = OAuth(); - }).to.throw('consumer option is required'); - }); - }); -}); \ No newline at end of file diff --git a/test/options/last_ampersand.js b/test/options/last_ampersand.js deleted file mode 100644 index 13b092e..0000000 --- a/test/options/last_ampersand.js +++ /dev/null @@ -1,55 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -function hash_function_SHA1(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); -} - -describe("last_ampersand option", function() { - - describe("default (true)", function() { - var oauth = OAuth({ - consumer: { - secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw' - }, - signature_method: 'HMAC-SHA1', - hash_function: hash_function_SHA1 - }); - - var token = { - secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE' - }; - - it("should be equal to Twitter example", function() { - expect(oauth.getSigningKey(token.secret)).to.equal('kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'); - }); - - it("should has the ampersand at the end", function() { - expect(oauth.getSigningKey()).to.equal('kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&'); - }); - }); - - describe("change to false", function() { - var oauth = OAuth({ - consumer: { - secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw' - }, - signature_method: 'HMAC-SHA1', - hash_function: hash_function_SHA1, - last_ampersand: false - }); - - var token = { - secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE' - }; - - it("should be equal to Twitter example", function() { - expect(oauth.getSigningKey(token.secret)).to.equal('kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'); - }); - - it("should not has the ampersand at the end", function() { - expect(oauth.getSigningKey()).to.equal('kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw'); - }); - }); -}); \ No newline at end of file diff --git a/test/options/multiple_values.js b/test/options/multiple_values.js deleted file mode 100644 index 4237b69..0000000 --- a/test/options/multiple_values.js +++ /dev/null @@ -1,54 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -function hash_function_SHA1(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); -} - -describe("Signature method", function() { - describe("HMAC-SHA1 signature method with multiple values", function() { - var oauth = new OAuth({ - consumer: { - key: "batch-dbc2cd8c-6ca8-463b-96e2-6d8683eac6fd", - secret: "4S4Rvm25CJZWv7HBg5HOhhlRTBSZ7npl" - }, - signature_method: 'HMAC-SHA1', - hash_function: hash_function_SHA1 - }); - - //overide for testing only !!! - oauth.getTimeStamp = function() { - return 1445951836; - }; - - //overide for testing only !!! - oauth.getNonce = function(length) { - return 'tKOQtKan8PHIrIoOlrl17zHkZQ2H5CsP'; - }; - - - var request_data = { - url: "http://localhost:3737/rest/profiles/1ea2a42f-e14d-4057-8bcd-3e0b4514a267/properties?alt=json", - method: "PUT", - data: { - currentbrowserversion: [ '1', '5', 'dfadfadfa' ], - alt: 'json' - } - }; - - var result = oauth.authorize(request_data); - - it("Signature should match", function() { - expect(result.oauth_signature).to.equal("ri0lfv4udd2uQmkg5cCPVqLruyk="); - }); - - it("Nonce should match", function() { - expect(result.oauth_nonce).to.equal("tKOQtKan8PHIrIoOlrl17zHkZQ2H5CsP"); - }); - - it("Timestamp should match", function() { - expect(result.oauth_timestamp).to.equal(1445951836); - }); - }); -}); \ No newline at end of file diff --git a/test/options/nonce_length.js b/test/options/nonce_length.js deleted file mode 100644 index 3c9bdae..0000000 --- a/test/options/nonce_length.js +++ /dev/null @@ -1,40 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../../oauth-1.0a'); - -//TODO: check alphabet and numberic only - -describe("nonce_length option", function() { - describe("default (32)", function() { - var oauth = OAuth({ - consumer: {} - }); - - it("nonce length should be 32", function() { - expect(oauth.getNonce().length).to.equal(32); - }); - }); - - describe("length 100", function() { - var oauth = OAuth({ - consumer: {}, - nonce_length: 100 - }); - - it("nonce length should be 100", function() { - expect(oauth.getNonce().length).to.equal(100); - }); - }); - - describe("random length", function() { - var random = parseInt(Math.random()*100, 10); - - var oauth = new OAuth({ - consumer: {}, - nonce_length: random - }); - - it("nonce length should be correct", function() { - expect(oauth.getNonce().length).to.equal(random); - }); - }); -}); \ No newline at end of file diff --git a/test/options/parameter_seperator.js b/test/options/parameter_seperator.js deleted file mode 100644 index ac9aa69..0000000 --- a/test/options/parameter_seperator.js +++ /dev/null @@ -1,102 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -function hash_function_SHA1(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); -} - -describe("parameter_seperator option", function() { - describe("default (', ')", function() { - var oauth = OAuth({ - consumer: { - key: 'xvz1evFS4wEEPTGEFPHBog', - secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw' - }, - signature_method: 'HMAC-SHA1', - hash_function: hash_function_SHA1 - }); - - //overide for testing only !!! - oauth.getTimeStamp = function() { - return 1318622958; - }; - - //overide for testing only !!! - oauth.getNonce = function(length) { - return 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg'; - }; - - var token = { - key: '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb', - secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE' - }; - - var request = { - url: 'https://api.twitter.com/1/statuses/update.json?include_entities=true', - method: 'POST', - data: { - status: 'Hello Ladies + Gentlemen, a signed OAuth request!' - } - }; - - it("should be equal to Twitter example", function() { - expect(oauth.toHeader(oauth.authorize(request, token))).to.have.property('Authorization', 'OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318622958", oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", oauth_version="1.0"'); - }); - }); - - describe("-", function() { - var oauth = OAuth({ - consumer: { - key: 'xvz1evFS4wEEPTGEFPHBog', - secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw' - }, - signature_method: 'HMAC-SHA1', - hash_function: hash_function_SHA1, - parameter_seperator: '-' - }); - - //overide for testing only !!! - oauth.getTimeStamp = function() { - return 1318622958; - }; - - //overide for testing only !!! - oauth.getNonce = function(length) { - return 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg'; - }; - - var token = { - key: '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb', - secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE' - }; - - var request = { - url: 'https://api.twitter.com/1/statuses/update.json?include_entities=true', - method: 'POST', - data: { - status: 'Hello Ladies + Gentlemen, a signed OAuth request!' - } - }; - - it("header should be correct", function() { - expect(oauth.toHeader(oauth.authorize(request, token))).to.have.property('Authorization', 'OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog"-oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg"-oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D"-oauth_signature_method="HMAC-SHA1"-oauth_timestamp="1318622958"-oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"-oauth_version="1.0"'); - }); - }); -}); - -function generateTest(options) { - var oauth = new OAuth(options); - - //overide for testing only !!! - oauth.getTimeStamp = function() { - return 1318622958; - }; - - //overide for testing only !!! - oauth.getNonce = function(length) { - return 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg'; - }; - - return oauth; -} \ No newline at end of file diff --git a/test/options/signature_method.js b/test/options/signature_method.js deleted file mode 100644 index 19492f2..0000000 --- a/test/options/signature_method.js +++ /dev/null @@ -1,36 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../../oauth-1.0a'); - -describe("Signature method", function() { - describe("default PLAINTEXT signature method", function() { - var oauth = new OAuth({ - consumer: {} - }); - - it("hash should be return key only", function() { - expect(oauth.signature_method).to.equal('PLAINTEXT'); - }); - }); - - describe("default PLAINTEXT hash function", function() { - var oauth = new OAuth({ - consumer: {}, - signature_method: 'PLAINTEXT' - }); - - it("hash should be return key only", function() { - expect(oauth.hash_function('base_string', 'key')).to.equal('key'); - }); - }); - - describe("missing hash function", function() { - it("constructor should throw a error", function() { - expect(function() { - OAuth({ - consumer: {}, - signature_method: 'RSA-SHA1', - }); - }).to.throw('hash_function option is required'); - }); - }); -}); \ No newline at end of file diff --git a/test/services/bitbucket.js b/test/services/bitbucket.js deleted file mode 100644 index 5c0240a..0000000 --- a/test/services/bitbucket.js +++ /dev/null @@ -1,76 +0,0 @@ -var expect = require('chai').expect; -var Request = require('request'); -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -describe("Bitbucket Personal Consumer", function() { - this.timeout(10000); - - var oauth = new OAuth({ - consumer: { - key: process.env.BITBUCKET_CONSUMER_PUBLIC, - secret: process.env.BITBUCKET_CONSUMER_SECRET - }, - signature_method: 'HMAC-SHA1', - hash_function: function(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); - } - }); - - describe("#Request Token", function() { - var request = { - url: 'https://bitbucket.org/api/1.0/oauth/request_token', - method: 'POST', - data: { - oauth_callback: 'http://www.ddo.me' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: oauth.authorize(request) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('oauth_callback_confirmed', 'true'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - done(); - }); - }); - }); - - describe("#Request Token by Header", function() { - var request = { - url: 'https://bitbucket.org/api/1.0/oauth/request_token', - method: 'POST', - data: { - oauth_callback: 'http://www.ddo.me' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: request.data, - headers: oauth.toHeader(oauth.authorize(request)) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('oauth_callback_confirmed', 'true'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - done(); - }); - }); - }); -}); \ No newline at end of file diff --git a/test/services/flickr.js b/test/services/flickr.js deleted file mode 100644 index ddb8901..0000000 --- a/test/services/flickr.js +++ /dev/null @@ -1,184 +0,0 @@ -var expect = require('chai').expect; -var Request = require('request'); -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -describe("Flickr Personal Consumer", function() { - this.timeout(10000); - - var oauth = new OAuth({ - consumer: { - key: process.env.FLICKR_CONSUMER_key, - secret: process.env.FLICKR_CONSUMER_SECRET - }, - signature_method: 'HMAC-SHA1', - hash_function: function(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); - } - }); - - describe.skip("#Request Token", function() { - var request = { - url: 'http://www.flickr.com/services/oauth/request_token', - method: 'POST', - data: { - oauth_callback: 'http://www.ddo.me' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: oauth.authorize(request) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('oauth_callback_confirmed', 'true'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - done(); - }); - }); - }); - - describe.skip("#Request Token by Header", function() { - var request = { - url: 'http://www.flickr.com/services/oauth/request_token', - method: 'POST', - data: { - oauth_callback: 'http://www.ddo.me' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: request.data, - headers: oauth.toHeader(oauth.authorize(request)) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('oauth_callback_confirmed', 'true'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - console.log(body); - console.log('http://www.flickr.com/services/oauth/authorize?oauth_token=' + token.key); - - done(); - }); - }); - }); - - /* - Need to get token from Request Token - And oauth_verifier after pass authorize on website - */ - describe.skip("#Access Token", function() { - //this token get from Request Token - var token = { - key: 'get from Request Token', - secret: 'get from Request Token' - }; - - var request = { - url: 'http://www.flickr.com/services/oauth/access_token', - method: 'POST', - data: { - oauth_verifier: 'get from Request Token' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: oauth.authorize(request, token) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('fullname'); - expect(body).to.have.property('user_nsid'); - expect(body).to.have.property('username'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - token.key = body.oauth_token; - token.secret = body.oauth_token_secret; - - done(); - }); - }); - }); - - /* - Need to get token from Access Token - */ - describe("#flickr.test.login", function() { - var token = { - key: process.env.FLICKR_TOKEN_PUBLIC, - secret: process.env.FLICKR_SECRET_SECRET - }; - - var request = { - url: 'http://api.flickr.com/services/rest/?method=flickr.test.login', - method: 'GET', - data: { - api_key: token.key, - format: 'json' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - qs: oauth.authorize(request, token) - }, function(err, res, body) { - expect(body).to.be.a('string'); - expect(body).to.have.string('jsonFlickrApi'); - done(); - }); - }); - }); - - /* - Need to get token from Access Token - */ - describe("#flickr.test.null", function() { - var token = { - key: process.env.FLICKR_TOKEN_PUBLIC, - secret: process.env.FLICKR_SECRET_SECRET - }; - - var request = { - url: 'http://api.flickr.com/services/rest/?method=flickr.test.null', - method: 'GET', - data: { - api_key: token.key, - format: 'json' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - qs: oauth.authorize(request, token) - }, function(err, res, body) { - expect(body).to.be.a('string'); - expect(body).to.have.string('jsonFlickrApi'); - done(); - }); - }); - }); -}); \ No newline at end of file diff --git a/test/services/linkedin.js b/test/services/linkedin.js deleted file mode 100644 index 1719973..0000000 --- a/test/services/linkedin.js +++ /dev/null @@ -1,50 +0,0 @@ -var expect = require('chai').expect; -var Request = require('request'); -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -/* - Can not use Header -*/ -describe("Linkedin Personal Consumer", function() { - this.timeout(10000); - - var oauth = new OAuth({ - consumer: { - key: process.env.LINKEDIN_CONSUMER_PUBLIC, - secret: process.env.LINKEDIN_CONSUMER_SECRET - }, - signature_method: 'HMAC-SHA1', - hash_function: function(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); - } - }); - - describe("#Request Token", function() { - var request = { - url: 'https://api.linkedin.com/uas/oauth/requestToken', - method: 'POST', - data: { - oauth_callback: 'http://www.ddo.me' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: oauth.authorize(request) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('oauth_callback_confirmed', 'true'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - done(); - }); - }); - }); -}); \ No newline at end of file diff --git a/test/services/openbank.js b/test/services/openbank.js deleted file mode 100644 index 5abba02..0000000 --- a/test/services/openbank.js +++ /dev/null @@ -1,49 +0,0 @@ -var expect = require('chai').expect; -var Request = require('request'); -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -describe("Openbank Personal Consumer", function() { - this.timeout(10000); - - var oauth = new OAuth({ - consumer: { - key: process.env.OPENBANK_CONSUMER_PUBLIC, - secret: process.env.OPENBANK_CONSUMER_SECRET - }, - signature_method: 'HMAC-SHA256', - hash_function: function(base_string, key) { - return crypto.createHmac('sha256', key).update(base_string).digest('base64'); - } - }); - - //need to send as header - describe("#Request Token", function() { - var request = { - url: 'https://apisandbox.openbankproject.com/oauth/initiate', - method: 'POST', - data: { - oauth_callback: 'http://www.ddo.me' - } - }; - - it("should be a valid response", function(done) { - Request({ - url: request.url, - method: request.method, - form: request.data, - headers: oauth.toHeader(oauth.authorize(request)) - }, function(err, res, body) { - expect(body).to.be.a('string'); - - body = oauth.deParam(body); - - expect(body).to.have.property('oauth_callback_confirmed', 'true'); - expect(body).to.have.property('oauth_token'); - expect(body).to.have.property('oauth_token_secret'); - - done(); - }); - }); - }); -}); \ No newline at end of file diff --git a/test/services/twitter.js b/test/services/twitter.js deleted file mode 100644 index d799fb7..0000000 --- a/test/services/twitter.js +++ /dev/null @@ -1,179 +0,0 @@ -var expect = require('chai').expect; -var Request = require('request'); -var OAuth = require('../../oauth-1.0a'); -var crypto = require('crypto'); - -describe("Twitter Personal Consumer", function() { - var oauth = new OAuth({ - consumer: { - key: process.env.TWITTER_CONSUMER_PUBLIC, - secret: process.env.TWITTER_CONSUMER_SECRET - }, - signature_method: 'HMAC-SHA1', - hash_function: function(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); - } - }); - - var token = { - key: process.env.TWITTER_TOKEN_PUBLIC, - secret: process.env.TWITTER_TOKEN_SECRET - }; - - describe("#Get user timeline", function() { - this.timeout(10000); - - var request = { - url: 'https://api.twitter.com/1.1/statuses/user_timeline.json', - method: 'GET' - }; - - it("should be an array of tweets", function(done) { - Request({ - url: request.url, - method: request.method, - qs: oauth.authorize(request, token), - json: true - }, function(err, res, body) { - expect(err).to.be.a('null'); - expect(body).to.be.an.instanceof(Array); - done(); - }); - }); - }); - - describe("#Get user timeline limit 5", function() { - this.timeout(10000); - - var request = { - url: 'https://api.twitter.com/1.1/statuses/user_timeline.json', - method: 'GET', - data: { - count: 5 - } - }; - - it("should be an array of tweets (length 5)", function(done) { - Request({ - url: request.url, - method: request.method, - qs: oauth.authorize(request, token), - json: true - }, function(err, res, body) { - expect(err).to.be.a('null'); - expect(body).to.be.an.instanceof(Array); - expect(body).to.have.length(5); - done(); - }); - }); - }); - - describe("#Get user timeline limit 5 by url", function() { - this.timeout(10000); - - var request = { - url: 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=5', - method: 'GET' - }; - - it("should be an array of tweets", function(done) { - Request({ - url: request.url, - method: request.method, - qs: oauth.authorize(request, token), - json: true - }, function(err, res, body) { - expect(err).to.be.a('null'); - expect(body).to.be.an.instanceof(Array); - expect(body).to.have.length(5); - done(); - }); - }); - }); - - describe("#Get user timeline by header", function() { - this.timeout(10000); - - var request = { - url: 'https://api.twitter.com/1.1/statuses/user_timeline.json', - method: 'GET' - }; - - it("should be an array of tweets", function(done) { - Request({ - url: request.url, - method: request.method, - qs: request.data, - headers: oauth.toHeader(oauth.authorize(request, token)), - json: true - }, function(err, res, body) { - expect(err).to.be.a('null'); - expect(body).to.be.an.instanceof(Array); - done(); - }); - }); - }); - - describe.skip("#Tweet", function() { - this.timeout(10000); - - var text = 'Testing oauth-1.0a'; - - var request = { - url: 'https://api.twitter.com/1.1/statuses/update.json', - method: 'POST', - data: { - status: text - } - }; - - it("should be an success object", function(done) { - Request({ - url: request.url, - method: request.method, - form: oauth.authorize(request, token), - json: true - }, function(err, res, body) { - expect(body).to.have.property('entities'); - expect(body).to.have.property('created_at'); - expect(body).to.have.property('id'); - expect(body).to.have.property('text'); - expect(body.text).to.equal(text); - expect(body.user).to.be.an('object'); - done(); - }); - }); - }); - - describe.skip("#Tweet by header", function() { - this.timeout(10000); - - var text = 'Testing oauth-1.0a'; - - var request = { - url: 'https://api.twitter.com/1.1/statuses/update.json', - method: 'POST', - data: { - status: text - } - }; - - it("should be an success object", function(done) { - Request({ - url: request.url, - method: request.method, - form: request.data, - headers: oauth.toHeader(oauth.authorize(request, token)), - json: true - }, function(err, res, body) { - expect(body).to.have.property('entities'); - expect(body).to.have.property('created_at'); - expect(body).to.have.property('id'); - expect(body).to.have.property('text'); - expect(body.text).to.equal(text); - expect(body.user).to.be.an('object'); - done(); - }); - }); - }); -}); \ No newline at end of file diff --git a/test/twitter_sample_data.js b/test/twitter_sample_data.js deleted file mode 100644 index c41abe5..0000000 --- a/test/twitter_sample_data.js +++ /dev/null @@ -1,94 +0,0 @@ -var expect = require('chai').expect; -var OAuth = require('../oauth-1.0a'); -var crypto = require('crypto'); - -describe("Twitter Sample", function() { - var oauth = new OAuth({ - consumer: { - key: 'xvz1evFS4wEEPTGEFPHBog', - secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw' - }, - signature_method: 'HMAC-SHA1', - hash_function: function(base_string, key) { - return crypto.createHmac('sha1', key).update(base_string).digest('base64'); - } - }); - - //overide for testing only !!! - oauth.getTimeStamp = function() { - return 1318622958; - }; - - //overide for testing only !!! - oauth.getNonce = function(length) { - return 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg'; - }; - - var token = { - key: '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb', - secret: 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE' - }; - - var request = { - url: 'https://api.twitter.com/1/statuses/update.json?include_entities=true', - method: 'POST', - data: { - status: 'Hello Ladies + Gentlemen, a signed OAuth request!' - } - }; - - var oauth_data = { - oauth_consumer_key: oauth.consumer.key, - oauth_nonce: oauth.getNonce(), - oauth_signature_method: oauth.signature_method, - oauth_timestamp: oauth.getTimeStamp(), - oauth_version: '1.0', - oauth_token: token.key - }; - - describe("#getParameterString", function() { - it("should be equal to Twitter example", function() { - expect(oauth.getParameterString(request, oauth_data)).to.equal('include_entities=true&oauth_consumer_key=xvz1evFS4wEEPTGEFPHBog&oauth_nonce=kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1318622958&oauth_token=370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb&oauth_version=1.0&status=Hello%20Ladies%20%2B%20Gentlemen%2C%20a%20signed%20OAuth%20request%21'); - }); - }); - - describe("#getBaseString", function() { - it("should be equal to Twitter example", function() { - expect(oauth.getBaseString(request, oauth_data)).to.equal('POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521'); - }); - }); - - describe("#getSigningKey", function() { - it("should be equal to Twitter example", function() { - expect(oauth.getSigningKey(token.secret)).to.equal('kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'); - }); - }); - - describe("#getSignature", function() { - it("should be equal to Twitter example", function() { - expect(oauth.getSignature(request, token.secret, oauth_data)).to.equal('tnnArxj06cWHq44gCs1OSKk/jLY='); - }); - }); - - describe("#authorize", function() { - it("should be equal to Twitter example", function() { - expect(oauth.authorize(request, token)).to.eql({ - oauth_consumer_key: 'xvz1evFS4wEEPTGEFPHBog', - oauth_nonce: 'kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg', - oauth_signature_method: 'HMAC-SHA1', - oauth_timestamp: 1318622958, - oauth_version: '1.0', - oauth_token: '370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb', - status: 'Hello Ladies + Gentlemen, a signed OAuth request!', - include_entities: 'true', - oauth_signature: 'tnnArxj06cWHq44gCs1OSKk/jLY=' - }); - }); - }); - - describe("#toHeader", function() { - it("should be equal to Twitter example", function() { - expect(oauth.toHeader(oauth.authorize(request, token))).to.have.property('Authorization', 'OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318622958", oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", oauth_version="1.0"'); - }); - }); -}); \ No newline at end of file