Skip to content

Add JSInspect to CI #4350

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

Closed
wants to merge 7 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ before_script:
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d parse_server_postgres_adapter_test_database
- psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d parse_server_postgres_adapter_test_database
- silent=1 mongodb-runner --start
- npm install -g jsinspect
- jsinspect -t 40 ./src
after_script:
- bash <(curl -s https://codecov.io/bash)

Expand Down
6 changes: 1 addition & 5 deletions src/AccountLockout.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export class AccountLockout {

return this._config.database.find('_User', query)
.then(users => {
if (Array.isArray(users) && users.length > 0) {
return true;
} else {
return false;
}
return Array.isArray(users) && users.length > 0;
});
}

Expand Down
39 changes: 39 additions & 0 deletions src/Adapters/Auth/AuthAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*eslint no-unused-vars: "off"*/

var https = require('https');

export class AuthAdapter {

/*
Expand All @@ -17,6 +20,42 @@ export class AuthAdapter {
validateAuthData(authData, options) {
return Promise.resolve({});
}

/**
* A promisey wrapper for all auth requests
*
* @param {string} name Name of auth to use in rejection message
* @param {Object|string} config Config/String to pass to https.get
* @param {Object|null} postData Optional data to post with
* @returns {Promise}
*/
static request(name, config, postData) {
return new Promise(function(resolve, reject) {
const req = https.get(config, function(res) {
let data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with ' + name + '.');
});
if(postData) {
req.on('error', function() {
reject('Failed to validate this access token with ' + name + '.');
});
req.write(postData);
req.end();
}
});
}
}

export default AuthAdapter;
22 changes: 3 additions & 19 deletions src/Adapters/Auth/facebook.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Helper functions for accessing the Facebook Graph API.
var https = require('https');
import AuthAdapter from "./AuthAdapter";

var Parse = require('parse/node').Parse;

// Returns a promise that fulfills iff this user id is valid.
Expand Down Expand Up @@ -36,24 +37,7 @@ function validateAppId(appIds, authData) {

// A promisey wrapper for FB graph requests.
function graphRequest(path) {
return new Promise(function(resolve, reject) {
https.get('https://graph.facebook.com/v2.5/' + path, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Facebook.');
});
});
return AuthAdapter.request('Facebook', 'https://graph.facebook.com/v2.5/' + path);
}

module.exports = {
Expand Down
33 changes: 8 additions & 25 deletions src/Adapters/Auth/github.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Helper functions for accessing the github API.
var https = require('https');
import AuthAdapter from "./AuthAdapter";
var Parse = require('parse/node').Parse;

// Returns a promise that fulfills iff this user id is valid.
Expand All @@ -22,30 +22,13 @@ function validateAppId() {

// A promisey wrapper for api requests
function request(path, access_token) {
return new Promise(function(resolve, reject) {
https.get({
host: 'api.github.com',
path: '/' + path,
headers: {
'Authorization': 'bearer ' + access_token,
'User-Agent': 'parse-server'
}
}, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Github.');
});
return AuthAdapter.request('Github', {
host: 'api.github.com',
path: '/' + path,
headers: {
'Authorization': 'bearer ' + access_token,
'User-Agent': 'parse-server'
}
});
}

Expand Down
55 changes: 17 additions & 38 deletions src/Adapters/Auth/google.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
// Helper functions for accessing the google API.
var https = require('https');
var Parse = require('parse/node').Parse;
import AuthAdapter from "./AuthAdapter";
const Parse = require('parse/node').Parse;

function validateIdToken(id, token) {
return request("tokeninfo?id_token=" + token)
.then((response) => {
if (response && (response.sub == id || response.user_id == id)) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Google auth is invalid for this user.');
});
return makeRequest(id, "tokeninfo?id_token=" + token);
}

function validateAuthToken(id, token) {
return request("tokeninfo?access_token=" + token)
.then((response) => {
if (response && (response.sub == id || response.user_id == id)) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Google auth is invalid for this user.');
});
return makeRequest(id, "tokeninfo?access_token=" + token);
}

// Returns a promise that fulfills if this user id is valid.
Expand All @@ -46,26 +30,21 @@ function validateAppId() {
return Promise.resolve();
}

function makeRequest(id, path) {
return request(path)
.then((response) => {
if (response && (response.sub === id || response.user_id === id)) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Google auth is invalid for this user.');
});
}

// A promisey wrapper for api requests
function request(path) {
return new Promise(function(resolve, reject) {
https.get("https://www.googleapis.com/oauth2/v3/" + path, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Google.');
});
});
return AuthAdapter.request('Google', 'https://www.googleapis.com/oauth2/v3/' + path);
}

module.exports = {
Expand Down
22 changes: 5 additions & 17 deletions src/Adapters/Auth/instagram.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Helper functions for accessing the instagram API.
var https = require('https');
var Parse = require('parse/node').Parse;
import AuthAdapter from "./AuthAdapter";

const Parse = require('parse/node').Parse;

// Returns a promise that fulfills iff this user id is valid.
function validateAuthData(authData) {
return request("users/self/?access_token=" + authData.access_token)
.then((response) => {
if (response && response.data && response.data.id == authData.id) {
if (response && response.data && response.data.id === authData.id) {
return;
}
throw new Parse.Error(
Expand All @@ -22,20 +23,7 @@ function validateAppId() {

// A promisey wrapper for api requests
function request(path) {
return new Promise(function(resolve, reject) {
https.get("https://api.instagram.com/v1/" + path, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
data = JSON.parse(data);
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Instagram.');
});
});
return AuthAdapter.request('Instagram', "https://api.instagram.com/v1/" + path);
}

module.exports = {
Expand Down
29 changes: 6 additions & 23 deletions src/Adapters/Auth/linkedin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Helper functions for accessing the linkedin API.
var https = require('https');
import AuthAdapter from "./AuthAdapter";
var Parse = require('parse/node').Parse;

// Returns a promise that fulfills iff this user id is valid.
Expand All @@ -22,7 +22,7 @@ function validateAppId() {

// A promisey wrapper for api requests
function request(path, access_token, is_mobile_sdk) {
var headers = {
const headers = {
'Authorization': 'Bearer ' + access_token,
'x-li-format': 'json',
}
Expand All @@ -31,27 +31,10 @@ function request(path, access_token, is_mobile_sdk) {
headers['x-li-src'] = 'msdk';
}

return new Promise(function(resolve, reject) {
https.get({
host: 'api.linkedin.com',
path: '/v1/' + path,
headers: headers
}, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Linkedin.');
});
return AuthAdapter.request('Linkedin', {
host: 'api.linkedin.com',
path: '/v1/' + path,
headers: headers
});
}

Expand Down
31 changes: 7 additions & 24 deletions src/Adapters/Auth/meetup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Helper functions for accessing the meetup API.
var https = require('https');
import AuthAdapter from "./AuthAdapter";
var Parse = require('parse/node').Parse;

// Returns a promise that fulfills iff this user id is valid.
Expand All @@ -22,29 +22,12 @@ function validateAppId() {

// A promisey wrapper for api requests
function request(path, access_token) {
return new Promise(function(resolve, reject) {
https.get({
host: 'api.meetup.com',
path: '/2/' + path,
headers: {
'Authorization': 'bearer ' + access_token
}
}, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Meetup.');
});
return AuthAdapter.request('Meetup', {
host: 'api.meetup.com',
path: '/2/' + path,
headers: {
'Authorization': 'bearer ' + access_token
}
});
}

Expand Down
31 changes: 7 additions & 24 deletions src/Adapters/Auth/spotify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Helper functions for accessing the Spotify API.
var https = require('https');
import AuthAdapter from "./AuthAdapter";
var Parse = require('parse/node').Parse;

// Returns a promise that fulfills iff this user id is valid.
Expand Down Expand Up @@ -36,29 +36,12 @@ function validateAppId(appIds, authData) {

// A promisey wrapper for Spotify API requests.
function request(path, access_token) {
return new Promise(function(resolve, reject) {
https.get({
host: 'api.spotify.com',
path: '/v1/' + path,
headers: {
'Authorization': 'Bearer ' + access_token
}
}, function(res) {
var data = '';
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
try {
data = JSON.parse(data);
} catch(e) {
return reject(e);
}
resolve(data);
});
}).on('error', function() {
reject('Failed to validate this access token with Spotify.');
});
return AuthAdapter.request('Spotify', {
host: 'api.spotify.com',
path: '/v1/' + path,
headers: {
'Authorization': 'Bearer ' + access_token
}
});
}

Expand Down
Loading