coauth-sdk
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "coauth-sdk", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "sdk.js", |
39
sdk.js
@@ -48,2 +48,11 @@ | ||
}, | ||
user: function(uuid) { | ||
return User(uuid, this); | ||
}, | ||
session: function(uuid) { | ||
return Session(uuid, undefined, this); | ||
}, | ||
token: function(uuid) { | ||
return Token(uuid, this); | ||
}, | ||
deleteUser: function(user_id) { | ||
@@ -59,16 +68,2 @@ var self = this; | ||
}); | ||
}, | ||
session: function(uuid) { | ||
var self = this; | ||
return new Promise(function(f,r) { | ||
self.coauth.API('/sessions/'+uuid).then(function(resp) { | ||
if (resp.data.error) | ||
r(resp.data); | ||
else | ||
f( User(resp.data.user_id, self) ); | ||
}, r); | ||
}); | ||
}, | ||
token: function(uuid) { | ||
return Token(uuid, this); | ||
} | ||
@@ -146,2 +141,18 @@ } | ||
Session.prototype = { | ||
user: function(fn, r) { | ||
if (this.User !== undefined) { | ||
fn(this.User); | ||
return Promise.resolve(); | ||
} | ||
var self = this; | ||
return this.API('').then(function(resp) { | ||
if (resp.data.error) | ||
r(resp.data); | ||
else { | ||
self.User = User(resp.data.user_id, self); | ||
fn( self.User ); | ||
} | ||
}, r); | ||
}, | ||
close: function() { | ||
@@ -148,0 +159,0 @@ var self = this; |
210
tests.js
@@ -20,3 +20,3 @@ | ||
fn(f, r, d); | ||
}); | ||
}).catch(e); | ||
} | ||
@@ -44,3 +44,3 @@ } | ||
// var $session = coauth.session(session_id); | ||
// $session.then(function($user) { | ||
// $session.user(function($user) { | ||
// | ||
@@ -55,97 +55,119 @@ // }); | ||
var coauth = coauthSDK.v1( "http://localhost:2884", | ||
"502fbc82-6bfc-4e47-ad36-a8c23ee7b130" ); | ||
var password = "testing"; | ||
var newPassword = "testing1"; | ||
Promise.sequence([ | ||
test(function(f,r) { | ||
log.debug("Create user"); | ||
coauth.create(password).then(function($user) { | ||
log.info("User ID:", $user.id ); | ||
assert( Py.type($user.id) === 'String' ); | ||
var server = require('../server/server.js'); | ||
var port = 8000; | ||
server.init(port, function(apikey) { | ||
var url = "http://localhost:"+port; | ||
var coauth = coauthSDK.v1( url, apikey ); | ||
var password = "testing"; | ||
var newPassword = "testing1"; | ||
Promise.sequence([ | ||
test(function(f,r) { | ||
log.debug("Create user"); | ||
coauth.create(password).then(function($user) { | ||
log.info("User ID:", $user.id ); | ||
assert( Py.type($user.id) === 'String' ); | ||
Promise.sequence([ | ||
test(function(f,r) { | ||
log.debug("Create session"); | ||
$user.session(password).then(function($session) { | ||
log.info("Session ID:", $session.id ); | ||
assert( Py.type($session.id) === 'String' ); | ||
assert( $session.User.id === $user.id ); | ||
f($session); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Close session"); | ||
$session.close().then(function(status) { | ||
assert( status === true ); | ||
log.info("Closed Session", $session.id, status) | ||
f($session); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Delete session"); | ||
$session.del().then(function(status) { | ||
assert( status === true ); | ||
log.info("Deleted Session", $session.id, status) | ||
f(); | ||
}, e).catch(e); | ||
}), | ||
test(function() { | ||
f($user); | ||
}) | ||
]); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$user) { | ||
log.debug("Update user"); | ||
$user.update(newPassword).then(function() { | ||
log.info("Updated User", $user.id); | ||
Promise.sequence([ | ||
test(function(f,r) { | ||
log.debug("Create session"); | ||
$user.session(password).then(function($session) { | ||
log.info("Session ID:", $session.id ); | ||
assert( Py.type($session.id) === 'String' ); | ||
assert( $session.User.id === $user.id ); | ||
f($session); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Close session"); | ||
$session.close().then(function(status) { | ||
assert( status === true ); | ||
log.info("Closed Session", $session.id, status) | ||
f($session); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Delete session"); | ||
$session.del().then(function(status) { | ||
assert( status === true ); | ||
log.info("Deleted Session", $session.id, status) | ||
f(); | ||
}, e).catch(e); | ||
}), | ||
test(function() { | ||
f($user); | ||
}) | ||
]); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$user) { | ||
log.debug("Update user"); | ||
$user.update(newPassword).then(function() { | ||
log.info("Updated User", $user.id); | ||
Promise.sequence([ | ||
test(function(f,r) { | ||
log.debug("Create session"); | ||
$user.session(newPassword).then(function($session) { | ||
log.info("Session ID:", $session.id ); | ||
assert( Py.type($session.id) === 'String' ); | ||
assert( $session.User.id === $user.id ); | ||
f($session); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Delete session"); | ||
Promise.sequence([ | ||
test(function(f,r) { | ||
log.debug("Create session"); | ||
$user.session(newPassword).then(function($session) { | ||
log.info("Session ID:", $session.id ); | ||
assert( Py.type($session.id) === 'String' ); | ||
assert( $session.User.id === $user.id ); | ||
f($session); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Create session from session.id"); | ||
var $sess = coauth.session($session.id); | ||
$sess.user(function($user) { | ||
log.debug("Get previous user to compare") | ||
$session.user(function($u) { | ||
assert( $user.id === $u.id ); | ||
f($session); | ||
}, e).catch(e); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$session) { | ||
log.debug("Delete session"); | ||
$session.del().then(function(status) { | ||
assert( status === true ); | ||
log.info("Deleted Session", $session.id, status) | ||
f(); | ||
}, e).catch(e); | ||
}), | ||
test(function() { | ||
f($user); | ||
}) | ||
]); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$user) { | ||
log.debug("Create token"); | ||
Testing.api(url+'/v1/coauth/tokens/create', { | ||
body: { | ||
user_id: $user.id, | ||
password: newPassword | ||
}, | ||
json: true | ||
}).then(function(resp) { | ||
log.debug("Use token", resp.data.token); | ||
var $token = coauth.token(resp.data.token); | ||
$token.use(function($session) { | ||
assert( $session.User.id === $user.id ); | ||
$session.del().then(function(status) { | ||
assert( status === true ); | ||
log.info("Deleted Session", $session.id, status) | ||
f(); | ||
}, e).catch(e); | ||
}), | ||
test(function() { | ||
f($user); | ||
}) | ||
]); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$user) { | ||
log.debug("Create token"); | ||
Testing.api('http://localhost:2884/v1/coauth/tokens/create', { | ||
body: { | ||
user_id: $user.id, | ||
password: newPassword | ||
}, | ||
json: true | ||
}).then(function(resp) { | ||
log.debug("Use token", resp.data.token); | ||
coauth.token(resp.data.token).use(function($session) { | ||
assert( $session.User.id === $user.id ); | ||
f($user); | ||
f($user); | ||
}); | ||
}, e).catch(e); | ||
}, e).catch(e); | ||
}, e).catch(e); | ||
}), | ||
test(function(f,r,$user) { | ||
log.debug("Delete user"); | ||
coauth.deleteUser($user.id).then(function(status) { | ||
assert( status === true ); | ||
log.info("Deleted User", $user.id, status); | ||
}, e).catch(e); | ||
}) | ||
]); | ||
}), | ||
test(function(f,r,$user) { | ||
log.debug("Delete user"); | ||
coauth.deleteUser($user.id).then(function(status) { | ||
assert( status === true ); | ||
log.info("Deleted User", $user.id, status); | ||
f(); | ||
}, e).catch(e); | ||
}), | ||
function() { | ||
process.exit(0); | ||
} | ||
]); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8950
4
350