Skip to content

Commit 526c277

Browse files
committed
Add dkim selector suffix tests #34
1 parent cfa5756 commit 526c277

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

tests/suffix_test.php

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Tests for DKIM default suffix.
19+
*
20+
* @package tool_emailutils
21+
* @author Benjamin Walker <[email protected]>
22+
* @copyright Catalyst IT 2024
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*
25+
*/
26+
27+
/**
28+
* Tests for DKIM default suffix.
29+
*
30+
* @copyright Catalyst IT 2024
31+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32+
*/
33+
class tool_emailutils_suffix_test extends advanced_testcase {
34+
35+
/**
36+
* Test suffix.
37+
*
38+
* @param string $lmsdomain lms domain
39+
* @param string $noreplydomain noreply domain
40+
* @param string $primarydomain primary domain
41+
* @param string $selectorsuffix selector suffix
42+
* @dataProvider dns_comparisons
43+
*/
44+
public function test_suffix(string $lmsdomain, string $noreplydomain, string $primarydomain, string $selectorsuffix) {
45+
$this->resetAfterTest();
46+
$mock = $this->getMockBuilder('\tool_emailutils\dns_util')
47+
->setMethods(['get_primary_domain', 'get_noreply_domain'])
48+
->getMock();
49+
50+
$mock->expects($this->any())
51+
->method('get_primary_domain')
52+
->willReturn($primarydomain);
53+
54+
$mock->expects($this->any())
55+
->method('get_noreply_domain')
56+
->willReturn($noreplydomain);
57+
58+
$selector = $mock->get_selector_suffix($lmsdomain);
59+
$this->assertEquals($selectorsuffix, $selector);
60+
}
61+
62+
/**
63+
* Data provider used to test comparisons between different domains.
64+
*
65+
* @return array
66+
*/
67+
public function dns_comparisons() {
68+
return [
69+
'no subdomain' => [
70+
'client.com',
71+
'client.com',
72+
'client.com',
73+
'',
74+
],
75+
'subdomain' => [
76+
'lms.client.com',
77+
'client.com',
78+
'client.com',
79+
'lms',
80+
],
81+
'another subdomain' => [
82+
'moodle.client.com',
83+
'client.com',
84+
'client.com',
85+
'moodle',
86+
],
87+
'multiple subdomain' => [
88+
'lms.moodle.client.com',
89+
'client.com',
90+
'client.com',
91+
'lms-moodle',
92+
],
93+
'longer tld' => [
94+
'lms.moodle.client.nsw.gov.au',
95+
'client.nsw.gov.au',
96+
'client.nsw.gov.au',
97+
'lms-moodle',
98+
],
99+
'www only subdomain' => [
100+
'www.client.com',
101+
'client.com',
102+
'client.com',
103+
'',
104+
],
105+
'www multiple subdomain' => [
106+
'www.moodle.client.com',
107+
'client.com',
108+
'client.com',
109+
'moodle',
110+
],
111+
'different subdomain' => [
112+
'lms.client.com',
113+
'mail.client.com',
114+
'client.com',
115+
'lms',
116+
],
117+
'noreply contains part of subdomain' => [
118+
'lms.moodle.client.com',
119+
'moodle.client.com',
120+
'client.com',
121+
'lms',
122+
],
123+
'noreply subdomain of lms' => [
124+
'lms.moodle.client.com',
125+
'email.lms.moodle.client.com',
126+
'client.com',
127+
'',
128+
],
129+
'unable to identify primary domain' => [
130+
'lms.moodle.client.com',
131+
'client.com',
132+
'lms.moodle.client.com',
133+
'lms-moodle',
134+
],
135+
'different noreply' => [
136+
'lms.moodle.client.com',
137+
'vendor.com',
138+
'client.com',
139+
'lms-moodle-client-com',
140+
],
141+
'different noreply with no subdomain' => [
142+
'client.com',
143+
'vendor.com',
144+
'client.com',
145+
'client-com',
146+
],
147+
];
148+
}
149+
150+
}

0 commit comments

Comments
 (0)