Merge pull request #1081 from ParsePlatform/flovilmart.deleteAuthData
Ensures _auth_data_[provider] gets deleted from document
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
var OAuth = require("../src/authDataManager/OAuth1Client");
|
var OAuth = require("../src/authDataManager/OAuth1Client");
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
var Config = require("../src/Config");
|
||||||
|
|
||||||
describe('OAuth', function() {
|
describe('OAuth', function() {
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ describe('OAuth', function() {
|
|||||||
|
|
||||||
it("Should properly generate request signature", (done) => {
|
it("Should properly generate request signature", (done) => {
|
||||||
var request = {
|
var request = {
|
||||||
host: "dummy.com",
|
host: "dummy.com",
|
||||||
path: "path"
|
path: "path"
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ describe('OAuth', function() {
|
|||||||
|
|
||||||
it("Should properly build request", (done) => {
|
it("Should properly build request", (done) => {
|
||||||
var options = {
|
var options = {
|
||||||
host: "dummy.com",
|
host: "dummy.com",
|
||||||
consumer_key: "hello",
|
consumer_key: "hello",
|
||||||
consumer_secret: "world",
|
consumer_secret: "world",
|
||||||
auth_token: "token",
|
auth_token: "token",
|
||||||
@@ -86,7 +87,7 @@ describe('OAuth', function() {
|
|||||||
|
|
||||||
it("Should fail a GET request", (done) => {
|
it("Should fail a GET request", (done) => {
|
||||||
var options = {
|
var options = {
|
||||||
host: "api.twitter.com",
|
host: "api.twitter.com",
|
||||||
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||||
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||||
};
|
};
|
||||||
@@ -100,7 +101,7 @@ describe('OAuth', function() {
|
|||||||
|
|
||||||
it("Should fail a POST request", (done) => {
|
it("Should fail a POST request", (done) => {
|
||||||
var options = {
|
var options = {
|
||||||
host: "api.twitter.com",
|
host: "api.twitter.com",
|
||||||
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||||
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||||
};
|
};
|
||||||
@@ -117,7 +118,7 @@ describe('OAuth', function() {
|
|||||||
|
|
||||||
it("Should fail a request", (done) => {
|
it("Should fail a request", (done) => {
|
||||||
var options = {
|
var options = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
consumer_key: "XXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||||
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
consumer_secret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
||||||
};
|
};
|
||||||
@@ -141,8 +142,8 @@ describe('OAuth', function() {
|
|||||||
var provider = require("../src/authDataManager/"+providerName);
|
var provider = require("../src/authDataManager/"+providerName);
|
||||||
jequal(typeof provider.validateAuthData, "function");
|
jequal(typeof provider.validateAuthData, "function");
|
||||||
jequal(typeof provider.validateAppId, "function");
|
jequal(typeof provider.validateAppId, "function");
|
||||||
jequal(provider.validateAuthData({}, {}).constructor, Promise.prototype.constructor);
|
jequal(provider.validateAuthData({}, {}).constructor, Promise.prototype.constructor);
|
||||||
jequal(provider.validateAppId("app", "key", {}).constructor, Promise.prototype.constructor);
|
jequal(provider.validateAppId("app", "key", {}).constructor, Promise.prototype.constructor);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -204,12 +205,12 @@ describe('OAuth', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var headers = {'X-Parse-Application-Id': 'test',
|
var headers = {'X-Parse-Application-Id': 'test',
|
||||||
'X-Parse-REST-API-Key': 'rest',
|
'X-Parse-REST-API-Key': 'rest',
|
||||||
'Content-Type': 'application/json' }
|
'Content-Type': 'application/json' }
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
headers: {'X-Parse-Application-Id': 'test',
|
headers: {'X-Parse-Application-Id': 'test',
|
||||||
'X-Parse-REST-API-Key': 'rest',
|
'X-Parse-REST-API-Key': 'rest',
|
||||||
'Content-Type': 'application/json' },
|
'Content-Type': 'application/json' },
|
||||||
url: 'http://localhost:8378/1/users',
|
url: 'http://localhost:8378/1/users',
|
||||||
body: JSON.stringify(jsonBody)
|
body: JSON.stringify(jsonBody)
|
||||||
@@ -248,7 +249,7 @@ describe('OAuth', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("unlink and link with custom provider", (done) => {
|
it("unlink and link with custom provider", (done) => {
|
||||||
@@ -266,28 +267,38 @@ describe('OAuth', function() {
|
|||||||
|
|
||||||
model._unlinkFrom("myoauth", {
|
model._unlinkFrom("myoauth", {
|
||||||
success: function(model) {
|
success: function(model) {
|
||||||
|
|
||||||
ok(!model._isLinked("myoauth"),
|
ok(!model._isLinked("myoauth"),
|
||||||
"User should not be linked to myoauth");
|
"User should not be linked to myoauth");
|
||||||
ok(!provider.synchronizedUserId, "User id should be cleared");
|
ok(!provider.synchronizedUserId, "User id should be cleared");
|
||||||
ok(!provider.synchronizedAuthToken, "Auth token should be cleared");
|
ok(!provider.synchronizedAuthToken, "Auth token should be cleared");
|
||||||
ok(!provider.synchronizedExpiration,
|
ok(!provider.synchronizedExpiration,
|
||||||
"Expiration should be cleared");
|
"Expiration should be cleared");
|
||||||
|
// make sure the auth data is properly deleted
|
||||||
|
var config = new Config(Parse.applicationId);
|
||||||
|
config.database.mongoFind('_User', {
|
||||||
|
_id: model.id
|
||||||
|
}).then((res) => {
|
||||||
|
expect(res.length).toBe(1);
|
||||||
|
expect(res[0]._auth_data_myoauth).toBeUndefined();
|
||||||
|
expect(res[0]._auth_data_myoauth).not.toBeNull();
|
||||||
|
|
||||||
model._linkWith("myoauth", {
|
model._linkWith("myoauth", {
|
||||||
success: function(model) {
|
success: function(model) {
|
||||||
ok(provider.synchronizedUserId, "User id should have a value");
|
ok(provider.synchronizedUserId, "User id should have a value");
|
||||||
ok(provider.synchronizedAuthToken,
|
ok(provider.synchronizedAuthToken,
|
||||||
"Auth token should have a value");
|
"Auth token should have a value");
|
||||||
ok(provider.synchronizedExpiration,
|
ok(provider.synchronizedExpiration,
|
||||||
"Expiration should have a value");
|
"Expiration should have a value");
|
||||||
ok(model._isLinked("myoauth"),
|
ok(model._isLinked("myoauth"),
|
||||||
"User should be linked to myoauth");
|
"User should be linked to myoauth");
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
error: function(model, error) {
|
error: function(model, error) {
|
||||||
ok(false, "linking again should succeed");
|
ok(false, "linking again should succeed");
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(model, error) {
|
error: function(model, error) {
|
||||||
@@ -304,4 +315,4 @@ describe('OAuth', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export function transformKeyValue(schema, className, restKey, restValue, options
|
|||||||
return transformWhere(schema, className, s);
|
return transformWhere(schema, className, s);
|
||||||
});
|
});
|
||||||
return {key: '$and', value: mongoSubqueries};
|
return {key: '$and', value: mongoSubqueries};
|
||||||
default:
|
default:
|
||||||
// Other auth data
|
// Other auth data
|
||||||
var authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
|
var authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
|
||||||
if (authDataMatch) {
|
if (authDataMatch) {
|
||||||
@@ -224,7 +224,7 @@ function transformUpdate(schema, className, restUpdate) {
|
|||||||
if (className == '_User') {
|
if (className == '_User') {
|
||||||
restUpdate = transformAuthData(restUpdate);
|
restUpdate = transformAuthData(restUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mongoUpdate = {};
|
var mongoUpdate = {};
|
||||||
var acl = transformACL(restUpdate);
|
var acl = transformACL(restUpdate);
|
||||||
if (acl._rperm || acl._wperm) {
|
if (acl._rperm || acl._wperm) {
|
||||||
@@ -260,7 +260,14 @@ function transformUpdate(schema, className, restUpdate) {
|
|||||||
function transformAuthData(restObject) {
|
function transformAuthData(restObject) {
|
||||||
if (restObject.authData) {
|
if (restObject.authData) {
|
||||||
Object.keys(restObject.authData).forEach((provider) => {
|
Object.keys(restObject.authData).forEach((provider) => {
|
||||||
restObject[`_auth_data_${provider}`] = restObject.authData[provider];
|
let providerData = restObject.authData[provider];
|
||||||
|
if (providerData == null) {
|
||||||
|
restObject[`_auth_data_${provider}`] = {
|
||||||
|
__op: 'Delete'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
restObject[`_auth_data_${provider}`] = providerData;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
delete restObject.authData;
|
delete restObject.authData;
|
||||||
}
|
}
|
||||||
@@ -823,4 +830,3 @@ module.exports = {
|
|||||||
transformWhere: transformWhere,
|
transformWhere: transformWhere,
|
||||||
untransformObject: untransformObject
|
untransformObject: untransformObject
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user