mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
accounts tests: improve isolation.
The neverending story.
This commit is contained in:
@@ -54,9 +54,9 @@ Tinytest.add('accounts - updateOrCreateUserFromExternalService - Weibo', functio
|
||||
var weiboId2 = Random.id();
|
||||
|
||||
// users that have different service ids get different users
|
||||
uid1 = Accounts.updateOrCreateUserFromExternalService(
|
||||
var uid1 = Accounts.updateOrCreateUserFromExternalService(
|
||||
'weibo', {id: weiboId1}, {profile: {foo: 1}}).id;
|
||||
uid2 = Accounts.updateOrCreateUserFromExternalService(
|
||||
var uid2 = Accounts.updateOrCreateUserFromExternalService(
|
||||
'weibo', {id: weiboId2}, {profile: {bar: 2}}).id;
|
||||
test.equal(Meteor.users.find({"services.weibo.id": {$in: [weiboId1, weiboId2]}}).count(), 2);
|
||||
test.equal(Meteor.users.findOne({"services.weibo.id": weiboId1}).profile.foo, 1);
|
||||
@@ -70,8 +70,8 @@ Tinytest.add('accounts - updateOrCreateUserFromExternalService - Weibo', functio
|
||||
});
|
||||
|
||||
Tinytest.add('accounts - updateOrCreateUserFromExternalService - Twitter', function (test) {
|
||||
var twitterIdOld = 123;
|
||||
var twitterIdNew = '123';
|
||||
var twitterIdOld = parseInt(Random.hexString(4), 16);
|
||||
var twitterIdNew = ''+twitterIdOld;
|
||||
|
||||
// create an account with twitter using the old ID format of integer
|
||||
var uid1 = Accounts.updateOrCreateUserFromExternalService(
|
||||
|
||||
@@ -6,6 +6,7 @@ Tinytest.add("oauth1 - loginResultForState is stored", function (test) {
|
||||
var twitterfooAccessToken = Random.id();
|
||||
var twitterfooAccessTokenSecret = Random.id();
|
||||
var state = Random.id();
|
||||
var serviceName = Random.id();
|
||||
|
||||
OAuth1Binding.prototype.prepareRequestToken = function() {};
|
||||
OAuth1Binding.prototype.prepareAccessToken = function() {
|
||||
@@ -13,13 +14,12 @@ Tinytest.add("oauth1 - loginResultForState is stored", function (test) {
|
||||
this.accessTokenSecret = twitterfooAccessTokenSecret;
|
||||
};
|
||||
|
||||
if (!Accounts.loginServiceConfiguration.findOne({service: 'twitterfoo'}))
|
||||
Accounts.loginServiceConfiguration.insert({service: 'twitterfoo'});
|
||||
Accounts.twitterfoo = {};
|
||||
Accounts.loginServiceConfiguration.insert({service: serviceName});
|
||||
Accounts[serviceName] = {};
|
||||
|
||||
try {
|
||||
// register a fake login service - twitterfoo
|
||||
Accounts.oauth.registerService("twitterfoo", 1, function (query) {
|
||||
// register a fake login service
|
||||
Accounts.oauth.registerService(serviceName, 1, function (query) {
|
||||
return {
|
||||
serviceData: {
|
||||
id: twitterfooId,
|
||||
@@ -35,7 +35,7 @@ Tinytest.add("oauth1 - loginResultForState is stored", function (test) {
|
||||
|
||||
var req = {
|
||||
method: "POST",
|
||||
url: "/_oauth/twitterfoo?close",
|
||||
url: "/_oauth/" + serviceName + "?close",
|
||||
query: {
|
||||
state: state,
|
||||
oauth_token: twitterfooAccessToken
|
||||
@@ -44,12 +44,13 @@ Tinytest.add("oauth1 - loginResultForState is stored", function (test) {
|
||||
Accounts.oauth._middleware(req, new http.ServerResponse(req));
|
||||
|
||||
// verify that a user is created
|
||||
var user = Meteor.users.findOne(
|
||||
{"services.twitterfoo.screenName": twitterfooName});
|
||||
var selector = {};
|
||||
selector["services." + serviceName + ".screenName"] = twitterfooName;
|
||||
var user = Meteor.users.findOne(selector);
|
||||
test.notEqual(user, undefined);
|
||||
test.equal(user.services.twitterfoo.accessToken,
|
||||
test.equal(user.services[serviceName].accessToken,
|
||||
twitterfooAccessToken);
|
||||
test.equal(user.services.twitterfoo.accessTokenSecret,
|
||||
test.equal(user.services[serviceName].accessTokenSecret,
|
||||
twitterfooAccessTokenSecret);
|
||||
|
||||
// and that that user has a login token
|
||||
@@ -63,7 +64,7 @@ Tinytest.add("oauth1 - loginResultForState is stored", function (test) {
|
||||
test.equal(
|
||||
Accounts.oauth._loginResultForState[state].token, token);
|
||||
} finally {
|
||||
delete Accounts.oauth._services.twitterfoo;
|
||||
delete Accounts.oauth._services[serviceName];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -75,17 +76,17 @@ Tinytest.add("oauth1 - error in user creation", function (test) {
|
||||
var twitterfailName = 'nickname' + Random.id();
|
||||
var twitterfailAccessToken = Random.id();
|
||||
var twitterfailAccessTokenSecret = Random.id();
|
||||
var serviceName = Random.id();
|
||||
|
||||
if (!Accounts.loginServiceConfiguration.findOne({service: 'twitterfail'}))
|
||||
Accounts.loginServiceConfiguration.insert({service: 'twitterfail'});
|
||||
Accounts.twitterfail = {};
|
||||
Accounts.loginServiceConfiguration.insert({service: serviceName});
|
||||
Accounts[serviceName] = {};
|
||||
|
||||
// Wire up access token so that verification passes
|
||||
Accounts.oauth1._requestTokens[state] = twitterfailAccessToken;
|
||||
|
||||
try {
|
||||
// register a failing login service
|
||||
Accounts.oauth.registerService("twitterfail", 1, function (query) {
|
||||
Accounts.oauth.registerService(serviceName, 1, function (query) {
|
||||
return {
|
||||
serviceData: {
|
||||
id: twitterfailId,
|
||||
@@ -109,7 +110,7 @@ Tinytest.add("oauth1 - error in user creation", function (test) {
|
||||
Meteor._suppress_log(1);
|
||||
var req = {
|
||||
method: "POST",
|
||||
url: "/_oauth/twitterfail?close",
|
||||
url: "/_oauth/" + serviceName + "?close",
|
||||
query: {
|
||||
state: state,
|
||||
oauth_token: twitterfailAccessToken
|
||||
@@ -119,7 +120,9 @@ Tinytest.add("oauth1 - error in user creation", function (test) {
|
||||
Accounts.oauth._middleware(req, new http.ServerResponse(req));
|
||||
|
||||
// verify that a user is not created
|
||||
var user = Meteor.users.findOne({"services.twitter.screenName": twitterfailName});
|
||||
var selector = {};
|
||||
selector["services." + serviceName + ".screenName"] = twitterfailName;
|
||||
var user = Meteor.users.findOne(selector);
|
||||
test.equal(user, undefined);
|
||||
|
||||
// verify an error is stored in login state
|
||||
@@ -130,7 +133,7 @@ Tinytest.add("oauth1 - error in user creation", function (test) {
|
||||
Meteor.apply('login', [{oauth: {version: 1, state: state}}]);
|
||||
});
|
||||
} finally {
|
||||
delete Accounts.oauth._services.twitterfail;
|
||||
delete Accounts.oauth._services[serviceName];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,27 +2,29 @@ Tinytest.add("oauth2 - loginResultForState is stored", function (test) {
|
||||
var http = Npm.require('http');
|
||||
var foobookId = Random.id();
|
||||
var state = Random.id();
|
||||
var serviceName = Random.id();
|
||||
|
||||
if (!Accounts.loginServiceConfiguration.findOne({service: 'foobook'}))
|
||||
Accounts.loginServiceConfiguration.insert({service: 'foobook'});
|
||||
Accounts.foobook = {};
|
||||
Accounts.loginServiceConfiguration.insert({service: serviceName});
|
||||
Accounts[serviceName] = {};
|
||||
|
||||
try {
|
||||
// register a fake login service - foobook
|
||||
Accounts.oauth.registerService("foobook", 2, function (query) {
|
||||
// register a fake login service
|
||||
Accounts.oauth.registerService(serviceName, 2, function (query) {
|
||||
return {serviceData: {id: foobookId}};
|
||||
});
|
||||
|
||||
// simulate logging in using foobook
|
||||
var req = {method: "POST",
|
||||
url: "/_oauth/foobook?close",
|
||||
url: "/_oauth/" + serviceName + "?close",
|
||||
query: {state: state}};
|
||||
Accounts.oauth._middleware(req, new http.ServerResponse(req));
|
||||
|
||||
// verify that a user is created
|
||||
var user = Meteor.users.findOne({"services.foobook.id": foobookId});
|
||||
var selector = {};
|
||||
selector["services." + serviceName + ".id"] = foobookId;
|
||||
var user = Meteor.users.findOne(selector);
|
||||
test.notEqual(user, undefined);
|
||||
test.equal(user.services.foobook.id, foobookId);
|
||||
test.equal(user.services[serviceName].id, foobookId);
|
||||
|
||||
// and that that user has a login token
|
||||
test.equal(user.services.resume.loginTokens.length, 1);
|
||||
@@ -35,7 +37,7 @@ Tinytest.add("oauth2 - loginResultForState is stored", function (test) {
|
||||
test.equal(
|
||||
Accounts.oauth._loginResultForState[state].token, token);
|
||||
} finally {
|
||||
delete Accounts.oauth._services.foobook;
|
||||
delete Accounts.oauth._services[serviceName];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,14 +46,14 @@ Tinytest.add("oauth2 - error in user creation", function (test) {
|
||||
var http = Npm.require('http');
|
||||
var state = Random.id();
|
||||
var failbookId = Random.id();
|
||||
var serviceName = Random.id();
|
||||
|
||||
if (!Accounts.loginServiceConfiguration.findOne({service: 'failbook'}))
|
||||
Accounts.loginServiceConfiguration.insert({service: 'failbook'});
|
||||
Accounts.failbook = {};
|
||||
Accounts.loginServiceConfiguration.insert({service: serviceName});
|
||||
Accounts[serviceName] = {};
|
||||
|
||||
try {
|
||||
// register a failing login service
|
||||
Accounts.oauth.registerService("failbook", 2, function (query) {
|
||||
Accounts.oauth.registerService(serviceName, 2, function (query) {
|
||||
return {
|
||||
serviceData: {
|
||||
id: failbookId
|
||||
@@ -71,12 +73,14 @@ Tinytest.add("oauth2 - error in user creation", function (test) {
|
||||
// simulate logging in with failure
|
||||
Meteor._suppress_log(1);
|
||||
var req = {method: "POST",
|
||||
url: "/_oauth/failbook?close",
|
||||
url: "/_oauth/" + serviceName + "?close",
|
||||
query: {state: state}};
|
||||
Accounts.oauth._middleware(req, new http.ServerResponse(req));
|
||||
|
||||
// verify that a user is not created
|
||||
var user = Meteor.users.findOne({"services.failbook.id": failbookId});
|
||||
var selector = {};
|
||||
selector["services." + serviceName + ".id"] = failbookId;
|
||||
var user = Meteor.users.findOne(selector);
|
||||
test.equal(user, undefined);
|
||||
|
||||
// verify an error is stored in login state
|
||||
@@ -87,7 +91,7 @@ Tinytest.add("oauth2 - error in user creation", function (test) {
|
||||
Meteor.apply('login', [{oauth: {version: 2, state: state}}]);
|
||||
});
|
||||
} finally {
|
||||
delete Accounts.oauth._services.failbook;
|
||||
delete Accounts.oauth._services[serviceName];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user