Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Facebook AccountKit auth #6870

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 18 additions & 97 deletions spec/AuthenticationAdapters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('AuthenticationProviders', function () {
'gcenter',
'gpgames',
'facebook',
'facebookaccountkit',
'github',
'instagram',
'google',
Expand All @@ -43,7 +42,7 @@ describe('AuthenticationProviders', function () {
'phantauth',
'microsoft',
].map(function (providerName) {
it('Should validate structure of ' + providerName, (done) => {
it('Should validate structure of ' + providerName, done => {
const provider = require('../lib/Adapters/Auth/' + providerName);
jequal(typeof provider.validateAuthData, 'function');
jequal(typeof provider.validateAppId, 'function');
Expand Down Expand Up @@ -71,7 +70,7 @@ describe('AuthenticationProviders', function () {
return;
}
spyOn(require('../lib/Adapters/Auth/httpsRequest'), 'get').and.callFake(
(options) => {
options => {
if (
options ===
'https://oauth.vk.com/access_token?client_id=appId&client_secret=appSecret&v=5.59&grant_type=client_credentials'
Expand Down Expand Up @@ -175,7 +174,7 @@ describe('AuthenticationProviders', function () {
body: jsonBody,
};
return request(options)
.then((response) => {
.then(response => {
if (callback) {
callback(null, response, response.data);
}
Expand All @@ -184,15 +183,15 @@ describe('AuthenticationProviders', function () {
body: response.data,
};
})
.catch((error) => {
.catch(error => {
if (callback) {
callback(error);
}
throw error;
});
};

it('should create user with REST API', (done) => {
it('should create user with REST API', done => {
createOAuthUser((error, response, body) => {
expect(error).toBe(null);
const b = body;
Expand All @@ -203,7 +202,7 @@ describe('AuthenticationProviders', function () {
const q = new Parse.Query('_Session');
q.equalTo('sessionToken', sessionToken);
q.first({ useMasterKey: true })
.then((res) => {
.then(res => {
if (!res) {
fail('should not fail fetching the session');
done();
Expand All @@ -219,7 +218,7 @@ describe('AuthenticationProviders', function () {
});
});

it('should only create a single user with REST API', (done) => {
it('should only create a single user with REST API', done => {
let objectId;
createOAuthUser((error, response, body) => {
expect(error).toBe(null);
Expand All @@ -239,9 +238,9 @@ describe('AuthenticationProviders', function () {
});
});

it("should fail to link if session token don't match user", (done) => {
it("should fail to link if session token don't match user", done => {
Parse.User.signUp('myUser', 'password')
.then((user) => {
.then(user => {
return createOAuthUserWithSessionToken(user.getSessionToken());
})
.then(() => {
Expand All @@ -250,7 +249,7 @@ describe('AuthenticationProviders', function () {
.then(() => {
return Parse.User.signUp('myUser2', 'password');
})
.then((user) => {
.then(user => {
return createOAuthUserWithSessionToken(user.getSessionToken());
})
.then(fail, ({ data }) => {
Expand Down Expand Up @@ -330,7 +329,7 @@ describe('AuthenticationProviders', function () {
expect(typeof authAdapter.validateAppId).toBe('function');
}

it('properly loads custom adapter', (done) => {
it('properly loads custom adapter', done => {
const validAuthData = {
id: 'hello',
token: 'world',
Expand Down Expand Up @@ -370,14 +369,14 @@ describe('AuthenticationProviders', function () {
expect(appIdSpy).not.toHaveBeenCalled();
done();
},
(err) => {
err => {
jfail(err);
done();
}
);
});

it('properly loads custom adapter module object', (done) => {
it('properly loads custom adapter module object', done => {
const authenticationHandler = authenticationLoader({
customAuthentication: path.resolve('./spec/support/CustomAuth.js'),
});
Expand All @@ -394,14 +393,14 @@ describe('AuthenticationProviders', function () {
() => {
done();
},
(err) => {
err => {
jfail(err);
done();
}
);
});

it('properly loads custom adapter module object (again)', (done) => {
it('properly loads custom adapter module object (again)', done => {
const authenticationHandler = authenticationLoader({
customAuthentication: {
module: path.resolve('./spec/support/CustomAuthFunction.js'),
Expand All @@ -421,7 +420,7 @@ describe('AuthenticationProviders', function () {
() => {
done();
},
(err) => {
err => {
jfail(err);
done();
}
Expand Down Expand Up @@ -512,84 +511,6 @@ describe('AuthenticationProviders', function () {
expect(appIds).toEqual(['a', 'b']);
expect(providerOptions).toEqual(options.custom);
});

it('properly loads Facebook accountkit adapter with options', () => {
const options = {
facebookaccountkit: {
appIds: ['a', 'b'],
appSecret: 'secret',
},
};
const {
adapter,
appIds,
providerOptions,
} = authenticationLoader.loadAuthAdapter('facebookaccountkit', options);
validateAuthenticationAdapter(adapter);
expect(appIds).toEqual(['a', 'b']);
expect(providerOptions.appSecret).toEqual('secret');
});

it('should fail if Facebook appIds is not configured properly', (done) => {
const options = {
facebookaccountkit: {
appIds: [],
},
};
const { adapter, appIds } = authenticationLoader.loadAuthAdapter(
'facebookaccountkit',
options
);
adapter.validateAppId(appIds).then(done.fail, (err) => {
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
});
});

it('should fail to validate Facebook accountkit auth with bad token', (done) => {
const options = {
facebookaccountkit: {
appIds: ['a', 'b'],
},
};
const authData = {
id: 'fakeid',
access_token: 'badtoken',
};
const { adapter } = authenticationLoader.loadAuthAdapter(
'facebookaccountkit',
options
);
adapter.validateAuthData(authData).then(done.fail, (err) => {
expect(err.code).toBe(190);
expect(err.type).toBe('OAuthException');
done();
});
});

it('should fail to validate Facebook accountkit auth with bad token regardless of app secret proof', (done) => {
const options = {
facebookaccountkit: {
appIds: ['a', 'b'],
appSecret: 'badsecret',
},
};
const authData = {
id: 'fakeid',
access_token: 'badtoken',
};
const { adapter, providerOptions } = authenticationLoader.loadAuthAdapter(
'facebookaccountkit',
options
);
adapter
.validateAuthData(authData, providerOptions)
.then(done.fail, (err) => {
expect(err.code).toBe(190);
expect(err.type).toBe('OAuthException');
done();
});
});
});

describe('instagram auth adapter', () => {
Expand Down Expand Up @@ -1653,13 +1574,13 @@ describe('microsoft graph auth adapter', () => {
});
});

it('should fail to validate Microsoft Graph auth with bad token', (done) => {
it('should fail to validate Microsoft Graph auth with bad token', done => {
const authData = {
id: 'fake-id',
mail: 'fake@mail.com',
access_token: 'very.long.bad.token',
};
microsoft.validateAuthData(authData).then(done.fail, (err) => {
microsoft.validateAuthData(authData).then(done.fail, err => {
expect(err.code).toBe(101);
expect(err.message).toBe(
'Microsoft Graph auth is invalid for this user.'
Expand Down
Loading