Skip to content

Commit

Permalink
feat(smtp): support for unauthorized connections (#170)
Browse files Browse the repository at this point in the history
* feat(smtp): support for unauthorized connections

* feat(smtp): support for unauthorized connections

* fix(smtp_docs) : updated default values

* fix(smtp_docs) : updated default values

* fix(tests) : fixed broken config tests and updates the default config object to match new smtp configuration options
  • Loading branch information
syncush authored and NivLipetz committed Aug 2, 2019
1 parent 5c8c809 commit 7005be5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docs/devguide/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ Additional parameters for the following chosen databases:
| SMTP_PORT | smtp_server.port | SMTP port number || |
| SMTP_USERNAME | smtp_server.username | SMTP username || |
| SMTP_PASSWORD | smtp_server.password | SMTP password || |
| SMTP_TIMEOUT | smtp_server.timeout | timeout to SMTP server in milliseconds || |
| SMTP_TIMEOUT | smtp_server.timeout | timeout to SMTP server in milliseconds || 200 |
| SMTP_SECURE | smtp_server.secure | if true the connection will use TLS when connecting to server. [Nodemailer SMTP options](https://nodemailer.com/smtp/) || false |
| SMTP_REJECT_UNAUTH_CERTS | smtp_server.rejectUnauthCerts | should fail or succeed on unauthorized certificate || false |
4 changes: 3 additions & 1 deletion src/configManager/helpers/configDataMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ let configDataMap = {
port: process.env.SMTP_PORT,
username: process.env.SMTP_USERNAME,
password: process.env.SMTP_PASSWORD,
timeout: process.env.SMTP_TIMEOUT || 200
timeout: process.env.SMTP_TIMEOUT || 200,
secure: process.env.SMTP_SECURE || false,
rejectUnauthCerts: process.env.SMTP_REJECT_UNAUTH_CERTS || false
}),
type: 'json'
}
Expand Down
6 changes: 5 additions & 1 deletion src/reports/models/reportEmailSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ async function createSMTPClient(configSmtp) {
port: configSmtp.port,
host: configSmtp.host,
connectionTimeout: configSmtp.timeout,
secure: configSmtp.secure,
auth: {
user: configSmtp.username,
pass: configSmtp.password
},
tls: {
rejectUnauthorized: configSmtp.rejectUnauthCerts
}
};

Expand Down Expand Up @@ -102,4 +106,4 @@ function generateReportFromTemplate(testName, testInfo, grafanaUrl, aggregatedRe
let compiledTemplate = _.template(template);
let html = compiledTemplate(emailVars);
return html;
}
}
18 changes: 9 additions & 9 deletions tests/unit-tests/configManager/configHandler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ const configConstants = require('../../../src/common/consts').CONFIG;

let manager;

const defaultSmtpServerConfig = {
timeout: 200,
rejectUnauthCerts: false,
secure: false
};

const defaultConfig = {
delay_runner_ms: 0,
job_platform: 'DOCKER',
runner_docker_image: 'zooz/predator-runner:latest',
runner_cpu: 1,
runner_memory: 256,
smtp_server: {
timeout: 200
},
smtp_server: Object.assign({}, defaultSmtpServerConfig),
minimum_wait_for_delayed_report_status_update_in_ms: 30000
};

Expand All @@ -28,9 +32,7 @@ const defaultConfigNotEscaped = {
runner_docker_image: 'zooz/predator-runner:latest',
runner_cpu: 1,
runner_memory: 256,
smtp_server: {
timeout: 200
},
smtp_server: Object.assign({}, defaultSmtpServerConfig),
minimum_wait_for_delayed_report_status_update_in_ms: 30000
};

Expand Down Expand Up @@ -74,9 +76,7 @@ const resultAfterConvert = {
grafana_url: 'test_grafana_url',
runner_cpu: 2,
runner_memory: 256,
smtp_server: {
timeout: 200
},
smtp_server: Object.assign({}, defaultSmtpServerConfig),
minimum_wait_for_delayed_report_status_update_in_ms: 30000
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe('Manager config with env variables', function () {
process.env.SMTP_PORT = 'smtp_port_test';
process.env.SMTP_USERNAME = 'smtp_username_test';
process.env.SMTP_PASSWORD = 'smtp_password_test';
process.env.SMTP_REJECT_UNAUTH_CERTS = true;
process.env.SMTP_SECURE = true;
process.env.SMTP_TIMEOUT = '500';
process.env.RUNNER_MEMORY = '20';
process.env.RUNNER_CPU = '0.35';
Expand Down Expand Up @@ -54,7 +56,10 @@ describe('Manager config with env variables', function () {
'port': 'smtp_port_test',
'username': 'smtp_username_test',
'password': 'smtp_password_test',
'timeout': '500'
'timeout': '500',
'rejectUnauthCerts': 'true',
'secure': 'true'

});
});
});

0 comments on commit 7005be5

Please sign in to comment.