Skip to content

Commit

Permalink
remove nulls from daf9988 and add logging to config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvyre committed Jan 22, 2020
1 parent 68a4ad0 commit 273499f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
11 changes: 10 additions & 1 deletion src/backend/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
const dotenv = require('dotenv');
const { logger } = require('../utils/logger');

dotenv.config();
const result = dotenv.config();

if (result.error) {
logger.error(
'\n\n\t💡 It appears that you have not yet configurated a .env file.',
'\n\t Please refer to our documentation regarding environment configuration:',
'\n\t https://github.com/Seneca-CDOT/telescope/blob/master/docs/CONTRIBUTING.md\n'
);
}
4 changes: 2 additions & 2 deletions src/backend/lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const { logger } = require('../utils/logger');
const redisUrl = process.env.REDIS_URL || 'redis://127.0.0.1:6379';

// Set MOCK_REDIS=1 to mock, MOCK_REDIS= to use real redis
const useMockRedis = process.env.MOCK_REDIS || null;
const useMockRedis = process.env.MOCK_REDIS;

// RedisConstructor is one of Redis or MockRedis
const RedisConstructor = useMockRedis ? MockRedis : Redis;

function createRedisClient() {
try {
const { port, host } = url.parse(redisUrl, true);
return new RedisConstructor(port, host, { password: process.env.REDIS_PASSWORD || null });
return new RedisConstructor(port, host, { password: process.env.REDIS_PASSWORD });
} catch (err) {
const message = `Unable to parse port and host from "${redisUrl}"`;
logger.error({ err }, message);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/login/usingPassport.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SAML2_REDIRECT_URI=http://localhost:3000/oauth/callback
let cert = null;

const SAML2_BASE_URI = process.env.SAML2_BASE_URI || '';
const SAML2_REDIRECT_URI = process.env.SAML2_REDIRECT_URI || null;
const SAML2_REDIRECT_URI = process.env.SAML2_REDIRECT_URI;

try {
cert = fs.readFileSync(path.resolve(process.cwd(), './certs/key.pem'), 'utf8');
Expand Down
8 changes: 4 additions & 4 deletions src/backend/utils/email-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports.createTransporter = function(hosted, portNum, isSecure, username, passwo
exports.createMail = function(receipients, subjectMessage, message) {
// Email Content
const mailOptions = {
from: process.env.NODEMAILER_USERNAME || null, // Email Name
from: process.env.NODEMAILER_USERNAME, // Email Name
to: receipients, // People to send to
subject: subjectMessage, // Subject Line
html:
Expand Down Expand Up @@ -82,11 +82,11 @@ exports.verifyTransporter = function(transporter) {
exports.sendMessage = async function(receipiants, subjectMessage, message) {
return new Promise((resolve, reject) => {
const transporter = this.createTransporter(
process.env.NODEMAILER_SERVER || null,
process.env.NODEMAILER_SERVER,
2222,
false,
process.env.NODEMAILER_USERNAME || null,
process.env.NODEMAILER_PASSWORD || null
process.env.NODEMAILER_USERNAME,
process.env.NODEMAILER_PASSWORD
);
const allGood = this.verifyTransporter(transporter);
if (!allGood) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const options = {

// Log to stdout, or a file if LOG_FILE is specified
let destination;
if (process.env.LOG_FILE || null) {
destination = pino.destination(path.resolve(process.cwd(), process.env.LOG_FILE || null));
if (process.env.LOG_FILE) {
destination = pino.destination(path.resolve(process.cwd(), process.env.LOG_FILE));
options.prettyPrint = false;
// options.prettyPrint.colorize = false;
} else {
Expand Down
10 changes: 5 additions & 5 deletions test/email-sender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.skip('Tests if sendMessage resolves with expected info', async () => {
// Feeds test data into sendMessage function
const testSubjectMessage = 'Test';
const testHTML = '<h1>Hello World</h1>';
const testRecipient = process.env.NODEMAILER_TESTRECIPIENT || null;
const testRecipient = process.env.NODEMAILER_TESTRECIPIENT;
const testReturnValue = emailsender.sendMessage(testRecipient, testSubjectMessage, testHTML);
// Tests if the expected resolve is correct
expect(testReturnValue).resolves.toBe([testRecipient]);
Expand Down Expand Up @@ -44,11 +44,11 @@ test.skip('Tests if verifyTransport returns with expected info', () => {
test.skip('Tests if transport is created correctly', () => {
const transporter = emailsender.createTransporter();

expect(transporter.options).toHaveProperty('host', process.env.NODEMAILER_SERVER || null);
expect(transporter.options).toHaveProperty('host', process.env.NODEMAILER_SERVER);
expect(transporter.options).toHaveProperty('port', 2222);
expect(transporter.options).toHaveProperty('secure', false);
expect(transporter.options).toHaveProperty('auth.user', process.env.NODEMAILER_USERNAME || null);
expect(transporter.options).toHaveProperty('auth.pass', process.env.NODEMAILER_PASSWORD || null);
expect(transporter.options).toHaveProperty('auth.user', process.env.NODEMAILER_USERNAME);
expect(transporter.options).toHaveProperty('auth.pass', process.env.NODEMAILER_PASSWORD);
}, 10000);

test('Tests if email object is created correctly', () => {
Expand All @@ -57,7 +57,7 @@ test('Tests if email object is created correctly', () => {
const message = 'FIX ME!';
const email = emailsender.createMail(recipient, subjectMessage, message);

expect(email).toHaveProperty('from', process.env.NODEMAILER_USERNAME || null);
expect(email).toHaveProperty('from', process.env.NODEMAILER_USERNAME);
expect(email).toHaveProperty('to', 'dummy@email.com');
expect(email).toHaveProperty('subject', 'Hello');
expect(email).toHaveProperty(
Expand Down

0 comments on commit 273499f

Please sign in to comment.