hard to do oauth units, possibly move to acceptance fully

This commit is contained in:
Simon Tokumine 2012-06-01 21:00:45 +01:00
parent a062721cc6
commit 92660caea4
2 changed files with 48 additions and 49 deletions

View File

@ -1,12 +1,16 @@
#!/bin/sh
# this script prepare database and redis instance to run accpetance test
echo "preparing redis..."
echo "HSET rails:users:vizzuality id 1" | redis-cli -n 5
echo "HSET rails:users:vizzuality database_name cartodb_test_user_1_db" | redis-cli -n 5
echo "SADD rails:users:vizzuality:map_key 1234" | redis-cli -n 5
echo "hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR consumer_key fZeNGv5iYayvItgDYHUbot1Ukb5rVyX6QAg8GaY2" | redis-cli -n 5
echo "hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR consumer_secret IBLCvPEefxbIiGZhGlakYV4eM8AbVSwsHxwEYpzx" | redis-cli -n 5
echo "hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR access_token_token l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR" | redis-cli -n 5
echo "hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR access_token_secret 22zBIek567fMDEebzfnSdGe8peMFVFqAreOENaDK" | redis-cli -n 5
echo "hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR user_id 1" | redis-cli -n 5
echo "hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR time sometime" | redis-cli -n 5
echo "preparing postgres..."
@ -14,6 +18,7 @@ dropdb -Upostgres -hlocalhost cartodb_test_user_1_db
createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 cartodb_test_user_1_db
psql -Upostgres -hlocalhost cartodb_test_user_1_db < test.sql
echo "ok, you can run test now"

View File

@ -48,18 +48,10 @@ tests['test headers take presedence over query parameters'] = function(){
};
// before this, you must embed the test OAUTH hash in redis so everything works.
// Request url: http://vizzuality.testhost.lan/api/v1/tables
// hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR consumer_key fZeNGv5iYayvItgDYHUbot1Ukb5rVyX6QAg8GaY2
// hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR consumer_secret IBLCvPEefxbIiGZhGlakYV4eM8AbVSwsHxwEYpzx
// hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR access_token_token l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR
// hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR access_token_secret 22zBIek567fMDEebzfnSdGe8peMFVFqAreOENaDK
// hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR user_id 1
// hset rails:oauth_access_tokens:l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR time sometime
//the headers for this are:
var real_oauth_header = 'OAuth realm="http://vizzuality.testhost.lan/",oauth_consumer_key="fZeNGv5iYayvItgDYHUbot1Ukb5rVyX6QAg8GaY2",oauth_token="l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR",oauth_signature_method="HMAC-SHA1", oauth_signature="o4hx4hWP6KtLyFwggnYB4yPK8xI%3D",oauth_timestamp="1313581372",oauth_nonce="W0zUmvyC4eVL8cBd4YwlH1nnPTbxW0QBYcWkXTwe4",oauth_version="1.0"';
////the headers for this are:
//var real_oauth_header = 'OAuth realm="http://vizzuality.testhost.lan/",oauth_consumer_key="fZeNGv5iYayvItgDYHUbot1Ukb5rVyX6QAg8GaY2",oauth_token="l0lPbtP68ao8NfStCiA3V3neqfM03JKhToxhUQTR",oauth_signature_method="HMAC-SHA1", oauth_signature="o4hx4hWP6KtLyFwggnYB4yPK8xI%3D",oauth_timestamp="1313581372",oauth_nonce="W0zUmvyC4eVL8cBd4YwlH1nnPTbxW0QBYcWkXTwe4",oauth_version="1.0"';
//
//TODO FIX
//tests['test can access oauth hash for a user based on access token (oauth_token)'] = function(){
// var req = {query:{}, headers:{authorization:real_oauth_header}};
// var tokens = oAuth.parseTokens(req);
@ -68,16 +60,17 @@ tests['test headers take presedence over query parameters'] = function(){
// assert.equal(tokens.oauth_consumer_key, data.consumer_key)
// });
//};
//
//tests['test non existant oauth hash for a user based on oauth_token returns empty hash'] = function(){
// var req = {query:{}, headers:{authorization:full_oauth_header}};
// var tokens = oAuth.parseTokens(req);
//
// oAuth.getOAuthHash(tokens.oauth_token, function(err, data){
// assert.eql(data, {})
// });
//};
//
tests['test non existant oauth hash for a user based on oauth_token returns empty hash'] = function(){
var req = {query:{}, headers:{authorization:full_oauth_header}};
var tokens = oAuth.parseTokens(req);
oAuth.getOAuthHash(tokens.oauth_token, function(err, data){
assert.eql(data, {})
});
};
//TODO FIX
//tests['can return user for verified signature'] = function(){
// var req = {query:{},
// headers:{authorization:real_oauth_header, host: 'vizzuality.testhost.lan' },
@ -86,32 +79,33 @@ tests['test headers take presedence over query parameters'] = function(){
// };
//
// oAuth.verifyRequest(req, function(err, data){
//
// assert.eql(data, 1);
// }, true)
//};
//
//tests['returns null user for unverified signatures'] = function(){
// var req = {query:{},
// headers:{authorization:real_oauth_header, host: 'vizzuality.testyhost.lan' },
// method: 'GET',
// route: {path: '/api/v1/tables'}
// };
//
// oAuth.verifyRequest(req, function(err, data){
// assert.eql(data, null);
// }, true)
//};
//
//tests['returns null user for no oauth'] = function(){
// var req = {
// query:{},
// headers:{},
// method: 'GET',
// route: {path: '/api/v1/tables'}
// };
//
// oAuth.verifyRequest(req,function(err,data){
// assert.eql(data, null);
// });
//};
//
tests['returns null user for unverified signatures'] = function(){
var req = {query:{},
headers:{authorization:real_oauth_header, host: 'vizzuality.testyhost.lan' },
method: 'GET',
route: {path: '/api/v1/tables'}
};
oAuth.verifyRequest(req, function(err, data){
assert.eql(data, null);
}, true)
};
tests['returns null user for no oauth'] = function(){
var req = {
query:{},
headers:{},
method: 'GET',
route: {path: '/api/v1/tables'}
};
oAuth.verifyRequest(req,function(err,data){
assert.eql(data, null);
});
};