Skip to content

Commit 8a4ec74

Browse files
committed
Add dkim selector suffix tests #34
1 parent cfa5756 commit 8a4ec74

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

tests/suffix_test.php

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
* ests 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+
public function dns_comparisons() {
63+
return [
64+
'no subdomain' => [
65+
'client.com',
66+
'client.com',
67+
'client.com',
68+
'',
69+
],
70+
'subdomain' => [
71+
'lms.client.com',
72+
'client.com',
73+
'client.com',
74+
'lms',
75+
],
76+
'another subdomain' => [
77+
'moodle.client.com',
78+
'client.com',
79+
'client.com',
80+
'moodle',
81+
],
82+
'multiple subdomain' => [
83+
'lms.moodle.client.com',
84+
'client.com',
85+
'client.com',
86+
'lms-moodle',
87+
],
88+
'longer tld' => [
89+
'lms.moodle.client.nsw.gov.au',
90+
'client.nsw.gov.au',
91+
'client.nsw.gov.au',
92+
'lms-moodle',
93+
],
94+
'www only subdomain' => [
95+
'www.client.com',
96+
'client.com',
97+
'client.com',
98+
'',
99+
],
100+
'www multiple subdomain' => [
101+
'www.moodle.client.com',
102+
'client.com',
103+
'client.com',
104+
'moodle',
105+
],
106+
'different subdomain' => [
107+
'lms.client.com',
108+
'mail.client.com',
109+
'client.com',
110+
'lms',
111+
],
112+
'noreply contains part of subdomain' => [
113+
'lms.moodle.client.com',
114+
'moodle.client.com',
115+
'client.com',
116+
'lms',
117+
],
118+
'noreply subdomain of lms' => [
119+
'lms.moodle.client.com',
120+
'email.lms.moodle.client.com',
121+
'client.com',
122+
'',
123+
],
124+
'unable to identify primary domain' => [
125+
'lms.moodle.client.com',
126+
'client.com',
127+
'lms.moodle.client.com',
128+
'lms-moodle',
129+
],
130+
'different noreply' => [
131+
'lms.moodle.client.com',
132+
'vendor.com',
133+
'client.com',
134+
'lms-moodle-client-com',
135+
],
136+
'different noreply with no subdomain' => [
137+
'client.com',
138+
'vendor.com',
139+
'client.com',
140+
'client-com',
141+
],
142+
];
143+
}
144+
145+
}

0 commit comments

Comments
 (0)