Skip to content

Run test that require db access #5796

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

Merged
merged 1 commit into from
Jul 10, 2019
Merged
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
71 changes: 38 additions & 33 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3847,41 +3847,46 @@ describe('Parse.User testing', () => {
}
);
});
});

it('should validate credentials first and check if account already linked afterwards (GHSA-8w3j-g983-8jh5)', async done => {
// Add User to Database with authData
const database = Config.get(Parse.applicationId).database;
const collection = await database.adapter._adaptiveCollection('_User');
await collection.insertOne({
_id: 'ABCDEF1234',
name: '<some_name>',
email: '<some_email>',
username: '<some_username>',
_hashed_password: '<some_password>',
_auth_data_custom: {
id: 'linkedID', // Already linked userid
},
sessionToken: '<some_session_token>',
});
const provider = {
getAuthType: () => 'custom',
restoreAuthentication: () => true,
}; // AuthProvider checks if password is 'password'
Parse.User._registerAuthenticationProvider(provider);

// Try to link second user with wrong password
try {
const user = await Parse.AnonymousUtils.logIn();
await user._linkWith(provider.getAuthType(), {
authData: { id: 'linkedID', password: 'wrong' },
describe('Security Advisory GHSA-8w3j-g983-8jh5', function() {
it_only_db('mongo')(
'should validate credentials first and check if account already linked afterwards ()',
async done => {
// Add User to Database with authData
const database = Config.get(Parse.applicationId).database;
const collection = await database.adapter._adaptiveCollection('_User');
await collection.insertOne({
_id: 'ABCDEF1234',
name: '<some_name>',
email: '<some_email>',
username: '<some_username>',
_hashed_password: '<some_password>',
_auth_data_custom: {
id: 'linkedID', // Already linked userid
},
sessionToken: '<some_session_token>',
});
} catch (error) {
// This should throw Parse.Error.SESSION_MISSING and not Parse.Error.ACCOUNT_ALREADY_LINKED
expect(error.code).toEqual(Parse.Error.SESSION_MISSING);
const provider = {
getAuthType: () => 'custom',
restoreAuthentication: () => true,
}; // AuthProvider checks if password is 'password'
Parse.User._registerAuthenticationProvider(provider);

// Try to link second user with wrong password
try {
const user = await Parse.AnonymousUtils.logIn();
await user._linkWith(provider.getAuthType(), {
authData: { id: 'linkedID', password: 'wrong' },
});
} catch (error) {
// This should throw Parse.Error.SESSION_MISSING and not Parse.Error.ACCOUNT_ALREADY_LINKED
expect(error.code).toEqual(Parse.Error.SESSION_MISSING);
done();
return;
}
fail();
done();
return;
}
fail();
done();
});
);
});