|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | const { expect } = require('chai'); |
5 | | -const { extractQuotedPhrases, parseFilterQueryText, filterQueryTermMatches } = require('../lib/tools'); |
| 5 | +const { extractQuotedPhrases, parseFilterQueryText, filterQueryTermMatches, getRelayData } = require('../lib/tools'); |
6 | 6 |
|
7 | 7 | describe('Email Filtering helper functions', () => { |
8 | 8 | describe('extractQuotedPhrases', () => { |
@@ -371,4 +371,95 @@ describe('Email Filtering helper functions', () => { |
371 | 371 | expect(parsed.exactPhrases).to.deep.equal(['first phrase', 'second phrase']); |
372 | 372 | }); |
373 | 373 | }); |
| 374 | + |
| 375 | + describe('getRelayData', () => { |
| 376 | + [ |
| 377 | + { |
| 378 | + title: 'should return expected structure for a hostname relay without auth', |
| 379 | + input: 'smtp://mx.example.com', |
| 380 | + expected: { |
| 381 | + mx: [ |
| 382 | + { |
| 383 | + priority: 0, |
| 384 | + mx: true, |
| 385 | + exchange: 'mx.example.com', |
| 386 | + A: [], |
| 387 | + AAAA: [] |
| 388 | + } |
| 389 | + ], |
| 390 | + mxPort: 25, |
| 391 | + mxAuth: false, |
| 392 | + mxSecure: false, |
| 393 | + url: 'smtp://mx.example.com' |
| 394 | + } |
| 395 | + }, |
| 396 | + { |
| 397 | + title: 'should return expected structure for a hostname relay with auth and port', |
| 398 | + input: 'smtp://user:pass@mx.example.com:2525', |
| 399 | + expected: { |
| 400 | + mx: [ |
| 401 | + { |
| 402 | + priority: 0, |
| 403 | + mx: true, |
| 404 | + exchange: 'mx.example.com', |
| 405 | + A: [], |
| 406 | + AAAA: [] |
| 407 | + } |
| 408 | + ], |
| 409 | + mxPort: '2525', |
| 410 | + mxAuth: { |
| 411 | + user: 'user', |
| 412 | + pass: 'pass' |
| 413 | + }, |
| 414 | + mxSecure: false, |
| 415 | + url: 'smtp://user:pass@mx.example.com:2525' |
| 416 | + } |
| 417 | + }, |
| 418 | + { |
| 419 | + title: 'should return expected structure for an IPv4 relay', |
| 420 | + input: 'smtp://192.0.2.15:25', |
| 421 | + expected: { |
| 422 | + mx: [ |
| 423 | + { |
| 424 | + priority: 0, |
| 425 | + mx: true, |
| 426 | + exchange: '192.0.2.15', |
| 427 | + A: ['192.0.2.15'], |
| 428 | + AAAA: [] |
| 429 | + } |
| 430 | + ], |
| 431 | + mxPort: '25', |
| 432 | + mxAuth: false, |
| 433 | + mxSecure: false, |
| 434 | + url: 'smtp://192.0.2.15:25' |
| 435 | + } |
| 436 | + }, |
| 437 | + { |
| 438 | + title: 'should return expected structure for an IPv6 relay', |
| 439 | + input: 'smtps://user:p%40ss@[2001:db8::1]:465', |
| 440 | + expected: { |
| 441 | + mx: [ |
| 442 | + { |
| 443 | + priority: 0, |
| 444 | + mx: true, |
| 445 | + exchange: '2001:db8::1', |
| 446 | + A: [], |
| 447 | + AAAA: ['2001:db8::1'] |
| 448 | + } |
| 449 | + ], |
| 450 | + mxPort: '465', |
| 451 | + mxAuth: { |
| 452 | + user: 'user', |
| 453 | + pass: 'p@ss' |
| 454 | + }, |
| 455 | + mxSecure: true, |
| 456 | + url: 'smtps://user:p%40ss@[2001:db8::1]:465' |
| 457 | + } |
| 458 | + } |
| 459 | + ].forEach(testCase => { |
| 460 | + it(testCase.title, () => { |
| 461 | + expect(getRelayData(testCase.input)).to.deep.equal(testCase.expected); |
| 462 | + }); |
| 463 | + }); |
| 464 | + }); |
374 | 465 | }); |
0 commit comments