Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function fakeUserFactory(params = {}) {
const user = {
userName: randomId('userName'),
password: randomId('password'),
expires: Date.now() + (60 * 60 * 1000) // Default to 1 hour
};
return { ...user, ...params };
}
async function ensureAuthorizedOrRedirect(req, res, next) {
// Skip authentication for debugging purposes.
if (process.env.FAKE_AUTH) {
req.authorizedMetadata = { userName: randomId('username') };
return next();
}
// Public data doesn't need authentication
if (isPublicRequest(req.path)) {
req.authorizedMetadata = { userName: 'unauthenticated user' };
return next();
}
const {
accessTokenModel,
authClient
} = getConfigurations();
const redirectURLForAuthorizationCode = authClient.getAuthorizationUrl(req.path);
const accessToken = req.cookies.accessToken;
function fakeGranuleFactory(status = 'completed') {
return {
granuleId: randomId('granule'),
dataType: randomId('datatype'),
version: randomId('vers'),
collectionId: 'fakeCollection___v1',
status,
execution: randomString(),
createdAt: Date.now(),
updatedAt: Date.now(),
published: true,
cmrLink: 'example.com',
productVolume: 100
};
}
function fakeGranuleFactory(status = 'completed') {
return {
granuleId: randomId('granule'),
dataType: randomId('datatype'),
version: randomId('vers'),
collectionId: 'fakeCollection___v1',
status,
execution: randomString(),
createdAt: Date.now(),
updatedAt: Date.now(),
published: true,
cmrLink: 'example.com',
productVolume: 100
};
}
function fakeAccessTokenFactory(params = {}) {
return {
accessToken: randomId('accessToken'),
refreshToken: randomId('refreshToken'),
username: randomId('username'),
expirationTime: Date.now() + (60 * 60 * 1000),
...params
};
}
function setAuthEnvVariables() {
if (process.env.FAKE_AUTH) {
process.env.EARTHDATA_CLIENT_ID = randomId('EARTHDATA_CLIENT_ID');
process.env.EARTHDATA_CLIENT_PASSWORD = randomId('EARTHDATA_CLIENT_PASSWORD');
process.env.EARTHDATA_BASE_URL = 'https://example.com';
}
}