|
1 | 1 | const assert = require('assert') |
2 | 2 |
|
3 | 3 | const Address = require('address-rfc2821').Address |
| 4 | +const constants = require('haraka-constants') |
4 | 5 | const fixtures = require('haraka-test-fixtures') |
5 | 6 |
|
6 | 7 | describe('register', function () { |
@@ -293,3 +294,170 @@ describe('is_dkim_authenticated', function () { |
293 | 294 | }, connection) |
294 | 295 | }) |
295 | 296 | }) |
| 297 | + |
| 298 | +describe('check_abused_names', function () { |
| 299 | + let plugin |
| 300 | + let connection |
| 301 | + |
| 302 | + beforeEach(function () { |
| 303 | + connection = fixtures.connection.createConnection() |
| 304 | + connection.init_transaction() |
| 305 | + |
| 306 | + plugin = new fixtures.plugin('index') |
| 307 | + plugin.register() |
| 308 | + }) |
| 309 | + |
| 310 | + it('allows messages when no commonly abused names configured', function (done) { |
| 311 | + // Clear the commonly_abused config |
| 312 | + plugin.cfg.commonly_abused = {} |
| 313 | + |
| 314 | + const header_from = 'Costco Support <spam@spammer.com>' |
| 315 | + connection.transaction.header.add('From', header_from) |
| 316 | + connection.transaction.header.add('Subject', 'Your Costco Order') |
| 317 | + connection.transaction.mail_from = new Address('<spam@spammer.com>') |
| 318 | + |
| 319 | + plugin.check_abused_names(function (code) { |
| 320 | + assert.equal(code, undefined) |
| 321 | + done() |
| 322 | + }, connection) |
| 323 | + }) |
| 324 | + |
| 325 | + it('allows outbound messages without checking', function (done) { |
| 326 | + connection.relaying = true |
| 327 | + const header_from = 'Costco Support <spam@spammer.com>' |
| 328 | + connection.transaction.header.add('From', header_from) |
| 329 | + connection.transaction.header.add('Subject', 'Your Costco Order') |
| 330 | + connection.transaction.mail_from = new Address('<spam@spammer.com>') |
| 331 | + |
| 332 | + plugin.check_abused_names(function (code) { |
| 333 | + assert.equal(code, undefined) |
| 334 | + done() |
| 335 | + }, connection) |
| 336 | + }) |
| 337 | + |
| 338 | + it('rejects when costco in subject but domain is not costco.com', function (done) { |
| 339 | + const header_from = 'Support <spam@spammer.com>' |
| 340 | + connection.transaction.header.add('From', header_from) |
| 341 | + connection.transaction.header.add('Subject', 'Your Costco Order Confirmation') |
| 342 | + connection.transaction.mail_from = new Address('<spam@spammer.com>') |
| 343 | + |
| 344 | + plugin.check_abused_names(function (code, msg) { |
| 345 | + assert.equal(code, constants.DENY) |
| 346 | + assert.ok(msg.includes('impersonate')) |
| 347 | + assert.ok(msg.includes('costco.com')) |
| 348 | + done() |
| 349 | + }, connection) |
| 350 | + }) |
| 351 | + |
| 352 | + it('rejects when c0stc0 (with zeros) in subject but domain is not costco.com', function (done) { |
| 353 | + const header_from = 'Support <spam@evil.com>' |
| 354 | + connection.transaction.header.add('From', header_from) |
| 355 | + connection.transaction.header.add('Subject', 'Your c0stc0 Order') |
| 356 | + connection.transaction.mail_from = new Address('<spam@evil.com>') |
| 357 | + |
| 358 | + plugin.check_abused_names(function (code, msg) { |
| 359 | + assert.equal(code, constants.DENY) |
| 360 | + assert.ok(msg.includes('impersonate')) |
| 361 | + done() |
| 362 | + }, connection) |
| 363 | + }) |
| 364 | + |
| 365 | + it('rejects when costco in header from but domain is not costco.com', function (done) { |
| 366 | + const header_from = 'Costco Support <spam@spammer.com>' |
| 367 | + connection.transaction.header.add('From', header_from) |
| 368 | + connection.transaction.header.add('Subject', 'Order Update') |
| 369 | + connection.transaction.mail_from = new Address('<spam@spammer.com>') |
| 370 | + |
| 371 | + plugin.check_abused_names(function (code, msg) { |
| 372 | + assert.equal(code, constants.DENY) |
| 373 | + assert.ok(msg.includes('impersonate')) |
| 374 | + done() |
| 375 | + }, connection) |
| 376 | + }) |
| 377 | + |
| 378 | + it('rejects when costco in envelope from local part but domain is not costco.com', function (done) { |
| 379 | + const header_from = 'Support Team <spam@spammer.com>' |
| 380 | + connection.transaction.header.add('From', header_from) |
| 381 | + connection.transaction.header.add('Subject', 'Important Notice') |
| 382 | + connection.transaction.mail_from = new Address('<costco-support@spammer.com>') |
| 383 | + |
| 384 | + plugin.check_abused_names(function (code, msg) { |
| 385 | + assert.equal(code, constants.DENY) |
| 386 | + assert.ok(msg.includes('impersonate')) |
| 387 | + done() |
| 388 | + }, connection) |
| 389 | + }) |
| 390 | + |
| 391 | + it('allows when costco in subject and envelope domain is costco.com', function (done) { |
| 392 | + const header_from = 'Costco Support <noreply@costco.com>' |
| 393 | + connection.transaction.header.add('From', header_from) |
| 394 | + connection.transaction.header.add('Subject', 'Your Costco Order') |
| 395 | + connection.transaction.mail_from = new Address('<noreply@costco.com>') |
| 396 | + |
| 397 | + plugin.check_abused_names(function (code) { |
| 398 | + assert.equal(code, undefined) |
| 399 | + done() |
| 400 | + }, connection) |
| 401 | + }) |
| 402 | + |
| 403 | + it('allows when costco in subject and header from domain is costco.com', function (done) { |
| 404 | + const header_from = 'Costco Support <noreply@costco.com>' |
| 405 | + connection.transaction.header.add('From', header_from) |
| 406 | + connection.transaction.header.add('Subject', 'Your Costco Order') |
| 407 | + connection.transaction.mail_from = new Address('<spam@spammer.com>') |
| 408 | + |
| 409 | + plugin.check_abused_names(function (code) { |
| 410 | + assert.equal(code, undefined) |
| 411 | + done() |
| 412 | + }, connection) |
| 413 | + }) |
| 414 | + |
| 415 | + it('allows when costco in subject and envelope domain is subdomain of costco.com', function (done) { |
| 416 | + const header_from = 'Costco Support <noreply@mail.costco.com>' |
| 417 | + connection.transaction.header.add('From', header_from) |
| 418 | + connection.transaction.header.add('Subject', 'Your Costco Order') |
| 419 | + connection.transaction.mail_from = new Address('<noreply@mail.costco.com>') |
| 420 | + |
| 421 | + plugin.check_abused_names(function (code) { |
| 422 | + assert.equal(code, undefined) |
| 423 | + done() |
| 424 | + }, connection) |
| 425 | + }) |
| 426 | + |
| 427 | + it('allows messages without abused names', function (done) { |
| 428 | + const header_from = 'John Doe <john@example.com>' |
| 429 | + connection.transaction.header.add('From', header_from) |
| 430 | + connection.transaction.header.add('Subject', 'Hello there') |
| 431 | + connection.transaction.mail_from = new Address('<john@example.com>') |
| 432 | + |
| 433 | + plugin.check_abused_names(function (code) { |
| 434 | + assert.equal(code, undefined) |
| 435 | + done() |
| 436 | + }, connection) |
| 437 | + }) |
| 438 | + |
| 439 | + it('is case-insensitive when checking abused names', function (done) { |
| 440 | + const header_from = 'COSTCO Support <spam@spammer.com>' |
| 441 | + connection.transaction.header.add('From', header_from) |
| 442 | + connection.transaction.header.add('Subject', 'Your COSTCO Order') |
| 443 | + connection.transaction.mail_from = new Address('<spam@spammer.com>') |
| 444 | + |
| 445 | + plugin.check_abused_names(function (code) { |
| 446 | + assert.equal(code, constants.DENY) |
| 447 | + done() |
| 448 | + }, connection) |
| 449 | + }) |
| 450 | + |
| 451 | + it('rejects paypal abuse', function (done) { |
| 452 | + const header_from = 'PayPal Security <noreply@phishing.com>' |
| 453 | + connection.transaction.header.add('From', header_from) |
| 454 | + connection.transaction.header.add('Subject', 'Verify your PayPal account') |
| 455 | + connection.transaction.mail_from = new Address('<noreply@phishing.com>') |
| 456 | + |
| 457 | + plugin.check_abused_names(function (code, msg) { |
| 458 | + assert.equal(code, constants.DENY) |
| 459 | + assert.ok(msg.includes('paypal.com')) |
| 460 | + done() |
| 461 | + }, connection) |
| 462 | + }) |
| 463 | +}) |
0 commit comments