Skip to content

Commit 31dac4f

Browse files
committed
add getRelayData tests
1 parent 2a84831 commit 31dac4f

1 file changed

Lines changed: 92 additions & 1 deletion

File tree

test/filtering-tools-test.js

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const { expect } = require('chai');
5-
const { extractQuotedPhrases, parseFilterQueryText, filterQueryTermMatches } = require('../lib/tools');
5+
const { extractQuotedPhrases, parseFilterQueryText, filterQueryTermMatches, getRelayData } = require('../lib/tools');
66

77
describe('Email Filtering helper functions', () => {
88
describe('extractQuotedPhrases', () => {
@@ -371,4 +371,95 @@ describe('Email Filtering helper functions', () => {
371371
expect(parsed.exactPhrases).to.deep.equal(['first phrase', 'second phrase']);
372372
});
373373
});
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+
});
374465
});

0 commit comments

Comments
 (0)